Tutorial: Reading Water Flow rate with Water Flow Sensor

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

    Calc = (NbTopsFan * 60 / 4.5); // (Pulse frequency x 60) / 4.5Q, = flow rate in L/hour

    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…