19
19
*******************************
20
20
*
21
21
* REVISION HISTORY
22
- * Version 1.0 - Henrik EKblad
22
+ * Version 1.0 - Henrik Ekblad
23
23
*
24
24
* DESCRIPTION
25
- * This sketch provides an example how to implement a distance sensor using HC-SR04
26
- * Use this sensor to measure KWH and Watt of your house meeter
27
- * You need to set the correct pulsefactor of your meeter (blinks per KWH ).
28
- * The sensor starts by fetching current KWH value from gateway.
29
- * Reports both KWH and Watt back to gateway.
25
+ * This sketch provides an example how to implement a LM393 PCB
26
+ * Use this sensor to measure kWh and Watt of your house meter
27
+ * You need to set the correct pulsefactor of your meter (blinks per kWh ).
28
+ * The sensor starts by fetching current kWh value from gateway.
29
+ * Reports both kWh and Watt back to gateway.
30
30
*
31
31
* Unfortunately millis() won't increment when the Arduino is in
32
32
* sleepmode. So we cannot make this sensor sleep if we also want
33
- * to calculate/report watt-number .
33
+ * to calculate/report watt value .
34
34
* http://www.mysensors.org/build/pulse_power
35
35
*/
36
36
46
46
#include < MySensors.h>
47
47
48
48
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your light sensor. (Only 2 and 3 generates interrupt!)
49
- #define PULSE_FACTOR 1000 // Number of blinks per KWH of your meeter
50
- #define SLEEP_MODE false // Watt- value can only be reported when sleep mode is false.
49
+ #define PULSE_FACTOR 1000 // Number of blinks per of your meter
50
+ #define SLEEP_MODE false // Watt value can only be reported when sleep mode is false.
51
51
#define MAX_WATT 10000 // Max watt value to report. This filters outliers.
52
52
#define CHILD_ID 1 // Id of the sensor child
53
53
@@ -60,10 +60,10 @@ volatile uint32_t lastBlink = 0;
60
60
volatile uint32_t watt = 0 ;
61
61
uint32_t oldPulseCount = 0 ;
62
62
uint32_t oldWatt = 0 ;
63
- double oldKwh ;
63
+ double oldkWh ;
64
64
uint32_t lastSend;
65
65
MyMessage wattMsg (CHILD_ID,V_WATT);
66
- MyMessage kwhMsg (CHILD_ID,V_KWH);
66
+ MyMessage kWhMsg (CHILD_ID,V_KWH);
67
67
MyMessage pcMsg (CHILD_ID,V_VAR1);
68
68
69
69
@@ -107,19 +107,19 @@ void loop()
107
107
oldWatt = watt;
108
108
}
109
109
110
- // Pulse cout has changed
110
+ // Pulse count value has changed
111
111
if (pulseCount != oldPulseCount) {
112
112
send (pcMsg.set (pulseCount)); // Send pulse count value to gw
113
- double kwh = ((double )pulseCount/((double )PULSE_FACTOR));
113
+ double kWh = ((double )pulseCount/((double )PULSE_FACTOR));
114
114
oldPulseCount = pulseCount;
115
- if (kwh != oldKwh ) {
116
- send (kwhMsg .set (kwh , 4 )); // Send kwh value to gw
117
- oldKwh = kwh ;
115
+ if (kWh != oldkWh ) {
116
+ send (kWhMsg .set (kWh , 4 )); // Send kWh value to gw
117
+ oldkWh = kWh ;
118
118
}
119
119
}
120
120
lastSend = now;
121
121
} else if (sendTime && !pcReceived) {
122
- // No count received. Try requesting it again
122
+ // No pulse count value received. Try requesting it again
123
123
request (CHILD_ID, V_VAR1);
124
124
lastSend=now;
125
125
}
@@ -133,7 +133,7 @@ void receive(const MyMessage &message)
133
133
{
134
134
if (message.type ==V_VAR1) {
135
135
pulseCount = oldPulseCount = message.getLong ();
136
- Serial.print (" Received last pulse count from gw:" );
136
+ Serial.print (" Received last pulse count value from gw:" );
137
137
Serial.println (pulseCount);
138
138
pcReceived = true ;
139
139
}
0 commit comments