Sie sind auf Seite 1von 18

Automatic Water Level Indicator and Pump

Controller using Arduino


***Old Blog Has been removed with the Upgraded Project Details***
Hi All, welcome to yet another video. In this Video we will learn how to
create Fully Automatic Water Tank Level Controller with DRY PUMP
RUN PROTECTION feature using Arduino Nano.

Block Diagram
Let’s learn the Designing and Working of this project using given block
diagram.
The first block is Arduino Nano, Arduino is the brain of this project. It
will take input from the sensors and control all other units according to
the value received.
The second block is 16x2 LCD display. This unit will display the Water
Level in percentage as well as in Bar Diagram, it will also show the Pump
status. This section will also notify us whenever the Sump tank is empty.
The third block is the Sonar Sensor. This is used to measure the water
level present on the overhead water tank.
Let’s understand the working principle of the Sonar sensor.

Sonar Sensor emits an ultrasound at 40 kilohertz, which travels through


the air, and if there is an object or obstacle on its path, It will bounce
back to the module.
Arduino will use the echo pin, present on Ultrasonic sensor to measure
sound wave travel time in microseconds.
Considering the travel time and the speed of the sound, you can calculate
the distance using the formula shown here.
The fourth block is the Sump Water level sensor. These are two copper
wires which are dipped in to the Sump Water Tank. And Analog pin
present on the Arduino Nano will be used to sense the presence of water.
The fifth block is the push button, this is used to measure the Tank height
at the time of installation of this Circuit. This can further used if you wish
to replace the water tank with a new one.
The sixth block is the Internal Relay plush Water Pump. Arduino will
control the Water pump using the Internal relay. The relay present on
the circuit can be used to start any kind of 1 HP single phase Water pump
without starters.
The Seventh block is also the used for the same purpose, you can use this
section to replace the internal relay with any relay which is operating in
5V DC to get better power rating for driving the Water pump.
The Eight block is the Buzzer, this is used to notify when the sump tank is
empty.
Required Components
Now let’s move to the components required to build this project. You can
buy all these components from third party vendors like E-bay, Amazon
etc.
 Arduino Nano……….. 
 16*2 LCD Display........
 5V Relay......................
 Piezo Buzzer...............
 Push Button................
 LED............................
 BC 547 Transistor.......
 IN4007 Diode..............
 220 Ω Resistor.............
 Trimpot 10K Ω Variable Resistor....
 10K Ω Resistor(6 pcs)...
 1K Ω Resistor................
 3P PCB Screw Terminal Block Connector.....
 Female Pin Header Connector Strip.......
 Male Pin Header Connector Strip.......
 5V relay board(optional).......
 Jumper wire..  

Designing the PCB and Generating the Gerber File


So first of all, you need to design your PCB. You can choose online or
offline platform for designing your PCBs.
Here we used Fritzing software to design the PCB.  Go to Fritzing, design
your circuit using the Breadboard tab. You can pick the required
components to build the circuit from the top right search panel and add
it to the Breadboard tab.

Refer the Circuit diagram shown here to make one by your own. Please
visit the link in the description to know more about the Circuit. I have
also added wire sensors to measure the Overhead tank water level in this
circuit and I will be doing a separate video to show you how to replace
the sonar sensor and measure the water level using these wire sensors in
my next video. In this video let’s stick to Sonar sensor.
Go to PCB tab, you could see the PCB Layout automatically created
according to the design that we made in Breadboard tab.

 Arrange the components on to the PCB.Now Go to Routing and Click


on Autoroute. This will rearrange the connections to fit with the PCB.
Once the design is done you can export it to a Gerber format. 
Go to File-> Export-> For Production-> Extended Gerber.

Create a new folder and click on Select Folder. This will export all files to
that folder.
Now compress the Folder to ZIP or RAR format using any of the Zipping
Software. 

IDE
/*
  LiquidCrystal Library - Hello World

 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal


 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and youre
 can usually tell them by the 16-pin interface.

 This sketch prints "Hello World!" to the LCD


 and shows the time.

  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * LCD VSS pin to ground
 * LCD VCC pin to 5V
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008


 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe
 modified 7 Nov 2016
 by Arturo Guadalupi

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld

*/

