Water Level Monitoring using Raspberry Pi - Part 1
Nagendra Thangella Nagendra Thangella
75 subscribers
17,596 views
179

 Published On Jan 26, 2019

This video shows a simple water level monitor prepared from simple materials and using Raspberry Pi. The monitor writes the status blue, green, yellow and red depending on the water level. GPIO pins are used to capture the levels of water. In future, this monitor will be expanded with more features.

Materials needed - Balsa Stick, a cable with four strands of wire (a old phone cable works), female-to-female connectors, Raspberry Pi (any model should work, the video uses Pi 3B), bottle of water and electrical tape.

Raspberry Pi should have Python-3 installed. If not installed, install RPi-GPIO using the command 'sudo apt-get install rpi-gpio'.

Source code used in the demo is

#!/usr/bin/python3
#Author - Nagendra Thangella
#Disclaimer - No warranties or guaranties. Use this at your own risk.
#Prior to running this program, install Rpi-GPIO using command "sudo apt-get install rpi.gpio"
import RPi.GPIO as GPIO; import datetime; import time

#Define Static variables, file names and time format
#pollTime below is set to 1 second
#Besides the below pins, I use pin 1 for 3.3V
rPin = 7; yPin = 11; gPin = 23
pollTime = 1; prevStatus = -1; timeFormat = "%I:%M:%S %p"

#Setup GPIO
GPIO.setwarnings(False); GPIO.setmode(GPIO.BOARD)
#Setup various pins
GPIO.setup([gPin,yPin,rPin], GPIO.IN, GPIO.PUD_DOWN)

#Run infintely until user interrupts
try:
while 1:
#Get status of input pins
red = GPIO.input(rPin); yellow = GPIO.input(yPin); green = GPIO.input(gPin)
status = (red * 4) + (yellow * 2) + (green * 1)
#If status changes, set level indicator as red, yellow, green or blue in that order
blue (no pin) is on when all red, yellow and green are off.
if status != prevStatus:
levelIndicator = ((("blue","green")[green == 1],"yellow")[yellow == 1],"red")[red == 1]
prevStatus = status
currentTime = datetime.datetime.now().strftime(timeFormat)
print ("Status of water level at %s is %s \r\n" % (currentTime, levelIndicator))
time.sleep(pollTime)
#when user interrupts, cleanup and exit
except KeyboardInterrupt:
GPIO.cleanup()
print("Exiting")

show more

Share/Embed