Automatic Water Level Indicator and Controller using Arduino

Published  November 4, 2015   71
S Saddam
Author
Water Level Indicator and Controller Project using Arduino

In this Arduino based automatic water level indicator and controller project we are going to measure the water level by using ultrasonic sensors. Basic principal of ultrasonic distance measurement is based on ECHO. When sound waves are transmitted in environment then they return back to the origin as ECHO after striking on any obstacle. So we have to only calculate its traveling time of both sounds means outgoing time and returning time to origin after striking on any obstacle. And after some calculation we can get a result that is the distance. This concept is used in our water controller project where the water motor pump is automatically turned on when water level in the tank becomes low. You can also check this simple water level indicator circuit for a simpler version of this project.

 

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

Ultrasonic Sensor HC SR04

Ultrasonic sensor HC-SR04 is used to measure distance in range of 2cm-400cm with accuracy of 3mm. The sensor module consists of ultrasonic transmitter, receiver and the control circuit.

Ultrasonic Sensor timing diagram

The ultrasonic sensor module works on the natural phenomenon of ECHO of sound. A pulse is sent for about 10us to trigger the module. After which the module automatically sends 8 cycles of 40 KHz ultrasound signal and checks its echo. The signal after striking with an obstacle returns back and is captured by the receiver. Thus the distance of the obstacle from the sensor is simply calculated by the formula given as

            Distance= (time x speed)/2.

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.

 

Working of Automatic Water Level Controller

Working of this project is very simple we have used Ultrasonic sensor module which sends the sound waves in the water tank and detects reflection of sound waves that is ECHO. First of all we needs to trigger the ultrasonic sensor module to transmit signal by using Arduino and then wait to receive ECHO. Arduino reads the time between triggering and received ECHO.  We know that speed of sound is around 340 m/s. so we can calculate distance by using given formula:

Distance= (travel time/2) * speed of sound

Where speed of sound is approximately 340m per second.

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.

Water Level Indicator and Controller 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.

Water Level Indicator and Controller Circuit Diagram

 

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

Then we initialize all the devices used in project.

 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);

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.print("Water Space In  ");
 lcd.setCursor(0,1);
 lcd.print("Tank is: ");
 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.

 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);
 }
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;
 }
}

 

Have any question realated to this Article?

Ask Our Community Members

Comments

Submitted by suresh on Fri, 01/29/2016 - 01:37

Permalink

Hi sir,
I have two tank and I like to monitor one tank with ultrasonic sensor with this circuit , Is it possible ?
how can I make connection and how modify the codes

Submitted by F8EBL radio on Wed, 02/03/2016 - 05:01

Permalink

WARNING !!
In the circuit diagram above,, arduino +V supply is connected to +12v unreg. source.
Should be fed by +5V regulator.
relay should have 12 V supply. .
So take care to swap those supply if you want it to work and not smoke..
As this circuit involves lethal voltages, don t try to reproduce it if you don t know anything about electricity / electronics, .

F8EBL Radio..... The 'Vin' on the Aeduino Uno is between 7 to 12v and as per the schematic diagram it is being sent from a battery. All should be fine.

Submitted by boaz on Thu, 02/04/2016 - 15:51

Permalink

whats the meaning of ''temp'' in the code

Submitted by Amir Hakim Bin… on Wed, 03/16/2016 - 17:17

Permalink

i have insert this coding into the arduino uno r3 module in proteus to do the simulation of the program. but it only light up the lcd display without showing any information on the lcd..thank you for your guidance

by using proteus 8, after entrepreting the data of ardunio software, then insert it to arduino uno in the proteus. the try do the simulation process. same as for me, it only light up the lcd but not showing any result. this is because the sensor not detecting any distance

Submitted by sanoj k on Thu, 03/17/2016 - 16:32

Permalink