// include the library code:

#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; // define the Arduino pins used to
connect with the LCD pins RS, EN, D4 to D7
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);//initialize the library by associating any needed LCD
interface pinwith the arduino pin number it is connected to

#include <NewPing.h> // Include  library used for measuring the distance using HC-SR 06
sonar sensor

#define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     7  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 500 // Maximum distance we want to ping for (in centimeters).
Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins


and maximum distance.
#define RELAYPIN 8 // Arduino pin tied to Relaypin of the Relay Circuit
#define EXTRELAYPIN 13 // Arduino pin tied to vin pin of the External Relay Circuit
#define BUZZER 9 // Arduino pin tied to +ve terminal of the Buzzer
float val;
#include <EEPROM.h>
int addr = 0;
int addr2 = 1;
int flag;
byte readval;

#define buttonPin 10
int buttonState = 0;         // variable for reading the pushbutton status
float TankHeight, MaxWaterLevel, EmptySpace, SonarReading, ActualReading,  Temp;
int percentage;
int SpmpSensorPin = A0;    // set A0 as the Spump water sensor pin
int SpmpsensorValue = 0;  // variable to store the value coming from the sensor

// Creating Charaters for Bar Graph and Reverse Mode Icon


byte Level0[8] = {
        0b00000,
 0b00000,
 0b00000,
 0b00000,
 0b00000,
 0b00000,
 0b11111,
 0b11111
};
byte Level1[8] = {
        0b00000,
 0b00000,
 0b00000,
 0b00000,
 0b11111,
 0b11111,
 0b11111,
 0b11111
};
byte Level2[8] = {
        0b00000,
 0b00000,
 0b11111,
 0b11111,
 0b11111,
 0b11111,
 0b11111,
 0b11111
};
byte Level3[8] = {
        0b11111,
 0b11111,
 0b11111,
 0b11111,
 0b11111,
 0b11111,
 0b11111,
 0b11111
};
byte NoLevel[8] = {
        0b00000,
 0b00000,
 0b00000,
 0b00000,
 0b00000,
 0b00000,
 0b00000,
 0b00000,
};

void setup() {
  Serial.begin(9600);
  lcd.createChar(0, Level0);
  lcd.createChar(1, Level1);
  lcd.createChar(2, Level2);
  lcd.createChar(3, Level3);
  lcd.createChar(4, NoLevel);
  Serial.println(flag);
  lcd.begin(16, 2); // set up the LCD's number of columns and rows:
  pinMode(RELAYPIN,OUTPUT);// Relay pin as output pin
  pinMode(EXTRELAYPIN,OUTPUT);// External Relay pin as output pin
  digitalWrite(RELAYPIN,LOW); //Turn off the relay
  digitalWrite(EXTRELAYPIN,HIGH); //Turn off the external relay(External Relay I used
was turning on while giving LOW signal, Check your one while doing the program)
  pinMode(BUZZER,OUTPUT);// Buzzer pin as output pin
  digitalWrite(BUZZER,LOW);  //Turn off the Buzzer
  lcd.print("Automatic  Water");
  lcd.setCursor(0,1);
  lcd.print("*Pumping System*");
  delay(2000);
  lcd.clear();
   lcd.print("Long Press Button to Change Tank Height");
  delay(1000);
  for (int positionCounter = 0; positionCounter < 23; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft();
    // wait a bit:
    delay(300);
 }
delay(1000);
lcd.clear();
lcd.print("Tank must be Empty!");
 delay(1000);
   for (int positionCounter = 0; positionCounter < 3; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft();
    // wait a bit:
    delay(300);
 }
 delay(1000);
 lcd.clear();

  
   lcd.print("Change Tnk Height");
  
for (int i=0; i<=5; i++)
{
  lcd.setCursor(0,1);
  lcd.print("  in:");
  lcd.print(5-i);
  lcd.print(" Seconds");
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH)
 {
  TankHeight =sonar.ping_cm();
  EEPROM.write(addr, TankHeight);
 }
