Introduction:



In this tutorial, we are going to learn how to make an automatic water level controller and indicator for your home water tank.For this tutorial we are going to use HC-SR04 which an ultrasonic distance measuring sensor, using that first of all we will calculate the depth of the water in the water tank then accordingly we will display the depth using some led and On/Off the Water motor using a Single Relay Board. So let's Start making.



Parts Required:




  1. HC-SR04


  2. Arduino Uno


  3. Single Relay Board


  4. AC /  DC Water Pump Motor


  5. Bread Board


  6. 5 X 148 Ohm Resistor

  7. 10 X LEDs


  8. Vero Board




Procedure:




  1. First Of all place 10 led in a Vero Board.


  2. Now Connect the Similar color Led's VCC and GND As connected in the Diagram below.


  3. Now Make a Common GND for all the LED.


  4. Now add  148 Ohm Resistor to each of the VCC of the same color LED as connected in the diagram below.


  5. We have defined VCC of different LED as L1, L2, L3, L4, L5. Here L1 is the VCC of RED LED and Similarly L5 for the Green LED VCC.

  6. Now Connect L1, L2, L3, L4, L5 to Arduino Pin 1, 2, 3, 4, 5. and common GND to GND of the Arduino, As connected in the Diagram below.


  7. Now Connect the VCC and GND of the Relay Board to the VCC, GND of the Arduino, Signal Pin of the relay board to the Pin 7 of the Arduino Uno. 


  8. Now Connect the HC-SR04 Vcc and GND to the VCC and GND of the Arduino Uno.Trigger pin of HC-SR04 to the Pin 8 of the Arduino Uno.Echo Pin of the HC-SR04  to the Pin 9 of the Arduino Uno.


  9. Now its Time to connect our Water Pump.Connect one point of the water pump to the Power Supply and another point of the water pump to the Common Point Of the Relay Board.Connect the other pin of the power supply to the NO(Normally Open) Point of the Relay Board as connected in the diagram below.


  10. Now, let's Upload the Arduino Code to the Arduino Uno.But Before Uploading the Arduino You have to make Small Changes in the Arduino Code. Measure your Water tank in the form of Centimeter,


  11. Now here is the Arduino Code:

    /* This Code is Written By Sai Tat Sat Mishra
    * Founder Of http://www.Beginnertopro.in
    * On Date:31/12/2017
    */

    // defines pins numbers
    const int trigPin = 8;
    const int echoPin = 9;
    //height of the water tank in centimeter
    const int height_tank=25;

    //pin numbers of LED Pannel
    const int level1=1;
    const int level2=2;
    const int level3=3;
    const int level4=4;
    const int level5=5;
    //Pin Number of The Motor Relay
    const int motor_relay=7;

    // defines variables
    int distance;
    int duration;

    void setup() {
    pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
    pinMode(echoPin, INPUT); // Sets the echoPin as an Input
    pinMode(level1,OUTPUT);//Set the Level1 pin as an OUTPUT
    pinMode(level2,OUTPUT);//Set the Level2 pin as an OUTPUT
    pinMode(level3,OUTPUT);//Set the Level3 pin as an OUTPUT
    pinMode(level4,OUTPUT);//Set the Level4 pin as an OUTPUT
    pinMode(level5,OUTPUT);//Set the Level5 pin as an OUTPUT
    pinMode(motor_relay,OUTPUT);//Set the Motor Relay Pin as an OUTPUT
    Serial.begin(9600); // Starts the serial communication
    }
    void loop() {
    distance=ping();
    int division_lenght=height_tank/5;
    int level=distance/division_lenght;
    level=5-level;
    Serial.println(level);
    Serial.println(distance);
    if(level==1){
    digitalWrite(level1,HIGH);
    digitalWrite(level2,LOW);
    digitalWrite(level3,LOW);
    digitalWrite(level4,LOW);
    digitalWrite(level5,LOW);
    digitalWrite(motor_relay,HIGH);
    Serial.println("motor On");
    }else if(level==2){
    digitalWrite(level1,HIGH);
    digitalWrite(level2,HIGH);
    digitalWrite(level3,LOW);
    digitalWrite(level4,LOW);
    digitalWrite(level5,LOW);
    digitalWrite(motor_relay,HIGH);
    Serial.println("motor On");
    }else if(level==3){
    digitalWrite(level1,HIGH);
    digitalWrite(level2,HIGH);
    digitalWrite(level3,HIGH);
    digitalWrite(level4,LOW);
    digitalWrite(level5,LOW);
    digitalWrite(motor_relay,HIGH);
    Serial.println("motor On");
    }else if(level==4){
    digitalWrite(level1,HIGH);
    digitalWrite(level2,HIGH);
    digitalWrite(level3,HIGH);
    digitalWrite(level4,HIGH);
    digitalWrite(level5,LOW);
    digitalWrite(motor_relay,HIGH);
    Serial.println("motor On");
    }else if(level==5){
    digitalWrite(level1,HIGH);
    digitalWrite(level2,HIGH);
    digitalWrite(level3,HIGH);
    digitalWrite(level4,HIGH);
    digitalWrite(level5,HIGH);
    digitalWrite(motor_relay,LOW);
    Serial.println("motor OFF");
    }
    delay(1000);
    }

    int ping(){
    // Clears the trigPin
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    // Sets the trigPin on HIGH state for 10 micro seconds
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    // Reads the echoPin, returns the sound wave travel time in microseconds
    duration = pulseIn(echoPin, HIGH);
    // Calculating the distance
    distance= duration*0.034/2;
    // Prints the distance on the Serial Monitor
    return distance;
    }




     



  12. Now Upload the Code to your Arduino Uno. Fix the HC-SR04 in the Top Of your Water tank and Enjoy your Automated Water Level Controller And Indicator.



For making Watch this Video: