I am trying to connect a flow meter YF-S201 to Raspberry Pi B+.

It has three wires --> Red -> 5V --> Blac -> Ground --> Yellow -> Signal

I have a doubt with the cicuit, The flow meter works in 5V but raspberry GPIO are 3V3, however I had test the output of the yellow wire and never exceds the 3V (in my tests)

Someone has used this flow meter ¿How should I connect it?

I have built two circuits:


enter image description here

SECOND (with a Voltage divider):

enter image description here

I have test both circuits but when I run my code It doesn work fine. The input pin (22 BCM) always is LOW, I cannot receive the pulses, I don know if I forgot something in my code. When I test with the multimeter I see how the voltage in the yellow wire change (It make me thing that the flow meter is working properly)

Please could someone help me? I have been searching a lot on the Internet but unfortunately I can not find the explanation of what is happening to me and I do not know if the problem is my code or the circuit

The code

import RPi.GPIO as GPIO
import time, sys


GPIO.setup(FLOW_SENSOR, GPIO.IN, pull_up_down = GPIO.PUD_UP)

global count
count = 0

def countPulse(channel):
   global count
   if start_counter == 1:
      count = count+1
      print count
      flow = count / (60 * 7.5)

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

while True:
        start_counter = 1
        start_counter = 0
        flow = (count * 60 * 2.25 / 1000)
        print "The flow is: %.3f Liter/min" % (flow)
        count = 0
    except KeyboardInterrupt:
        print '\ncaught keyboard interrupt!, bye'

Thanks in advance

  • How did you test the voltage on signal wire? I would say that you need voltage divider. The voltage of signal pulses is most likely equal (little less than equal) to supply voltage. Feb 21, 2017 at 18:30
  • I test the voltage on the signal wire with the multimeter (red touching signal wire and black touching ground wire). Am I testing it correctly?
    – user62418
    Feb 21, 2017 at 18:52
  • Note that in your image you show signal connected to pin 22, but in code you use 23. Signal voltage testing with multimeter is not OK, unless pulses are really slow and long. Feb 21, 2017 at 18:56
  • Sorry @NonStandardModel, currently I use the pin 22 in my Raspberry and also in the code, I don't know how to edit the question to correct it :S
    – user62418
    Feb 21, 2017 at 19:09
  • I have corrected the code in the question.
    – user62418
    Feb 21, 2017 at 19:14

2 Answers 2


Searching the Internet I found this circuit for a flow meter. I don't know very much about electronics. How about it?

Red ------------- 5V

           +----- 3V3
Yellow ----+----- gpio

Black ----------- Ground
  • Yes, that will work as long as the flow meter has an open collector output.
    – joan
    Feb 21, 2017 at 19:25
  • In this circuit when I test with the multimeter (Red to the 3V3 wire and black to the gpio wire) the voltage exceeds 3V3 when the flow meter is actived (fluid passes throught the flow meter ) :-S
    – user62418
    Feb 21, 2017 at 20:01

As long as your flow meter has an open collector output (as most seem to) it should be quite safe to use with the Pi.

An open collector output means that the pulse is indicated by the sensor pulling the output pin to ground (0). At other times the sensor lets the output pin float to an external voltage.

This means you need a pull-up to 3V3 through a resistor on the sensor output pin. A resistor value of 4k7 is quite normal. Alternatively you could just enable the internal GPIO pull-up to 3V3 for the GPIO you connect to the sensor's output pin.

Example pigpio script

#!/usr/bin/env python

# flow-meter.py
# 2017-02-21
# Public Domain

import time
import pigpio

RUN_TIME = 60.0

pi = pigpio.pi() # connect to Pi
if not pi.connected:

pi.set_mode(FLOW_GPIO, pigpio.INPUT)
pi.set_pull_up_down(FLOW_GPIO, pigpio.PUD_UP)

callback = pi.callback(FLOW_GPIO) # default tally callback

stop = time.time() + RUN_TIME


   while time.time() < stop:



except KeyboardInterrupt:


callback.cancel() # cancel callback

pi.stop() # disconnect from Pi
  • but if you use sleep in your program....will it count pulses during the sleep period Feb 21, 2017 at 18:52
  • 1
    @NonStandardModel Yes, callbacks are automatically handled by a separate Python thread.
    – joan
    Feb 21, 2017 at 18:54
  • I have found on this site hobbytronics.co.uk/yf-s201-water-flow-meter that it has 5V TTL Output. Feb 21, 2017 at 19:25
  • Yes, It is the same flow meter, I don't want to fry my pi :S
    – user62418
    Feb 21, 2017 at 19:35
  • 1
    @user62418 If it is 5V TTL you would need to use a voltage divider to drop the 5V to a Pi safe 3V3. Personally I reckon the blurb is wrong, but it's not my Pi to risk.
    – joan
    Feb 21, 2017 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.