8

I'm trying to use this water flow sensor with raspberry:

https://www.adafruit.com/products/828

I'm using this python code to read the pulses:

#!/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
GPIO.add_event_detect(FLOW_SENSOR, GPIO.RISING, callback=countPulse)
while True:
 try:
 time.sleep(1)
 except KeyboardInterrupt:
 print '\ncaught keyboard interrupt!, bye'
 GPIO.cleanup()
 sys.exit()

Unfortunately, this code is not working properly and as I'm new with raspberry I don't know how to solve the problem.

I would like to know if is necessary to use another component in raspberry, like MCP3008 or another one.

If possible, send me how to wire the sensor cables is raspberry too.

Steve Robillard
35k18 gold badges106 silver badges110 bronze badges
asked Aug 15, 2015 at 20:05
1

1 Answer 1

10

Water meter pulse outputs are typically open drain.

This means they are pulled to ground to signal a pulse and float high to an external voltage.

As a quick check change the following two lines.

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

to

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

and

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

to

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

answered Aug 15, 2015 at 20:53
1
  • 1
    Hi joan, the code is working now and the pulses are been counted. Thanks!! Commented Aug 29, 2015 at 13:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.