Automatic Water Level Indicator and Controller using Arduino

Arduino

BySaddam 69

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

 

Get Our Weekly Newsletter!

Subscribe below to receive most popular news, articles and DIY projects from Circuit Digest

Comments

  • Mohammed S M Nayon 's picture
    Mohammed S M Nayon
    Dec 16, 2015

    I'm new with it. Tell me how to collect the code?

  • adane mekonnen's picture
    adane mekonnen
    Apr 04, 2018

    thank you , becuse i support for my idea

  • iman maulana's picture
    iman maulana
    Dec 30, 2015

    Can you tell me how to connect arduino to water pump using relay modul 4 channel?

  • suresh's picture
    suresh
    Jan 29, 2016

    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

  • F8EBL radio's picture
    F8EBL radio
    Feb 03, 2016

    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, .

  • Don Arduino gizmo's picture
    Don Arduino gizmo
    May 05, 2017

    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.

  • Veilantah Ramirez's picture
    Veilantah Ramirez
    Jul 15, 2017

    I think the Aeduino Uno is just fine with 7 to 12v..

  • boaz's picture
    boaz
    Feb 04, 2016

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

  • saddam khan's picture
    saddam khan
    Feb 07, 2016

    temp is used as a variable.

    we can say temporary variable.

  • shriyash patil's picture
    shriyash patil
    Jan 09, 2018

    temp is a temperory variable created to save the data for a temporarily use

  • suman's picture
    suman
    Feb 12, 2016

    why delay is given in every step?

  • Bongumusa's picture
    Bongumusa
    Feb 28, 2016

    On the component list I see PVT, but on the schematic diagram I can't locate it, please help me with that one

  • Amir Hakim Bin Zahari's picture
    Amir Hakim Bin ...
    Mar 16, 2016

    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

  • adli's picture
    adli
    Feb 13, 2017

    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

  • sanoj k's picture
    sanoj k
    Mar 17, 2016

    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 ?

  • Rajib shresths's picture
    Rajib shresths
    Mar 22, 2016

    how to get library file of lcd

  • Abhishek's picture
    Abhishek
    Mar 28, 2016

    Its a core library of Arduino, you don't need to install it, it is already there.

  • Anthony Tortolani's picture
    Anthony Tortolani
    Apr 15, 2016

    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.

  • Anthony Tortolani's picture
    Anthony Tortolani
    Apr 16, 2016

    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!

  • Gautam Kr. Mandal's picture
    Gautam Kr. Mandal
    Jun 01, 2016

    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.

  • syed ehsan's picture
    syed ehsan
    Jun 04, 2016

    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

  • yedukn's picture
    yedukn
    Jun 10, 2016

    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?

  • Niraj's picture
    Niraj
    Jun 25, 2016

    for relay input 5v can given into arduion board??

  • abhi's picture
    abhi
    Aug 22, 2016

    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...

  • Abhishek's picture
    Abhishek
    Aug 22, 2016

    Try changing the code LiquidCrystal lcd(7,6,5,4,3,2); to LiquidCrystal lcd(2,3,4,5,6,7);

  • dexter's picture
    dexter
    Dec 18, 2016

    thank you so much for this!

  • krishna's picture
    krishna
    Aug 30, 2018

    tq for replay i have change the code and its work

  • Md. Abu Raihan's picture
    Md. Abu Raihan
    Nov 17, 2016

    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.

  • Maddy's picture
    Maddy
    Dec 10, 2016

    IC 7806 is clearly shown in circuit diagram and PVT is green color's terminal block on Relay board, you can see in image on the top.

  • ell's picture
    ell
    Nov 25, 2016

    hello, the code is giving me some errors when i try to run it with turbo C.

  • Keito's picture
    Keito
    Jan 17, 2017

    Is it also possible if I wan't to add a dispense in the water controller? Example, if I want to maintain this specific water level, any excess water added will be dispense automatically.

  • irfan's picture
    irfan
    Jan 28, 2017

    when i can past this code lcd cannot display any think plzz urgently tell me about it

  • NITHIN S U's picture
    NITHIN S U
    Feb 09, 2017

    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.

  • Nasir's picture
    Nasir
    Apr 18, 2017

    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?

  • Mohammed Sulaiman's picture
    Mohammed Sulaiman
    Jul 17, 2017

    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.

  • chucky's picture
    chucky
    Jul 24, 2017

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

  • sachin mahajan's picture
    sachin mahajan
    Jul 24, 2017

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

  • Luyanda's picture
    Luyanda
    Aug 05, 2017

    How to add keypad in this circuit to selecm9t required water level please help

  • Omair's picture
    Omair
    Sep 24, 2017

    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.

  • samson's picture
    samson
    Oct 23, 2017

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

  • manoj's picture
    manoj
    Oct 26, 2017

    why we use "temp" variable ?

  • manpreet singh's picture
    manpreet singh
    Nov 11, 2017

    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

  • AISHA's picture
    AISHA
    Nov 14, 2017

    Hi manpreet,

    You cannot use a HC-05 Bluetooth module without a Microcontroller because they work with USART

  • suriya 's picture
    suriya
    Nov 15, 2017

    how to use arduino codes for this project????im really confused..

  • MOATH AL-HARBI's picture
    MOATH AL-HARBI
    Nov 19, 2017

    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

  • Sabyasachi pal's picture
    Sabyasachi pal
    Dec 21, 2017

    How to stop running dry pump if reservoir water get empty?

  • Assaf faisal's picture
    Assaf faisal
    Jan 06, 2018

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

  • dipen's picture
    dipen
    Feb 08, 2018

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

  • Vaishnavi 's picture
    Vaishnavi
    Mar 14, 2018

    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

  • sukruth's picture
    sukruth
    Mar 15, 2018

    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

  • Victor's picture
    Victor
    Mar 16, 2018

    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

  • AISHA's picture
    AISHA
    Mar 16, 2018

    Yes you can use nano, no changes are needed in the code and hardware, just connect the pins on nano just as you connect to to a UNO

  • Kapil Chouhan's picture
    Kapil Chouhan
    Mar 17, 2018

    Hi sir... I wanted to know what's the use of temp here and what kind of data it is holding.

  • Thomas Joseph's picture
    Thomas Joseph
    Mar 26, 2018

    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.

  • Arunkumar S's picture
    Arunkumar S
    Mar 28, 2018

    SIR MY PROJECT USING SENSOR IS LEVEL SENSOR SIR . I NEED HELP FOR PROGRAM SIR AUTOMATIC WATER LEVEL PROGRAM I S DOUBT SIR SO PLEASE PROGRAMING SEND ME SIR

  • sukruth's picture
    sukruth
    Apr 03, 2018

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

  • saloni lohiya's picture
    saloni lohiya
    Apr 06, 2018

    i have complied the code but nothing is being displayed on lcd ,what should i doo,

  • Aswinth Raj's picture
    Aswinth Raj
    Apr 06, 2018

    Check your connections, try some simple LCD program and see if it is working. Also make sure your contrast level for the LCD is set properly 

  • ARUN KUMAR's picture
    ARUN KUMAR
    Apr 11, 2018

    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

  • Andri's picture
    Andri
    Apr 11, 2018

    what if buzzer is turned off by switch. If water tank full or Low

  • Yadhuk's picture
    Yadhuk
    Jun 04, 2018

    Thanks for the circuit and explanation. Good reference project.

  • Andrea F's picture
    Andrea F
    Jul 02, 2018

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

  • Samuela Batiniyaqona Vadei 's picture
    Samuela Batiniy...
    Jul 26, 2018

    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

Log in or register to post Comment