CODING :-
Link To download :- https://drive.google.com/file/d/1b-FphGvXEaGMTFvrBYEZvx-Yw5EDEL8_/view?usp=sharing
Expalantion :-
Copy Code from below & u can try :-
// Connections defines pins numbers
const int trigPin = 8; // Sensor Trigger pin to Arduino pin 8const int echoPin = 9; // Sensor ECHO pin to Arduino pin 9int 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 Riselong duration;int distance; // distance between Sensor and object , here object = Water
void setup() {//depth of tank is 11cmpinMode(trigPin, OUTPUT); // Sets the trigPin as an OutputpinMode(echoPin, INPUT); // Sets the echoPin as an InputpinMode(buzzPin, OUTPUT); // buzz pin is output to control buzzeringSerial.begin(9600); // Starts the serial communication
}
void loop() {// Clears the trigPindigitalWrite(trigPin, LOW);delayMicroseconds(2);// Sets the trigPin on HIGH state for 10 micro secondsdigitalWrite(trigPin, HIGH);delayMicroseconds(10);digitalWrite(trigPin, LOW);// Reads the echoPin, returns the sound wave travel time in microsecondsduration = 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 bucketSerial.println(waterlevel); // function for water levelSerial.print("\nwaterlevel= "); // PrintsSerial.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);// BuzzdigitalWrite(buzzPin, HIGH); // Switch Buzzer HIGH or ON or starts Buzzing} else {// Don't buzzdigitalWrite(buzzPin, LOW); // else Buzzer off}}
No comments:
Post a Comment