20
20
*
21
21
* REVISION HISTORY
22
22
* Version 1.0 - Henrik Ekblad
23
+ * Version 1.1 - GizMoCuz
23
24
*
24
25
* DESCRIPTION
25
26
* Use this sensor to measure volume and flow of your house watermeter.
33
34
* http://www.mysensors.org/build/pulse_water
34
35
*/
35
36
36
- #include < SPI.h>
37
37
#include < MySensor.h>
38
+ #include < SPI.h>
38
39
39
40
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your sensor. (Only 2 and 3 generates interrupt!)
40
41
#define SENSOR_INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
47
48
48
49
#define CHILD_ID 1 // Id of the sensor child
49
50
50
- unsigned long SEND_FREQUENCY = 20000 ; // Minimum time between send (in milliseconds). We don't want to spam the gateway.
51
+ unsigned long SEND_FREQUENCY = 30000 ; // Minimum time between send (in milliseconds). We don't want to spam the gateway.
51
52
52
53
MySensor gw;
53
54
MyMessage flowMsg (CHILD_ID,V_FLOW);
@@ -72,8 +73,11 @@ void setup()
72
73
{
73
74
gw.begin (incomingMessage);
74
75
76
+ // initialize our digital pins internal pullup resistor so one pulse switches from high to low (less distortion)
77
+ pinMode (DIGITAL_INPUT_SENSOR, INPUT_PULLUP);
78
+
75
79
// Send the sketch version information to the gateway and Controller
76
- gw.sendSketchInfo (" Water Meter" , " 1.2 " );
80
+ gw.sendSketchInfo (" Water Meter" , " 1.1 " );
77
81
78
82
// Register this device as Waterflow sensor
79
83
gw.present (CHILD_ID, S_WATER);
@@ -85,15 +89,15 @@ void setup()
85
89
86
90
lastSend = lastPulse = millis ();
87
91
88
- attachInterrupt (SENSOR_INTERRUPT, onPulse, RISING );
92
+ attachInterrupt (SENSOR_INTERRUPT, onPulse, FALLING );
89
93
}
90
94
91
95
92
96
void loop ()
93
97
{
94
98
gw.process ();
95
99
unsigned long currentTime = millis ();
96
-
100
+
97
101
// Only send values at a maximum frequency or woken up from sleep
98
102
if (SLEEP_MODE || (currentTime - lastSend > SEND_FREQUENCY))
99
103
{
@@ -124,7 +128,7 @@ void loop()
124
128
}
125
129
126
130
// Pulse count has changed
127
- if (pulseCount != oldPulseCount) {
131
+ if (( pulseCount != oldPulseCount)||(!SLEEP_MODE) ) {
128
132
oldPulseCount = pulseCount;
129
133
130
134
Serial.print (" pulsecount:" );
@@ -133,7 +137,7 @@ void loop()
133
137
gw.send (lastCounterMsg.set (pulseCount)); // Send pulsecount value to gw in VAR1
134
138
135
139
double volume = ((double )pulseCount/((double )PULSE_FACTOR));
136
- if (volume != oldvolume) {
140
+ if (( volume != oldvolume)||(!SLEEP_MODE) ) {
137
141
oldvolume = volume;
138
142
139
143
Serial.print (" volume:" );
@@ -152,6 +156,7 @@ void incomingMessage(const MyMessage &message) {
152
156
if (message.type ==V_VAR1) {
153
157
unsigned long gwPulseCount=message.getULong ();
154
158
pulseCount += gwPulseCount;
159
+ flow=oldflow=0 ;
155
160
Serial.print (" Received last pulse count from gw:" );
156
161
Serial.println (pulseCount);
157
162
pcReceived = true ;
@@ -178,4 +183,3 @@ void onPulse()
178
183
}
179
184
pulseCount++;
180
185
}
181
-
0 commit comments