shafin kothia
Published

Water Level Monitor with Raspberry pi

How to build a water level sensor for water tanks with a Raspberry pi ?

BeginnerFull instructions provided1 hour1,993
Water Level Monitor with Raspberry pi

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
Raspberry Pi 3b
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor
×1
Buzzer
Buzzer
Buzzer
×1
Jumper wires (generic)
Jumper wires (generic)
Jumper Wires
×1

Story

Read more

Schematics

Circuit Diagram

Code

Ultrasonic Sensor Water Level

Python
import RPi.GPIO as GPIO
import time


GPIO.setmode(GPIO.BCM)

TRIG = 2
ECHO = 3
i=0

GPIO.setup(TRIG ,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)
GPIO.setup(4 ,GPIO.OUT)

GPIO.output(TRIG, False)
print("Starting.....")
time.sleep(2)

while True:
   GPIO.output(TRIG, True)
   time.sleep(0.00001)
   GPIO.output(TRIG, False)

   while GPIO.input(ECHO)==0:
      pulse_start = time.time()

   while GPIO.input(ECHO)==1:
      pulse_stop = time.time()

   pulse_time = pulse_stop - pulse_start

   distance = pulse_time * 17150
   print(round(distance, 2));

   time.sleep(1)
   
   if distance < 4:
       print("Water will overflow")
       GPIO.output(4, True);
       time.sleep(0.5)
       GPIO.output(4, False);
       time.sleep(0.5)
       GPIO.output(4, True);
       time.sleep(0.5)
       GPIO.output(4, False);
       time.sleep(0.5)
   else:
       GPIO.output(4, False);

Credits

shafin kothia

shafin kothia

2 projects • 5 followers
I have been developing AIversity for robotics training and projects

Comments