How to count pulses on a Flow Meter

Are you wanting to find the total volume, or the flow rate? If you want the total volume, then simply count the pulses. For flow rate, eg., litres/second then you need to count pulses per unit time. The way we used to read these meters for flow rate depended on how fast the pulses were coming in.

For slow pulses, we measured the time between incoming pulses. Start a timer, and whenever a pulse comes in, note the time and reset the timer. The flow rate is the reciprocal of the time.

For faster pulse rates, we would use a timer set to a fixed time and count how many pulses occur in the set time period. The flow rate is then directly proportional to this count.

Depending on whether the pulses are generated electromechanically or not, you may need to add some debounce logic to your code. I suspect you won’t need to debounce the input, because a Rpi running Xojo won’t be fast enough to catch a contact bounce. But, if using an interrupt to catch the pulse, make sure to disable that input immediately in the interrupt service routine to make sure that multiple contact bounces don’t get queued. Then re-enable the input just before exiting the routine.

1 Like