delay(1000);
}

  TankHeight= EEPROM.read(addr);
  lcd.clear();
  lcd.print("Tnk Height Set:");
  lcd.setCursor(0,1);
  lcd.print("    ");
  lcd.print(TankHeight);
  lcd.print("cm    ");
  delay(2000);
  lcd.clear();
  MaxWaterLevel=0.85*TankHeight;
  EmptySpace=TankHeight-MaxWaterLevel;
}

void loop() {
  // put your main code here, to run repeatedly:

  delay(50); // Wait 100ms between pings (about 20 pings/sec). 29ms should be the shortest
delay between pings.
  SonarReading=sonar.ping_cm();
  SpmpsensorValue=analogRead(SpmpSensorPin);
  Serial.println(SpmpsensorValue);
  Temp= SonarReading-EmptySpace;
  ActualReading= MaxWaterLevel-Temp;
  percentage=(ActualReading/MaxWaterLevel*100);
  lcd.setCursor(8,0);
  lcd.print("Lev:");
  lcd.print(percentage);
  lcd.print("%    ");
  lcd.setCursor(0, 1);
  lcd.print("LOW");
  lcd.setCursor(11, 1);
  lcd.print("HIGH ");
  if(SpmpsensorValue>=100)
 {
  if(percentage<=20)
 {
  lcd.setCursor(0,0);
  lcd.print("PMP ON  ");
  digitalWrite(RELAYPIN,HIGH);
  digitalWrite(EXTRELAYPIN,LOW);
  flag=1;
  EEPROM.write(addr2, flag);
  flag= EEPROM.read(addr2);
  ZeroPercentage();
 }
  else if(percentage>20 && percentage<=100)
 {
  flag= EEPROM.read(addr2);
  if(percentage>20 && percentage<=100 && flag ==1)
 {
    digitalWrite(RELAYPIN,HIGH);
    digitalWrite(EXTRELAYPIN,LOW);
    lcd.setCursor(0,0);
    lcd.print("PMP ON  ");
    if(percentage>20 && percentage<=25)
      {
        TwentyFivePercentage();
      }
      else if(percentage>25 && percentage<=50)
      {
        FiftyPercentage();
      }
         
    else if(percentage>50 && percentage<=75)
      {
         SeventyFivePercentage();  
      }
    else if(percentage>75 && percentage<=100)
      {
          HundredPercentage();
      }
    }
   else if(percentage>20 && percentage<=100 && flag ==0)
 {
    digitalWrite(RELAYPIN,LOW);
    digitalWrite(EXTRELAYPIN,HIGH);
    lcd.setCursor(0,0);
    lcd.print("PMP OFF ");
    if(percentage>20 && percentage<=25)
      {
       
        TwentyFivePercentage();
   
      }
      else if(percentage>25 && percentage<=50)
      {
        FiftyPercentage();
      }
     
     
    else if(percentage>50 && percentage<=75)
      {
        SeventyFivePercentage();
      }
    else if(percentage>75 && percentage<=100)
      {
        HundredPercentage();
     
      }
    }
   }
  else if(percentage>100)
 {
  delay(500);
  lcd.setCursor(0,0);
  lcd.print("PMP OFF ");
  lcd.setCursor(8,0);
  lcd.print("Lev:");
  lcd.print("100");
  lcd.print("%    ");
  digitalWrite(RELAYPIN,LOW);
  digitalWrite(EXTRELAYPIN,HIGH);
  flag=0;
  EEPROM.write(addr2, flag);
  flag= EEPROM.read(addr2);
  HundredPercentage();
    }
 }
 else if(SpmpsensorValue<=100)
{
  flag= EEPROM.read(addr2);
  if(flag==1)
  { lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("*SumTank Empty*");
    lcd.setCursor(0,1);
    lcd.print("*Pump kept OFF*");
    digitalWrite(BUZZER,HIGH);
    digitalWrite(RELAYPIN, LOW);
    digitalWrite(EXTRELAYPIN, HIGH);
    delay(100);
    digitalWrite(BUZZER,LOW);
    delay(100);
 }
  else if(flag==0)
 {
  lcd.setCursor(0,0);
  lcd.print("STnk MT ");
   
      if(percentage<=20)
      {
        ZeroPercentage();
      } 
      else if(percentage>20 && percentage<=25)
      {
        TwentyFivePercentage();
      }
      else if(percentage>25 && percentage<=50)
      {
        FiftyPercentage();
      }
     
     
    else if(percentage>50 && percentage<=75)
      {
         SeventyFivePercentage();  
      }
    else if(percentage>75 && percentage<=100)
      {
          HundredPercentage();
      }
    else if(percentage>100)
      {
         HundredPercentage();
      }
 }
}
}
void ZeroPercentage()
{
  lcd.setCursor(3, 1);
  lcd.write(byte(4));
  lcd.setCursor(4, 1);
  lcd.write(byte(4));
  lcd.setCursor(5, 1);
  lcd.write(byte(4));
  lcd.setCursor(6, 1);
  lcd.write(byte(4));
  lcd.setCursor(7, 1);
  lcd.write(byte(4));
  lcd.setCursor(8, 1);
  lcd.write(byte(4));
  lcd.setCursor(9, 1);
  lcd.write(byte(4));
  lcd.setCursor(10, 1);
  lcd.write(byte(4));
}
void TwentyFivePercentage()
{
  lcd.setCursor(3, 1);
  lcd.write(byte(0));
  lcd.setCursor(4, 1);
  lcd.write(byte(0));
  lcd.setCursor(5, 1);
  lcd.write(byte(4));
  lcd.setCursor(6, 1);
  lcd.write(byte(4));
  lcd.setCursor(7, 1);
  lcd.write(byte(4));
  lcd.setCursor(8, 1);
  lcd.write(byte(4));
  lcd.setCursor(9, 1);
  lcd.write(byte(4));
  lcd.setCursor(10, 1);
  lcd.write(byte(4));
}
void FiftyPercentage()
{
  lcd.setCursor(3, 1);
  lcd.write(byte(0));
  lcd.setCursor(4, 1);
  lcd.write(byte(0));
  lcd.setCursor(5, 1);
  lcd.write(byte(1));
  lcd.setCursor(6, 1);
  lcd.write(byte(1));
  lcd.setCursor(7, 1);
  lcd.write(byte(4));
  lcd.setCursor(8, 1);
  lcd.write(byte(4));
  lcd.setCursor(9, 1);
  lcd.write(byte(4));
  lcd.setCursor(10, 1);
  lcd.write(byte(4));
}
void SeventyFivePercentage()
{
  lcd.setCursor(3, 1);
  lcd.write(byte(0));
  lcd.setCursor(4, 1);
  lcd.write(byte(0));
  lcd.setCursor(5, 1);
  lcd.write(byte(1));
  lcd.setCursor(6, 1);
  lcd.write(byte(1));
  lcd.setCursor(7, 1);
  lcd.write(byte(2));
  lcd.setCursor(8, 1);
  lcd.write(byte(2));
  lcd.setCursor(9, 1);
  lcd.write(byte(4));
  lcd.setCursor(10, 1);
  lcd.write(byte(4));
}
void HundredPercentage()
{
  lcd.setCursor(3, 1);
  lcd.write(byte(0));
  lcd.setCursor(4, 1);
  lcd.write(byte(0));
  lcd.setCursor(5, 1);
  lcd.write(byte(1));
  lcd.setCursor(6, 1);
  lcd.write(byte(1));
  lcd.setCursor(7, 1);
  lcd.write(byte(2));
  lcd.setCursor(8, 1);
  lcd.write(byte(2));
  lcd.setCursor(9, 1);
  lcd.write(byte(3));
  lcd.setCursor(10, 1);
  lcd.write(byte(3));
}

Let's assemble it together 


We are going to assemble the project as shown in this diagram.
Please refer the sequence shown in this video while assembling the
components together.

For the demo purpose we are using a 12V DC water pump. This circuit
can support  up to 1 HP Single phase water pump if you wish to use this
circuit for Application level.

If you wish you can also connect a 5V relay having better current rating
on to this circuit.

Das könnte Ihnen auch gefallen