Flow totalizer algoritm -- need ideas

Dear all,

I am developing a sketch to to measure the flow rate of the water being pumped from a reservoir and transmit it to a central location.
I had some troubles in to develop the basic code but thanks to the help I got from this forum I am almost there.

The problem I need to tackle now is to how to measure the total volume transferred by the pump in each pumping cycle (the pump is turned on and of by a level sensor located at the discharge reservoir).

I tried to use flags but the code became so complex that I know from experience that I should be doing it wrong.

There is certainly a simpler way, but I am not seeing it.

Any ideas?


If you know the pumping rate (litres per second) and the time (seconds), what’s the problem?
Where do flags come into the problem?

I would go with @TheMemberFormerlyKnownAsAWOL's post.

Also your post is a bit confusing. You write about pumping water from a reservoir but then you say there is a level sensor at the discharge reservoir. So is the level sensor where the water is being pumped from or to?

If the reservoir with a sensor has uniform geometry perhaps you could use the level sensor reading to calculate how much water has been pumped. That assumes there are no other inflows or outflows affecting the level apart from the pump.

TotalVolume += FlowInLitresPerSecond * MeasurementCycleDurationInSeconds;

Repeat for each cycle of measurement.

The answer also depends on the magnitude of the flow being measured. The ways you can measure water flowing into a 10,000 gal. tank are completely different from the ways you measure fuel flowing into an engine.

Ray L.

Thank you for the replies.

I will explain the system in more detail.

There is a well sending water to a lower reservoir by gravity.
If this reservoir fills up, the excess water overflows to the ground.

From this reservoir, the water is pumped to an elevated reservoir ( the 2nd one).
The pump is turned on/off by a level sensor located on the 2nd reservoir, so the level is never too low or too high, causing it to overflow.

The control variable that triggers the pump is the level of the 2nd reservoir, and it is possible to have water being consumed from it while the pump is on, so the pumped volume can be much greater than the volume between the lower level (pump on) and the higher level (pump off).

What I am finding very difficult to do is to develop a code to calculate the volume pumped in each on-off cycle.

As already pointed out, once you know the flow rate of the pump, which should be pretty near constant, then it's a simple matter of the flow rate times the on-time. Trivial.

Ray L.

Is this related to your earlier flowmeter post? If you know pulses per liter, (let's say 8.02), then if you counted 50000 pulses while the pump was running the volume would be 6234 liters, save that and add subsequent pump runs to it.