sir ,
can u please tell which relay i should use in this circuit. i am having a motor which takes 0.37kw power (230v from the mains.
can i use small 5v em relay ? or should i use SSR ?

Submitted by Anthony Tortolani on Fri, 04/15/2016 - 20:19

Permalink

hi, I'm a little new with Arduino, I'm getting error: 'lcd' was not declared in this scope, can you please tell me what I'm doing wrong? I copied and pasted the whole code in the void setup section, tried to install adafruit libraries, but still getting this error.

Submitted by Anthony Tortolani on Sat, 04/16/2016 - 01:41

Permalink

Hi, I was pasting the code on a wrong way, I already fixed that, but still having problems when checking the code, I have this error:

ultrasonic_water_level_sensor.ino:7: error: 'lcd' does not name a type
lcd.begin(16,2);
ultrasonic_water_level_sensor.ino:8: error: expected constructor, destructor, or type conversion before '(' token
pinMode(trigger,OUTPUT);
ultrasonic_water_level_sensor.ino:9: error: expected constructor, destructor, or type conversion before '(' token
pinMode(echo,INPUT);
ultrasonic_water_level_sensor.ino:10: error: expected constructor, destructor, or type conversion before '(' token
pinMode(motor, OUTPUT);
ultrasonic_water_level_sensor.ino:11: error: expected constructor, destructor, or type conversion before '(' token
pinMode(buzzer, OUTPUT);
^
ultrasonic_water_level_sensor.ino:12: error: 'lcd' does not name a type
lcd.print(" Water Level ");
^
ultrasonic_water_level_sensor.ino:13: error: 'lcd' does not name a type
lcd.setCursor(0,1);
^
ultrasonic_water_level_sensor.ino:14: error: 'lcd' does not name a type
lcd.print(" Indicator ");
^
ultrasonic_water_level_sensor.ino:15: error: expected constructor, destructor, or type conversion before '(' token
delay(2000);
^
ultrasonic_water_level_sensor.ino:17: error: expected constructor, destructor, or type conversion before '(' token
digitalWrite(trigger,HIGH);
^
ultrasonic_water_level_sensor.ino:18: error: expected constructor, destructor, or type conversion before '(' token
delayMicroseconds(10);
^
ultrasonic_water_level_sensor.ino:19: error: expected constructor, destructor, or type conversion before '(' token
digitalWrite(trigger,LOW);
^
ultrasonic_water_level_sensor.ino:20: error: expected constructor, destructor, or type conversion before '(' token
delayMicroseconds(2);
^
ultrasonic_water_level_sensor.ino:21: error: 'time' does not name a type
time=pulseIn(echo,HIGH);
^
ultrasonic_water_level_sensor.ino:22: error: 'distance' does not name a type
distance=time*340/20000;
^
ultrasonic_water_level_sensor.ino:23: error: 'lcd' does not name a type
lcd.clear();
^
ultrasonic_water_level_sensor.ino:24: error: 'lcd' does not name a type
lcd.print("Water Space In ");
^
ultrasonic_water_level_sensor.ino:25: error: 'lcd' does not name a type
lcd.setCursor(0,1);
^
ultrasonic_water_level_sensor.ino:26: error: 'lcd' does not name a type
lcd.print("Tank is: ");
^
ultrasonic_water_level_sensor.ino:27: error: 'lcd' does not name a type
lcd.print(distance);
^
ultrasonic_water_level_sensor.ino:28: error: 'lcd' does not name a type
lcd.print("Cm");
^
ultrasonic_water_level_sensor.ino:30: error: expected unqualified-id before 'if'
if(distance<12 && temp==0)
^
ultrasonic_water_level_sensor.ino:44: error: expected unqualified-id before 'else'
else if(distance<12 && temp==1)
^
exit status 1
'lcd' does not name a type

Please help!

Submitted by Gautam Kr. Mandal on Wed, 06/01/2016 - 14:05

Permalink

Dear Sir, I've decided to take up this project for my water tank. By please clear following doubts. Will this circuit switch on or off the pump and display the full or empty condition only? If I want intermediate status of water level, what code is required? Pl give that code for continuous monitoring of water level. Moreover the circuit is meant for display to be placed near the pump only? If I want to keep the controller i.e arduino with display at remote place with minimum no. of long cabling, what to do? Thank you.

Submitted by yedukn on Fri, 06/10/2016 - 23:00

Permalink

When the program runs and if the conditions are going to turn on the motor, the 8th pin continuously becomes ON until the condition for OFF executes.

ie, if we add
Serial.println("ON");
with digitalWrite(motor,HIGH);

the output in the serial monitor will be like this;

ON
ON
ON
ON
ON
ON

and so on.....until an OFF reaches.

Does this makes any problem to the relay driver or to the relay or to the motor? Does the program needs any modifications or not?

Submitted by abhi on Mon, 08/22/2016 - 16:24

Permalink

i try to make this project through this way. but in simulation in proteus the lcd display did not showing any type of information . can you please help us. i never make any changes in programing too...

Submitted by Md. Abu Raihan on Thu, 11/17/2016 - 03:33

Permalink

On the component list I see 7806 and PVT, but on the schematic diagram I can't locate it, please help me..I want to do this project.

Submitted by NITHIN S U on Thu, 02/09/2017 - 15:37

Permalink

Dear Sir, I've decided to take up this project for my water tank. By please clear following doubts. Will this circuit switch on or off the pump and display the full or empty condition only? If I want intermediate status of water level, what code is required? Pl give that code for continuous monitoring of water level. Moreover the circuit is meant for display to be placed near the pump only? If I want to keep the controller i.e arduino with display at remote place with minimum no. of long cabling, what to do? Thank you.

Submitted by Nasir on Tue, 04/18/2017 - 09:37

Permalink

Hey.
I am willing to make this for my water tank which is located at the 3rd floor of my house.
My question is that if i place Ultrasonic sensor inside the tank and place remaining assembly at ground floor then should i use any amplifier for the Ultrasonic sensor or the transmitted signal will be enough to travel to ground floor without any disturbance?

Submitted by Mohammed Sulaiman on Mon, 07/17/2017 - 13:03

Permalink

I didn't understand why you use U2 (ULN2003) for control a 6V or 12V relay? it's enough to control with BC547 and it will be more power saver.

Submitted by chucky on Mon, 07/24/2017 - 09:47

Permalink

i want to use a relay instead of a motor. can some one help me with the code, im new to ardiuno

Submitted by sachin mahajan on Mon, 07/24/2017 - 15:43

Permalink

sir, what is the need of steeoer motor in these project. can i use simple motor instead of steeper motor

Submitted by Omair on Sun, 09/24/2017 - 12:55

Permalink

Hello, Instead of displaying water level on LCD, can we send sms to predefine mobile numbers using GSM module but it should not flood the inbox with messages that tank is now emply. if yes then can someone help me with the software code as I am new to this and I have no software background. My objective is i need to automate underground water tank and tank notify me when the water level reached to certain low level so that i can call the water company and they come and fill up my underground tank.

Submitted by samson on Mon, 10/23/2017 - 03:17

Permalink

i copied the simulation and code correctly but only the motor is rotate, buzzer and lcd are not working what may be the fault

Submitted by manpreet singh on Sat, 11/11/2017 - 09:20

Permalink

hello sir
I have
1 sound senseor
2 HC-05 Buletooth module
sir,how to interface soundsensor with HC-05 module when tank is fullHC-05 trans =mit signal to other HC-05 module and get output on Buzzer or LCd

Submitted by MOATH AL-HARBI on Sun, 11/19/2017 - 11:02

Permalink

Can anyone help me answer the following questions?

1. How can I modify the code if I want to add another ultrasound sensor for the ground tank?
2. What does 12V represents? ( Does it represents computer connection ? )

Thank you

Submitted by Assaf faisal on Sat, 01/06/2018 - 02:35

Permalink

Hi
Can we get the water level signal sent to a mobile by a Bluetooth or remote signal device connected to the board.

Submitted by dipen on Thu, 02/08/2018 - 18:13

Permalink

we compleate this circuit but code is wrong in this site lcd is light up but no words are visible please send right code

Submitted by Vaishnavi on Wed, 03/14/2018 - 08:17

Permalink

I've tried this project and connected everything as directed. But mu lcd is not showing any display in it. Plzz help me out sir as early as possible

Submitted by sukruth on Thu, 03/15/2018 - 16:30

Permalink

Can i use this automatic water level indicator and controller as fuel level indicator.If yes please provide the circuit diagram for the fuel level indicator also

Submitted by Victor on Fri, 03/16/2018 - 12:46

Permalink

Hello there..please can i replace the arduino uno with an arduino nano?..if yes,what changes do i make to the schematic and code

Submitted by Thomas Joseph on Mon, 03/26/2018 - 03:52

Permalink

Dear Sir,

Very interesting project and it is working fine … i have request on this program.

As per this code motor turn ON water level less than “X” level, OK, the motor started pumping the water ;But in case lower tank was empty or some other reasons the TANK water level not increasing from the “X” level, we have to TURN OFF the motor for safety purpose.

For example: current water level is >60 CM and motor is ON,BUT after 3 MIN still water level not increasing or not reached a specific level( Eg: 50CM) we have to turn of the motor .

So this is my requirement how do I resolve this, could you please help me.

Submitted by sukruth on Tue, 04/03/2018 - 14:24

Permalink

Code is executed and uploading to arduino but lcd did not showing any display.please what can i do tell as soon as possible.

Submitted by ARUN KUMAR on Wed, 04/11/2018 - 13:08

Permalink

By using this circuit and diagram everything is working instead of LCD. I checked my connection again and again but i cant find the problem then i search in google and i do it another connection then lcd glow but it cant show tank is full ya motor started.please suggest me wht am i do

Submitted by Andrea F on Mon, 07/02/2018 - 23:04

Permalink

Thaks for the idea, so I have some problems to turn off the pum water, Could you help me?

Submitted by Samuela Batini… on Thu, 07/26/2018 - 05:14

Permalink

Hello Group,
Just a humble query. Is there a Ultrasonic Sensor Module that can go further than 400cm. Will like to use for a taller tank.
Please advise.
Thanks