17/02/21

Water Level Indicator & Alarm For Tank Overflow using Arduino & Ultrasonic Sensor

 



OUTPUT  VIDEO:-

                 Water Level Indicator & Alarm for Water tank Overflow                    


Full Video With Steps  


COMPONENTS :

1. Arduino
2.Ultrasonic Sensor
3.Buzzer
4.Water tank (or any bucket)
5.Jumper Wire (Male - Female)


Ultrasonic Sensor :- Sensor Gives Distance bewteen Sensor itself and Any Object or Obstacle in its path.

Ultrasonic sensors sends Sound Waves,which travels and when encounter any obstacle it gets Reflected .

How, We can Calculate Distance Using Ultrasonic Sensor ?

   Ultrasonic sensor Determining Distance 

How We can Calculate Distance Using Ultrasonic Sensor ?

Velocity = Distance travelled / Time Taken 
Therefore, Distance = Velocity * Time
 
Here,  Velocity of Sound in air = 342 m/s
& Time = 2t as Time taken to reach and Time taken to get Reflected

Now,Sensor sends Micro Pulses of Frequency
now, Controller gets time taken by sound to reach and reflected is known .
Velocity of Sound in air is fixed = 342 m/s 

So,  Distance = Velocity of sound in air * Time taken /2

STEPS :

1. Connect Ultrasonic sensor with Arduino.
2. To calibrate Ultrasonic sensor
First, Mount the sensor above the height of Tank.


Now,Calculate distance between Sensor and Bottom of Tank  using Scale Measurement ,& also with ultrasonic ,in order to confirm that ultrasonic sensor is showing Correct Readings.

See, Demo 
-  
           Calibrating Sensor


                               
Now, Water level = Distance between Sensor & Bottom of Tank - Changing distance of sensor and water.

See, Demo
Calculation Part for Water level

Here, If total distance bewteen Sensor and Bottom of  Tank = 20 cm,
than, when Water is filled ,the distance bewteen sensor & Water Decreases i.e = Water level
So, Water level =   total distance bewteen Sensor and Bottom of Tank - changing distance



 SETUP :- 


Step 3:- Connections

 

Trig pin of sensor to Pin 8 Of Arduino
Echo pin of sensor to Pin 9 Of Arduino
Vcc  to 5v
Gnd to Arduino ground 
Buzzer Positive red wire to Pin 13
Buzzer ground Black wire to Ground 


CODING :-


 Expalantion :-








Copy Code from below & u can try :-

// Connections  defines pins numbers
const int trigPin = 8;  // Sensor Trigger pin to Arduino pin 8
const int echoPin = 9; // Sensor ECHO pin to Arduino pin 9
int const buzzPin = 13;  // Buzzer Red wire to Arduino pin 13 & black wire to Arduino Ground 

// defines variables
int waterlevel;    // Variable for storing Water level values ,Water level Rise 
long duration;
int distance;     // distance between Sensor and object , here object = Water
void setup() {
  //depth of tank is 11cm 
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(buzzPin, OUTPUT); // buzz pin is output to control buzzering
Serial.begin(9600); // Starts the serial communication
}
void loop() {
  
// 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 = velocity of sound in air * time taken to reach and reflect/2
distance= duration*0.034/2;  // Velocity of Sound in Air = 342 m/s 


// Prints the distance on the Serial Monitor
//Serial.print("Distance= cm ");
//Serial.println(distance);


waterlevel=20-distance; // Sensor placed at 20cm away from bottom of bucket
Serial.println(waterlevel); // function for water level
Serial.print("\nwaterlevel=  ");  // Prints 
Serial.print(" (cm)");  // Prints unit " cm "
delay(10);

// For determining how Volume Water in litres Filled at Certain Height
// So 20 cm = 5.6 litres and, so for 1 litre = 3.2cm height 

// conditional Statement
if (waterlevel ==3.2) //  if water reaches to the height 3.2cm than Volume is 1 litre
{  
Serial.print("\n Water = 1 litre\n");
delay(1000);
}
else if (waterlevel == 6.4)
{
  Serial.print("\n Water = 2 litre\n");
  delay(1000); 
}
else if (waterlevel == 9.6)
{
  Serial.print(" \n Water = 3 litre\n"); 
  delay(1000);
}
else if (waterlevel == 12.8)
{
  Serial.print(" \n Water = 4 litre\n"); 
  delay(1000);
}
else if (waterlevel == 16)

{
  Serial.print("\n Water = 5 litre\n"); 
  delay(1000);
}

// For Tank OVERFLOW ALARM
// if distance between Sensor and water is 2cm or less , Buzzer should start BUZZING.. and With Message
// " WATER OVERFLOWING "

if (distance <= 2) {
Serial.print("\nWater Overflowing\n ");   // Indicates " Water overflowing "
delay(10);
// Buzz
digitalWrite(buzzPin, HIGH);   // Switch Buzzer HIGH or ON or starts Buzzing 
} else {
// Don't buzz
digitalWrite(buzzPin, LOW);   // else Buzzer off

}

}



No comments:

Post a Comment