# Tutorial: Reading Water Flow rate with Water Flow Sensor

eltoddo: Yes, it will be off 1.5cl in the worst case. If, and only if, the accuracy is constant for a certain device, it can be configured. Lets say you have constant -1% error in measured vs. real value, (aka. 50cl measured, 50.5cl real) you pull 1.01 as multiplier into the code. In +1%, you use 0.99 as multiplier. (Yes, it is a bit wrong, but I’m just making it simple enough.) Experiment and change the multiplier value to compensate. If the error was constant, that is.

Nashblackcat: If the sensor works with 1 to 30 liters per minute(LPM) range, 50cl is gained with 6LPM in 5 seconds. Take that as 10cl in 1 sec, and if going down to 2LPM speed, it is ~3.33cl in one sec. Hard to say what the safe margin is, but I would NOT try filling 4cl vodka shot. 8cl maybe.

LeeLinkoff: In the formula NbTopsFan * 60 / 7.5 , the NbTopsFan is the amount of rising pulse edges detected by the controller in a set delay time. Here it was 1 second. So we have here our pulses per second and the *60 multiplies this value by 60, so we get pulses per minute. The 7.5 is a constant set in the datasheet of the sensor that tells us the relation between flowrate and pulses per minute the sensor is sending. I would add here a correction value *0.97 to *1.03 if the measurement error is constant to a certain device.

nikoumouk: I agree, the comment and code is wrong and real output is in LPM. Add *60 or change original *60 to *3600 to get liters per hour.

What happens to pulses that arrives while the interrupt is disabled? Don’t you need a buffer here?

dnordenberg: No, you don’t care about them. We need to look only the pulses during the 1 second period for our calculation of flow. The problems will come up only if the flow will change a lot in a short period of time, instead of being (almost) constant.

Just to be clear (sorry for asking a dumb question)

The breadboard diagram looks to have the power and ground connected together and the power connected to signal at the left of the breadboard… This isn’t the case, correct?

Thanks.

-Rob

I just got two sensors and I am kind of disappointed.

I measured the repeatibility of the measurement and it was terrible.

I wanted to use those to measure how much beer I have left in my keg but I am not sure ig those sensors can be used for this.

When the flow is slow (which sometimes happens when you want to avoid foaming) the number of pulses generated by the sensor is about half of what it is when liquid flowing with high velocity. For 0.5l water (i measured the amount passed by puring to the measured device) the difference in number of “ticks” is big I got about 121 tick with slow flow and 240 with water tap fully open…

I think this sensor is not good to use in the systems where you often stop/start the flow.

This is a great book that really helped me use this sensor. It also uses an LCD (I used one I bought from seeedstudio, the brick one that they don’t have anymore in the shop, I see)

I see the author posted the schematics for this project. Unfortunately I don’t see arduino sketch and I don’t think I’m allowed to post it here. Too bad because the only thing I changed in his sketch was the constant (7.5 instead of 4.5).

But I really believe the book is really worth checking.

From the book I mentioned "Practical Arduino" :

"There is a slight complication though: most flow-rate sensors do not have a consistent scaling factor across their entire operational range.
At low flow rates the sensor might be impeded more by friction in the bearings, so its output frequency could actually be lower per liter than at higher flow rates. That variation could be corrected in software by applying a different scaling factor depending on the measured pulse rate. However, because the accuracy of inexpensive flow sensors is typically only +/– 10% anyway it doesn't really matter much in practice that the scaling factor deviates slightly at low flow rates."

PS: you can also find his sketch on the link I posted

The best possible solution for filling glasses or other “reasonably” sized containers, is to use a dummy measuring container in between the storage container and practical container.

Arrangement goes like this: You have flow sensor and automated valve on bottom of the measuring container. The measuring container is sizes so, that when full, it has the same volume as your practical container (eg a glass or tankard). Another automated valve and another flow sensor is placed on top of the measuring container. The measuring container also needs a hose or tube for replacement air to get liquid flow smoothly in and out of the container. The tube or hose end should be placed higher than the liquid level in storage container, so that it won’t overflow during filling. Now you can use your uC of choice to read flow sensors and control the valves.

Procedure is like this: Close valves, open top valve, poll for flow, when no flow, measuring container should be full. Close top valve, open bottom valve to fill the practical container, poll for flow, when no flow, measuring container should be empty. Close bottom valve. Repeat.

With this, one could calculate the remaining liquid in storage container too. As line pressure changes according to the amount of liquid in storage container, tracking the time needed to fill the measuring container would be relative to the amount of liquid still left. Measure time for filling when container is full, maybe some midpoints, and when nearly empty. Or collect a list of times every time the measuring container is filled and create a chart of time/number of fills.

