Tutorial: Reading Water Flow rate with Water Flow Sensor

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?


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?


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 :slight_smile:

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?



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 :smiley:


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

Please help me. I m new to raspberry pi.


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.

#!/usr/bin/env python

import RPi.GPIO as GPIO
import time, sys


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

GPIO.add_event_detect(FLOW_SENSOR, GPIO.RISING, callback=countPulse)

while True:
except KeyboardInterrupt:
print ‘\ncaught keyboard interrupt!, bye’


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

  • 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]



    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.



    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.



    Hi all!

    Does anybody have the datasheet for the G1" Water Flow Sensor?

    I am looking for the value of the constant that gives the relation between flowrate and pulses per minute the sensor is sending (7.5 for G1/2", 5.5 for G3/4")

    I have found the datasheet for G1/2" sensor, flow rate vs frequency rate for G1/4" G3/4" but nothing on G1" sensor



    Sorry for replying in such an old post but I really need this information!

    Can I make this work WITHOUT using interruptions? I mean, using regular inputs (analog probably) or PWM inputs?

    Thank you and sorry again.

    Very interesting…

    Think I might use it in my own applications. Only question: is it waterproof, or will i need to make it water proof?


    What distance can you send the signal from the flowmeter? How do you determine this? If the yellow signal wire to the seeeduino is 50 yards, would it still read properly on pin 2?


    I have a flow meter and have everything wired up to an arduino uno. the signal is coming in at digital port 4. my problem is that when i power the arduino and upload the code, without having the pump on i get values like 520, 512 etc. I am testing the system with a small fish tank pump and when i turn it on, i now get values like 240, 304, 248 etc.

    Three questions,

    1)why am i getting 520 when there is no water flowing through the meter? I would expect this to be zero not a value like 520

    2)Why do values vary so much on every sample? i can see 224, 280, 356, 404, 232,288 etc when the pump is just pumping the same amount more or less.

    3)In the sample code the equation is


    but in the comments above, it seems that the 4.5 suppose to be 7.5. Which one is correct?


    I’m trying to interface the sensor with Arm7.

    Can you tell me what pin2 corresponds to so that i can interface it with ARM7.

    How appropriate would this sensor be for measuring small amounts of liquid, like cups of beverage from a beverage dispenser? I would ideally like to achieve centiliter accuracy, if I pour a 50 centiliter cup of liquid (half a liter), is this sensor going to be resolute enough? …Do I risk being off by 1.5 cl or so per beverage? Or better yet, can it be calibrated?

    This is very interesting! Thanks for posting. I have a question around a practical example I’m thinking about putting together around this. I see the the “accurate within 3%” note and I get a bit nervous…