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

 

Comments (40)

  • Mohammed S M Nayon 's picture
    Mohammed S M Nayon

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

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

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

    Dec 30, 2015
  • Maddy's picture
    Maddy

    use only one channel or one relay.

    Feb 08, 2016
  • suresh's picture
    suresh

    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

    Jan 29, 2016
  • F8EBL radio's picture
    F8EBL radio

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

    Feb 03, 2016
  • Don Arduino gizmo's picture
    Don Arduino gizmo

    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.

    May 05, 2017
  • Veilantah Ramirez's picture
    Veilantah Ramirez

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

    Jul 15, 2017
  • boaz's picture
    boaz

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

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

    temp is used as a variable.

    we can say temporary variable.

    Feb 07, 2016
  • suman's picture
    suman

    why delay is given in every step?

    Feb 12, 2016
  • Bongumusa's picture
    Bongumusa

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

    Feb 28, 2016
  • Amir Hakim Bin Zahari's picture
    Amir Hakim Bin ...

    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

    Mar 16, 2016
  • Abhishek's picture
    Abhishek

    How are you simulating Ultrasonic sensor?

    Mar 28, 2016
  • adli's picture
    adli

    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

    Feb 13, 2017
  • sanoj k's picture
    sanoj k

    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 ?

    Mar 17, 2016
  • Abhishek's picture
    Abhishek

    yes, you can use 5v Relay.

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

    how to get library file of lcd

    Mar 22, 2016
  • Abhishek's picture
    Abhishek

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

    Mar 28, 2016
  • Anthony Tortolani's picture
    Anthony Tortolani

    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.

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

    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!

    Apr 16, 2016
  • Gautam Kr. Mandal's picture
    Gautam Kr. Mandal

    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.

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

    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

    Jun 04, 2016
  • yedukn's picture
    yedukn

    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?

    Jun 10, 2016
  • Niraj's picture
    Niraj

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

    Jun 25, 2016
  • abhi's picture
    abhi

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

    Aug 22, 2016
  • Abhishek's picture
    Abhishek

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

    Aug 22, 2016
  • dexter's picture
    dexter

    thank you so much for this!

    Dec 18, 2016
  • Md. Abu Raihan's picture
    Md. Abu Raihan

    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.

    Nov 17, 2016
  • Maddy's picture
    Maddy

    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.

    Dec 10, 2016
  • ell's picture
    ell

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

    Nov 25, 2016
  • Keito's picture
    Keito

    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.

    Jan 17, 2017
  • irfan's picture
    irfan

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

    Jan 28, 2017
  • NITHIN S U's picture
    NITHIN S U

    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.

    Feb 09, 2017
  • Nasir's picture
    Nasir

    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?

    Apr 18, 2017
  • Mohammed Sulaiman's picture
    Mohammed Sulaiman

    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.

    Jul 17, 2017
  • chucky's picture
    chucky

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

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

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

    Jul 24, 2017
  • Luyanda's picture
    Luyanda

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

    Aug 05, 2017
  • Omair's picture
    Omair

    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.

    Sep 24, 2017

Leave a comment