Académique Documents
Professionnel Documents
Culture Documents
Post Reply
13 posts • Page 1 of 1
tscodeler
Posts: 5
https://www.adafruit.com/products/828
Code: Select all
#!/usr/bin/env python
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.BOTH,
callback=countPulse)
while True:
try:
print(GPIO.input(23))
print (count)
time.sleep(1)
except KeyboardInterrupt:
print '\ncaught keyboard interrupt!, bye'
GPIO.cleanup()
sys.exit()
Last edited by tscodeler on Wed Aug 19, 2015 2:20 am, edited 1 time in total.
texy
Forum Moderator
Posts: 5155
Location: Berkshire, England
Re: How to use water flow
sensor on Raspberry?
Quote
Sun Aug 16, 2015 9:24 am
When posting pythons listing you need to use the Code tabs
otherwise all the formating is lost.
Texy
Various male/female 40- and 26-way GPIO header for sale here
( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?
f=93&t=147682#p971555
B.Goode
Posts: 8241
Location: UK
joan
Posts: 14188
Location: UK
tscodeler
Posts: 5
Code: Select all
Red ------------- 5V
+----- 3V3
|
10K
|
Yellow ----+----- gpio
tscodeler
Posts: 5
Code: Select all
#!/usr/bin/env python
FLOW_SENSOR = 23
GPIO.setmode(GPIO.BCM)
GPIO.setup(FLOW_SENSOR, GPIO.IN, pull_up_down =
GPIO.PUD_UP)
global count
count = 0
def countPulse(channel):
global count
count = count+1
print count
flow = count / (60 * 7.5)
print(flow)
GPIO.add_event_detect(FLOW_SENSOR, GPIO.FALLING,
callback=countPulse)
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
print '\ncaught keyboard interrupt!, bye'
GPIO.cleanup()
sys.exit()
This expression below is correct to calculate the measure of
water according the pulses generated?
flow = count / (60 * 7.5)
ghp
Posts: 1401
Location: Stuttgart Germany
Contact: Website
Ferdinand
Posts: 236
Joined: Sun Dec 01, 2013 2:24 pm
Location: Leiderdorp, NL
Test generator
Code: Select all
#!/usr/bin/python
#squarewave.py
# Square wave generator to test flowsensor
# connect GPIO 23 to GPIO 17
# change frequency settings to simulate water
flows streams
seconds = 1 / (2 * frequency)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(square_wave_pin,GPIO.OUT)
GPIO.output(square_wave_pin, False)
time.sleep(seconds)
try:
while True:
GPIO.output(square_wave_pin, False)
time.sleep(seconds)
GPIO.output(square_wave_pin, True)
time.sleep(seconds)
except KeyboardInterrupt:
GPIO.cleanup()
Your code
Code: Select all
#!/usr/bin/python
#flowsensor.py
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_UP)
global count
count = 0
def countPulse(channel):
global count
if start_counter == 1:
count = count+1
# print count
# flow = count / (60 * 7.5)
# print(flow)
GPIO.add_event_detect(FLOW_SENSOR, GPIO.FALLING,
callback=countPulse)
while True:
try:
start_counter = 1
time.sleep(1)
start_counter = 0
flow = (count * 60 * 2.25 / 1000)
print "The flow is: %.3f Liter/min" %
(flow)
count = 0
time.sleep(5)
except KeyboardInterrupt:
print '\ncaught keyboard interrupt!, bye'
GPIO.cleanup()
sys.exit()
Luck with your project!
tscodeler
Posts: 5
eswasar
Posts: 1
Thanks,
Swaroop
jwangyue
Posts: 1
Joined: Wed Dec 12, 2018 7:52 am
marataziat
Posts: 3
pcmanbob
Posts: 6640
Location: Mansfield UK