Water Meter

I am looking for a sample code to read pulse from a Adafruit water meter.

Tell us which meter you are getting.

I have Liquid Flow Meter - Plastic 1/2" NPS Threaded from Adafruit Industries for POC. here is the link http://www.adafruit.com/products/828
Technical Details

Electrical: •Working Voltage: 5 to 18VDC
Max current draw: 15mA @ 5V
Working Flow Rate: 1 to 30 Liters/Minute
Working Temperature range: -25 to 80°C
Working Humidity Range: 35%-80% RH
Maximum water pressure: 2.0 MPa
Output duty cycle: 50% ±10%
Output rise time: 0.04us
Output fall time: 0.18us
Flow rate pulse characteristics: Frequency (Hz) = 7.5 * Flow rate (L/min)
Pulses per Liter: 450
Durability: minimum 300,000 cycles
echanical: •1/2" NPS nominal pipe connections, 0.78" outer diameter, 1/2" of thread
Size: 2.5" x 1.4" x 1.4"

Thanks for helping out.

That’s a lot of pulses per liter, so the frequency of pulses will be fast when a lot of water is running. You might have to scale-down the pulses. Maybe Hugo or someone can figure out if the imp can handle the counting at the high frequencies.

Or maybe use a frequency to voltage method?

Hi Hugo, I am using this flow meter for beer dispensing for which I need to count the pulses. It doesn’t have to be exactly in a second as long as with every loop I get the exact count. Could you please provide some guidance how can I achieve it?

@daman,
If you have, or can get an oscilloscope, you should run some beer through and see what the pulses look like, along with the timing of them. With a beer dispenser, the flow rate may be low enough to work well with your meter.

Hi Mlseim, I appreciate your advise and I am going back to my first post “I am looking for a sample code to read pulse from a Adafruit water meter” How do I program it?
Do I use Pin1 with PULSE_CONUTER configuration and Or just pin2 with DIGITAL_IN configuration with read loop?

@daman,
Are you trying to use the meter to determine flow, total liquid dispensed, or perhaps produce an indication of when a specific amount of beer has been dispensed? It’s not clear what you mean in your earlier post by ‘as long as with every loop I get the exact count’. What is the ‘loop’ or cycle you’re referring to? I’m thinking perhaps a little better explanation of your intended use/application may yield more suggestions that might help you get closer to an implementation.

I think your suggestion of just using pin1.configure(PULSE_COUNTER, etc.) should work fine. Assuming a nominal dispensing rate of about 2 L/min, this would equate to 15pps (actually, quite a low frequency). You could choose the time interval you wanted to monitor this over, and/or if you needed to accumulate successive readings to get some sort of cumulative count that would correspond to a total amount dispensed.

The issue with PULSE_COUNTER is that it’s blocking; yes the pulse counter can deal with very high frequencies (up to MHz as I remember) but if you ask it to count pulses for a second, you can’t do anything else during that time.

Really, it’d be a lot more useful if it worked more like the sampler, whereby you could register a callback and be told regularly how many pulses happened in each interval. Hmm, API suggestion…

@LarryJ
@Hugo
My end goal is to measure beer by counting pulses. I did a POC using Raspberry where every pulse was recorded as an event and I was hoping to capture the pulses using Electric Imp the similar way or atleast the correct count.

After many changes "flow.configure(DIGITAL_IN_PULLUP) is seemed to working. As flow meter spins with every pulse it is changing the state of the Pin which I am counting.

Please let me know your thoughts on it.

@daman
I had neglected to initially mention (but @Hugo pointed out) that PULSE_COUNTER was blocking, so your use of DIGITAL_IN_PULLUP with a callback to manage your pulse count sounds like the preferred strategy. Only thing to perhaps recognize (which you likely have already) is that you would get 2x callbacks (vs. actual pulses) due to it being called on pin state changes … so you’d have to account for that if you were trying to get an accurate measurement. Good to hear you’ve got something going.

(And @Hugo, your suggestion of a sampler-like counter sounds like a useful feature).

@LarryJ
I am counting state only when it is HIGH or Equal to 1.
@Hugo
Could you elaborate “sampler-like counter”

Yea, I kinda figured you likely took care of the 2x issue … but commented just in case not :).

(The way I interpreted @Hugo’s musings about a hypothetical ‘sampler-like’ counter is that (like the current sampler), you would set a callback which would be initiated at a specified interval. Unlike the sampler however, where the callback is called after a fixed number of samples, this new API would initiate its callback at fixed time intervals … sorta like how imp.wakeup( ) works. Further, this callback would have access to the number of pulses/transitions that occurred on a desired pin since the last callback. It would just provide a convenient, non-blocking, way of doing what you want to do now … i.e. count pulses over fixed intervals).

Great topic!
I am interested how your accuracy is working out. Once you get some better data you should be able to calibrate the reading by adding/subtracting an “offset” value to each dispense to compensate for absolute meter accuracy.

You could do this by analyzing what your input is versus the imp measured pours (per keg??)

Your requirements sound similar to reading the flashing light on a power meter or the pulses from a wind speed sensor. Both of which there’s example code for… I think.

The maximum pulse rate for your beer flow meter is 5 pulses per second.

You can have the IMP device call a function everytime the IO pin goes high. The called function then increments a variable or counts pulses in a time window or even logs a series of timestamps for each pulse. This is all in software and doesn’t use the hardware sampler function which I think is for higher frequency sampling than a meter.

@rocketfire
I am using DIGITAL_IN_PULLUP. It is giving me lot of pulses as I blow air in the flow meter to move the turbine wheel. I am working to test it with beer. I will update the result one done.