# Pulse Counting Logic for Water Meter

What do you mean by Pin 3? The input is DIO3, which is pin 4 on the green screw terminal strip, or pin 6 on the RJ45 connector.

Do you see anything with a multimeter across the water meter output, and a low flow rate?

I don’t think you can assume anything about the reed switch. If you get one pulse per litre, and the meter’s rated maximum flow rate is 1 l/s, then I think all you can say with certainty is you’ll then have 1 pulse per second. I would expect the switch to open and close when the fastest (or maybe not!) dial hits the same position each time round, and I’d expect that angle between closing and opening to be about 60° - 90°, giving a m/s ratio of 1:5 - 1:3. But those numbers are pure speculation.

I’ve got a push-button switch here wired 3 - 4 on the terminal strip, and if I try hard, I can register 10 pulses per reading (= 1 per sec). But there’s almost no latitude in there - if one pulse or space is slightly short, it misses a pulse. If I sit with my finger on the button, I get 1 pulse on the first reading after I closed the switch, then 0 pulses until after the switch has been opened and closed again. And that’s exactly the behaviour that I expect.

I’ve taken OCR1A = 6249; down to 200 (~ 3 ms polling interval) and all that proves is it can be reduced and my switch doesn’t bounce much. (The interrupt-counting sketch consistently records 2 counts per operation.) It doesn’t appear to have affected the calibration significantly, which it shouldn’t (though at that rate, it could well have reduced the number of samples per cycle).

If you want this sketch to behave the same way as the interrupt-counting sketch, i.e. to report each time the accumulated count over all time, rather than the number counted over this reporting interval, then you need to change line 419 to read:
emontx.pulseCount += pulseCount;
The present behaviour is the same as my original V3.2 sketch.

[Edit 2]
In the sketch comments, I wrote “Pulses are counted by a reed switch connected between digital input 2 and GND.”. That should of course be between digital input 3 and GND. The top silk screen on my emonTx V3.4 is wrong, and the blob of ink on top of the wrong legend has worn off!

Apologies, I should have said pins 3 & 4.
I’ve changed line 419 and it now counting again, I’ll test it later tonight to see if its still bouncing, I’ll let you know how I get on.

Spot on Robert! Thankyou very much for your help.
The changes I made were…
Change line 419 to read: emontx.pulseCount += pulseCount;
Reduce the polling interval: OCR1A = 804;// = (1610^6) / (10256) - 1 (must be <65536)
I’ve ran through 500 litres of water at various flow rates and its accurate to one pulse over the 500 litres pulled through, thou this is questionable depending on where the dial was part way through a litre when I started the test.

I understand now what you meant about the reasoning for changing line 419 for accumulated counting, I didn’t understand originally and I noticed that I was getting random 1s or 2s on the input feed and my input feeds were setup to expect a accumulated feed.

Those weren’t random 1s & 2s, they were 1 & 2 litres recorded during that 10 s period!

I’m a bit concerned that you found it necessary to push the polling rate up quite that far. According to my sums, you’re polling the switch every 12.86 ms, so you’re hoping - apparently justifiably - that the contact bounce is over in that time. It also means that you’ll see a maximum pulse rate of nearly 10 pulses per second.

I don’t think I’d worry about 1 pulse in 500, that’s more accurate than the meter itself. (I found a figure of ± 6% at low flow rates and ± 2.5% at higher flow rates, but no definition of high and low.)