Académique Documents
Professionnel Documents
Culture Documents
(https://hub360.com.ng/)
Call Us (https://hub360.co
Your Cart
07044715478
0 ₦0.00
HOME (HTTPS://HUB360.COM.NG)
ARDUINO TUTORIALS (HTTPS://HUB360.COM.NG/LEARN/ARDUINO-TUTORIALS/)
AUTOMATIC WATER LEVEL INDICATOR AND CONTROLLER USING ULTRASONIC SENSOR (HC-SR04)
Hey guys, this is kayode and together over the next couple of weeks we will be unboxing some really cool projects
ranging from home automation systems to home security systems. At the end of each project am very sure that putting
together your own project will not be a problem. Let’s get started.
In our day to day activities, it is common to have shortage of water or overflow of water in our storage tanks. This is
because it takes time for individual who is manually operating the water pump to turn off the pumping machine and this
may cause water spillage and at times the individual might not know that the water level has dropped so low until the
tank is completely emptied. So why not build a system that monitors and controls this essential part of our life?
We are going to design a contactless water level indicator and controller using ultrasonic sensor. We will need the
following;
HC-SR04
LCD 16X2
Motor
ULN2003
Breadboard
Arduino uno
Jumper wires
A computer
Your attention (Hope you will give it to me?)
(http://hub360.com.ng/wp-
content/uploads/2017/11/download.jpg)
The HC-SR04 ultrasonic module is a module that can provide non-contact measurement within the range of 2cm to
400cm with ranging accuracy that can reach 3mm. It works on the principle of echolocation.
The ultrasonic sensor as a trigger and an echo pin. The arduino provides a high signal of 10microseconds to this pin.
After the HC-SR04 is triggered, it sends out eight 40Khz sound waves to the surface of the water. On getting to the
surface of the water, the wave is echoed back to the sensor and the arduino reads the echo pin to determine time spent
between triggering and receiving of the echo. Since we know that the speed of sound is around 340m/s then we can
calculate the distance using;
To determine the level of the water in the tank we must know the total length of the tank. It is this value that will enable
us calibrate our tank to our taste.
Circuit diagram
(http://hub360.com.ng/wp-content/uploads/2017/11/FINAL-WATER-DESIGN_bb.png)
(http://hub360.com.ng/wp-content/uploads/2017/11/hub360_ultrasonic_bb2.png)
The circuit is self-explanatory. The trigger and echo pins of the ultrasonic sensor are connected to pins 9 and 8 of
the arduino respectively. The LCD is connected to the arduino in 4-bit mode with the control pins RS, RW and EN
connected to pins 2, GND and 3 respectively. The data pins D4-D7 are connected to pins 4 ,5 ,6 and 7 respectively. The
negative terminal of the motor is connected at pin 11 of arduino through ULN2003 for turning on or turning off the water
pump.
NOTE: For the purpose of testing this project, we made use of a dc motor as shown in the circuit diagram. A relay must
be connected to the output of the ULN2003 when controlling a pumping machine.
The Ultrasonic sensor module is placed at the top of bucket (water tank) for demonstration. This sensor module will
read the distance between itself and the water surface and it will show the level of water and the status of the motor on
the LCD screen. If the distance is greater than or equal to 40 cm then Arduino turns ON the water pump. The LCD will
show “LEVEL: LOW” and “MOTOR: ON”. When the distance reaches distance about 10cm arduino turns OFF the relay and
LCD will show “LEVEL: FULL” and “MOTOR: OFF”. The LCD will also display medium and high levels when it get to these
points.
Code
We will do a little breakdown of the code and i will leave you with the code at the end.
First, we are going include the lcd library and also declare the pins we will be connecting things to.
// The ultrasonic sensor pins are connected to pins 8 and 7 of the arduino
#define trigger 9
#define echo 8
float time=0,distance=0;
const int MOTOR = 11; // the relay is connected to pin 9
Next, we set the pins the state of the pins we have earlier declared and display our initial message on the lcd.
void setup()
{
We move into our void loop section where the main job is done. The first seven lines handle the sending of signals out
from the arduino and receiving it back.
void loop()
{
lcd.clear();
digitalWrite(trigger,LOW);
delayMicroseconds(2);
digitalWrite(trigger,HIGH);
delayMicroseconds(10);
digitalWrite(trigger,LOW);
delayMicroseconds(2);
time=pulseIn(echo,HIGH); // stores the time span between the transmitted and reflected waves
The next line deals with calculating the distance between the sensor and the water surface.
The final part of the code deals with the monitoring of the water level and then taking appropriate decision with respect
to our motor.
lcd.setCursor(0,0);
lcd.print("LEVEL:");
lcd.setCursor(0,1);
lcd.print("MOTOR:");
delay(10);
if(distance>=40.00)
{
digitalWrite(MOTOR, HIGH);
lcd.setCursor(7,0);
lcd.print("LOW");
lcd.setCursor(7,1);
lcd.print("ON");
delay(1000);
}
else if(distance<20.00 && distance >10)
{
boolean motor_state1=digitalRead(MOTOR);// read the state of the motor pin
if (motor_state1== HIGH)
{
lcd.setCursor(7,0);
lcd.print("HIGH");
lcd.setCursor(7,1);
lcd.print("ON");
delay(1000);
}
else
{
lcd.setCursor(7,0);
lcd.print("HIGH");
lcd.setCursor(7,1);
lcd.print("OFF");
delay(1000);
}
}
lcd.setCursor(7,0);
lcd.print("MEDIUM");
lcd.setCursor(7,1);
lcd.print("OFF");
delay(1000);
}
}
That’s it guys copy and paste the code into the arduino IDE and voila you are good to go. Let me know if you have any
question.
// include the library code:
#include <LiquidCrystal.h>
// The ultrasonic sensor pins are connected to pins 9 and 8 of the arduino
#define trigger 9
#define echo 8
/*
The lcd circuit:
* LCD RS pin to digital pin 2
* LCD Enable pin to digital pin 3
* LCD D4 pin to digital pin 4
* LCD D5 pin to digital pin 5
* LCD D6 pin to digital pin 6
* LCD D7 pin to digital pin 7
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
*/
float time=0,distance=0;
const int MOTOR = 11; // the motor is connected to pin 11
void setup()
{
void loop()
{
lcd.clear();
digitalWrite(trigger,LOW);
delayMicroseconds(2);
digitalWrite(trigger,HIGH);
delayMicroseconds(10);
digitalWrite(trigger,LOW);
delayMicroseconds(2);
time=pulseIn(echo,HIGH); // stores the time span between the transmitted and reflected waves
distance=time*0.034/2; //formula to calculate the distance in cm
lcd.setCursor(0,0);
lcd.print("LEVEL:");
lcd.setCursor(0,1);
lcd.print("MOTOR:");
delay(10);
if(distance>=40.00)
{
digitalWrite(MOTOR, HIGH);
lcd.setCursor(7,0);
lcd.print("LOW");
lcd.setCursor(7,1);
lcd.print("ON");
delay(1000);
}
else if(distance<20.00 && distance >10)
{
boolean motor_state1=digitalRead(MOTOR);// read the state of the motor pin
if (motor_state1== HIGH)
{
lcd.setCursor(7,0);
lcd.print("HIGH");
lcd.setCursor(7,1);
lcd.print("ON");
delay(1000);
}
else
{
lcd.setCursor(7,0);
lcd.print("HIGH");
lcd.setCursor(7,1);
lcd.print("OFF");
delay(1000);
}
}
lcd.setCursor(7,0);
lcd.print("MEDIUM");
lcd.setCursor(7,1);
lcd.print("OFF");
delay(1000);
}
}
Cheers,
Kayode.
SHARE
(http://www.facebook.com/share.php?
(http://twitter.com/home?
(https://plus.google.com/share?
u=https://hub360.com.ng/automatic-
status=Automatic
url=https://hub360.com.ng/automatic-
water-water water-
RELATED NEWS
indicator-
indicator
indicator-
controller-
controller
controller-
using-using using-
ultrasonic-
ultrasonic
ultrasonic-
sensor-
sensorsensor-
sr04/&title=Automatic
SR04)+https://hub360.com.ng/automatic-
sr04/)
water water-
level level-
indicator
indicator-
and and-
(https://hub360.com.ng/weekend-tutorials-epispde-1-weigh-it/)
controller
controller-
WEEKEND HACKS: {EPISPDE 1} WEIGH IT (HTTPS://HUB360.COM.NG/WEEKEND-TUTORIALS-EPISPDE-1-WEIGH-
IT/)
using using-
ultrasonic
ultrasonic-
0 Comment(s)
sensorsensor-
Hx711 (Https://Hub360.Com.Ng/Learn/Hx711/) , LCD (Https://Hub360.Com.Ng/Learn/Lcd/) , Load Cell
(Https://Hub360.Com.Ng/Learn/Load-Cell/)
(HC- hc-
Read More (Https://Hub360.Com.Ng/Weekend-Tutorials-Epispde-1-Weigh-It/)
SR04))sr04/)
(https://hub360.com.ng/sensors-monday-ad8232-heart-rate-sensor-with-visualization-via-arduino-serial-plotter-
matlab-and-processing/)
SENSORS MONDAY: AD8232 HEART RATE SENSOR WITH VISUALIZATION VIA ARDUINO SERIAL PLOTTER, MATLAB
VISUALIZATION-VIA-ARDUINO-SERIAL-PLOTTER-MATLAB-AND-PROCESSING/)
2 Comment(s)
ARDUINO/)
0 Comment(s)
COMMENTS (6)
hello saze, thanks for reading through. For the purpose of testing this project, we made use of a dc motor as
shown in the circuit diagram. A relay must be connected to the output of the ULN2003 when controlling a
pumping machine. So to connect the relay, you will connect one end of the coil pin of the relay(should be a 30A
relay for a pumping machine) to the output of the ULN2003 and the other end to 12V. The potentiometer near the
LCD is used to adjust the contrast of the LCD.
LEAVE A COMMENT
CATEGORIES
Beginner (https://hub360.com.ng/learn/beginner/)
Intermediate (https://hub360.com.ng/learn/intermediate/)
Intermediate (https://hub360.com.ng/learn/intermediate-raspberry-pi-tutorials/)
Noobs (https://hub360.com.ng/learn/noobs/)
Uncategorized (https://hub360.com.ng/learn/uncategorized/)
(https://www.facebook.com/circuithub360)
(https://twitter.com/circuithub360)
(https://instagram.com/circuithub360)
(https://plus.google.com/)
About Us
OFFICE.
NIGERIAN ARMY SHOPPING ARENA, BLOCK EU2, SHOP 9 & 10, (BESIDE ECOBANK) OSHODI, LAGOS
Info@Hub360.Com.Ng (Mailto:info@Hub360.Com.Ng)
+234-7044715478
+234-8021118809
Our Services
Contact Us (https://hub360.com.ng/contact-us/)
Delivery/Shipping Information (https://hub360.com.ng/delivery-information/)
Frequently Asked Questions (https://hub360.com.ng/pre-built-pages/frequently-asked-questions/)
Terms and Conditions (https://hub360.com.ng/pre-built-pages/terms-and-conditions/)
Information
My Account (https://hub360.com.ng/my-account-2/)
New Product Request (https://hub360.com.ng/new-product-request/)
User Login (https://hub360.com.ng/pie-register-login/)
User Registeration (https://hub360.com.ng/pie-register-registration/)
locate us
Hub360
+
Shop EU2 9&10 Army Shopping Save
Arena, Oshodi-Isolo, Lagos
4.4 16 reviews
Report
Map data a map
©2019 error
Google