Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Shafin Kothia
Published © GPL3+

Water Level Monitor with Raspberry pi

Always forget to turn the tap off for a bucket and it overflows? This project will help you

BeginnerFull instructions provided1 hour38,742
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
5 projects • 12 followers
I am the manager of AIVersity and I make robotics projects and tutorials for people who started their wonderful journey in robotics and AI

Comments