Automatic Water Level Indicator and Controller Using Arduino
Automatic Water Level Indicator and Controller Using Arduino
Components
1. Arduino Uno
2. Ultrasonic sensor Module
3. 16x2 LCD
4. Relay 6 Volt
5. ULN2003
6. 7806
7. PVT
8. Copper wire
9. 9 volt battery or
12 Voltadaptor
10. Connecting wires
Ultrasonic Sensor Module
Here we have divided the product of speed and time by 2 because the time is the total time
it took to reach the obstacle and return back. Thus the time to reach obstacle is just half the
total time taken.
By using this methods we gets distance from sensor to water surface. After it we need to
calculate water level.
Now we need to calculate the total length of water tank. As we know the length of water
tank then we can calculate the water level by subtracting resulting distance coming from
ultrasonic from total length of tank. And we will get the water level distance. Now we can
convert this water level in to the percent of water, and can display it on LCD. The working of
the complete water level indicator project is shown in below block diagram.
Circuit Diagram and Explanation
As shown in the water level controller circuit given below, Ultrasonic sensor module’s
“trigger” and “echo” pins are directly connected to pin 10 and 11 of arduino. A 16x2 LCD is
connected with arduino in 4-bit mode. Control pin RS, RW and En are directly connected to
arduino pin 7, GND and 6. And data pin D4-D7 is connected to 5, 4, 3 and 2 of arduino, and
buzzer is connected at pin 12. 6 Volt relay is also connected at pin 8 of arduino
through ULN2003 for turning on or turning off the water motor pump. A voltage regulator
7805 is also used for providing 5 volt to relay and to remaining circuit.
In this circuit Ultrasonic sensor module is placed at the top of bucket (water tank) for
demonstration. This sensor module will read the distance between sensor module and
water surface, and it will show the distance on LCD screen with message “Water Space in
Tank is:”. It means we are here showing empty place of distance or volume for water
instead of water level. Because of this functionality we can use this system in any water
tank. When empty water level reaches at distance about 30 cm then Arduino turns ON the
water pump by driving relay. And now LCD will show “LOW Water Level” “Motor turned
ON”, and Relay status LED will start glowing
Now if the empty space reaches at distance about 12 cm arduino turns OFF the relay and
LCD will show “Tank is full” “Motor Turned OFF”. Buzzer also beep for some time and relay
status LED will turned OFF.
Programming
To program Arduino for water level controller, first we define all the pin that we are going
to use in the project for interfacing external devices like relay, LCD, buzzer etc.
#define trigger 10
#define echo 11
#define motor 8
#define buzzer 12
lcd.begin(16,2);
pinMode(trigger,OUTPUT);
pinMode(echo,INPUT);
pinMode(motor, OUTPUT);
pinMode(buzzer, OUTPUT);
lcd.setCursor(0,1);
delay(2000);
Now initialize the ultrasonic sensor module and read time of sending and receiving time of
ultrasonic waves or sound by using pulseIn(pin). Then perform calculations and display
the result on 16x2 LCD by using appropriate functions.
digitalWrite(trigger,HIGH);
delayMicroseconds(10);
digitalWrite(trigger,LOW);
delayMicroseconds(2);
time=pulseIn(echo,HIGH);
distance=time*340/20000;
lcd.clear();
lcd.setCursor(0,1);
lcd.print(distance);
lcd.print("Cm");
After it we check conditions if water tank is full or water level is LOW, and take actions
accordingly.
digitalWrite(motor, LOW);
digitalWrite(buzzer, HIGH);
lcd.clear();
lcd.setCursor(0,1);
delay(2000);
digitalWrite(buzzer, LOW);
delay(3000);
temp=1;
}
else if(distance<12 && temp==1)
digitalWrite(motor, LOW);
lcd.clear();
lcd.setCursor(0,1);
delay(5000);
Code
#include <LiquidCrystal.h>
#define trigger 10
#define echo 11
#define motor 8
#define buzzer 12
LiquidCrystal lcd(7,6,5,4,3,2);
float time=0,distance=0;
int temp=0;
void setup()
{
lcd.begin(16,2);
pinMode(trigger,OUTPUT);
pinMode(echo,INPUT);
pinMode(motor, OUTPUT);
pinMode(buzzer, OUTPUT);
lcd.print(" Water Level ");
lcd.setCursor(0,1);
lcd.print(" Indicator ");
delay(2000);
}
void loop()
{
lcd.clear();
digitalWrite(trigger,LOW);
delayMicroseconds(2);
digitalWrite(trigger,HIGH);
delayMicroseconds(10);
digitalWrite(trigger,LOW);
delayMicroseconds(2);
time=pulseIn(echo,HIGH);
distance=time*340/20000;
lcd.clear();
lcd.print("Water Space In ");
lcd.setCursor(0,1);
lcd.print("Tank is: ");
lcd.print(distance);
lcd.print("Cm");
delay(2000);
if(distance<12 && temp==0)
{
digitalWrite(motor, LOW);
digitalWrite(buzzer, HIGH);
lcd.clear();
lcd.print("Water Tank Full ");
lcd.setCursor(0,1);
lcd.print("Motor Turned OFF");
delay(2000);
digitalWrite(buzzer, LOW);
delay(3000);
temp=1;
}
else if(distance<12 && temp==1)
{
digitalWrite(motor, LOW);
lcd.clear();
lcd.print("Water Tank Full ");
lcd.setCursor(0,1);
lcd.print("Motor Turned OFF");
delay(5000);
}
else if(distance>30)
{
digitalWrite(motor, HIGH);
lcd.clear();
lcd.print("LOW Water Level");
lcd.setCursor(0,1);
lcd.print("Motor Turned ON");
delay(5000);
temp=0;
}
}