General Raspberry Pi

flow sensor not working raspberry pi

userHead Ankur.Bansal 2022-12-04 12:54:05 346 Views3 Replies

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()

 

2023-02-22 14:35:07
userHeadPic bidrohini.bidrohini
2023-02-22 14:32:10

I think you can cross-check your method with this video:

userHeadPic bidrohini.bidrohini
2023-02-22 10:07:46

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.

 

userHeadPic NeloKin