I'm trying to use this water flow sensor with raspberry:
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.