flow sensor not working raspberry pi
![userHead](https://dfimg.dfrobot.com/dfPortrait2.png)
I have purchased a DFRobot flow sensor (https://wiki.dfrobot.com/SKU_SEN0550_Gravity_Water_Flow_Sensor_G1_2#target_7) and am trying to make it work with raspberry pi (4B) using python code as mentioned below.
Issue is, no matter what the flow rate is (0 or more), it always gives flow rate between 2.4 ml/min to 3.0 ml/min. Can anyone help where I might be wrong in the code? or is it a faulty sensor?
import RPi.GPIO as GPIO
import time, sys
FLOW_SENSOR_GPIO = 26
GPIO.setmode(GPIO.BCM)
GPIO.setup(FLOW_SENSOR_GPIO, GPIO.IN, pull_up_down = GPIO.PUD_UP)
global count
count = 0
def countPulse(channel):
global count
if start_counter == 1:
count = count+1
GPIO.add_event_detect(FLOW_SENSOR_GPIO, GPIO.FALLING, callback=countPulse)
while True:
try:
start_counter = 1
time.sleep(1)
start_counter = 0
flow = (count / 150/60)
print("The flow is: %.3f Liter/min" % (flow))
count = 0
time.sleep(2)
except KeyboardInterrupt:
print('\nkeyboard interrupt!')
GPIO.cleanup()
sys.exit()
Hi
I have checked the example code of Gravity: Water Flow Sensor(SKU:0550). The working principle depends on interruption. Could you please apply similiar function on Raspberry Pi? I'm not sure whether just Falling edge detection will work.
![](https://dfimg.dfrobot.com/nobody/makelog/d10a48ab5f59866e6d825babd8f48252.png)
![userHeadPic](https://dfimg.dfrobot.com/dfPortrait2.png)