One could also use line pressure, monitor it’s change and use time and line size to fill containers accurately.

Hi, I have used your code with the water flow sensor from seedstudio.

When I run the code and slowly pour water into the sensor, I obtain value that exceed the range of the sensor (32 to 500LPM).

I copypasted the code in arduino and the electrical circuit is exactly like the one on the picture. I bought 2 sensor and they both display the same problem.

I would like to know if there anyone else experiencing the same problem? and is it possible that the sensor are broken?

HEY

I have bought a G1/2 Water Flow sensor . But it gives an output for only upto 3 lpm .

What changes do i have to make to this sensor so that it can measure upto 6 or 7 lpm.

Do i use a more sensitive hall effect sensors so that it is able to capture the faster rotations of the rotor. Could you please suggest a hall effect sensor .

Thanks for posting.

I’m newbie of seeeduino/arduino.

In this case what the relation between 10k resistor and measuring max LPM?

And is it correct that 10k resistor connect between 5V and 2nd pin of Seeeduino?

I’m trying to connect the G1/2 flow sensor to an Atmel attiny85 chip. I’m having trouble having the chip read the sensor. Are there any tricks i.e. pins I should use or a special way to callout the sensor?

thanks.

Is the amplitude voltage level of pulse signal dependent on the input voltage level? For example if the input voltage is 24 V then will the amplitude level of the pulse be 24 V ?

I believe I have found a mistake in the code!!

It says

Calc = (NbTopsFan * 60 / 7.5); to give the litres per minute.

This line is incorrect as NbTopsFan gives the amount of pulses in the one minute time.

60 is the amount of seconds in a minute

and 7.5 is the litre converter

so at the moment, using units only, the result is min/L

so just change it around to get an appropriate result

Calc = (NbTopsFan * 7.5 / 60) // this will result in pulses(litres)/minute

hey presto all you people wondering why your code didn’t work

I have couple of these YF-S201 flow sensors and I can’t find how it has to be mounted.

Some sites say vertical and other horizontal. :?

What is the correct orientation?

Or are both correct?

basile

Hi,

Just a quick question about the figure 7.5 that is used in the calculation. Is this for when the sensor is in a horizontal or vertical position? And if the figure differs on different orientations what would be the respective figure for the pulse frequency be?

Cheers

Guysss…

Have anyone did this sensor coded in python? I am actually stuck with this. Couldnt be able to get any value.

Hi,

I know this thread is mostly about interfacing with water flow sensor from Ardruino, but looks like a few folks trying to do the same using raspberry pi. After checking a bunch of tutorials and posts on raspberry pi + water flow sensor this is what I have come up with so far.

This is a very basic program in python which just counts ticks from the sensor. I haven’t put any water through it yet to see how accurate this is.

How I have sensor connected to GPIO pins

black to GND

red 5v0

yellow through 560 ohm resistor to #23

here is a code, I have to paste it here as I am too new of a user to link to github.

```[code] #!/usr/bin/env python```

import RPi.GPIO as GPIO
import time, sys

FLOW_SENSOR = 23

GPIO.setmode(GPIO.BCM)
GPIO.setup(FLOW_SENSOR, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)

global count
count = 0

def countPulse(channel):
global count
count = count+1
print count

while True:
try:
time.sleep(1)
except KeyboardInterrupt:
print ‘\ncaught keyboard interrupt!, bye’
GPIO.cleanup()
sys.exit()

[/code]

I am new to raspberry pi/ GPIO and not 100% sure on a few things
[list]

• Do I need a resistor?
Should I have a bouncetime? Doesn't look like I need to, i've tried to rotate pin wheel 360 degrees and it consistently gave me 3 pulses.
• [/list]

Thanks!

Anton

I recently purchased this sensor and I was hoping to use in conjunction with a 1/4 tube used as a straw. Naturally, when you drink from a straw there are pauses each time you swallow. I’ve read here that this sensor doesn’t do well with frequent start/stops. Is this an impractical use of the sensor? The liquid I’m measuring would be water.

Also, on a side note, when putting this together I noticed that it’s not quite air tight (maybe you naturally let air in when you drink from a straw?). This results in lots of tiny bubbles and I end up burping for a few minutes after drinking (lol!!). I think this might be solved with a valve similar to the camelbak valves or maybe I need to seal up all the seams on the sensor with some silicone.

Thanks!!

Hi,

I am using water flow sensor for measurement,i am connecting my sensor in such a way that one end is connected to the tap where water comes in and other end is connected to rotating tap through pipe where water comes out, i am measuring the pulses(count)output by the sensor. in my scenario i am measuring the pulses(count) for half liter. at different flow rates my pulse count is different for half liter,but i should get same pulse count for half liter at different flow rates.

Regards

Arun