Lab set Program-11
Water Level Depth Detection System using Ultrasonic Sensor
Objective
To develop a water-level depth detection system using an ultrasonic sensor (HC-SR04) and Arduino, where the sensor measures the distance to the water surface and calculates the water level in a tank.
Learning Outcomes
After completing this experiment, students will be able to:
-
Interface an ultrasonic sensor with Arduino.
-
Measure distance using TRIG–ECHO timing.
-
Convert distance readings into water depth level.
-
Display measurements on the Serial Monitor.
-
Understand practical applications in water tanks, overhead tanks, sumps etc.
Components (from Tinkercad Palette)
-
Arduino Uno
-
Ultrasonic Sensor (HC-SR04)
-
Breadboard
-
Jumper Wires
-
(Optional) LEDs to represent tank levels
Circuit Wiring (Exact)
-
Ultrasonic Sensor → Arduino
-
VCC → 5V
-
GND → GND
-
TRIG → Pin 9
-
ECHO → Pin 10
-
-
No additional components required.
-
Keep the ultrasonic sensor facing a flat object in Tinkercad to simulate water surface.
Arduino Sketch
// Lab Program 11: Water Level Depth Detection using Ultrasonic Sensor
#define trigPin 9
#define echoPin 10
long duration;
float distance; // Distance between sensor and water surface
float tankHeight = 30.0; // Height of tank in cm (you can change this)
float waterLevel; // Actual water depth
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop() {
// Trigger pulse
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Measure echo time
duration = pulseIn(echoPin, HIGH);
// Convert time → distance (cm)
distance = duration * 0.034 / 2;
// Calculate water level depth
waterLevel = tankHeight - distance;
if (waterLevel < 0) waterLevel = 0; // Avoid negative values
// Print details
Serial.print("Distance to Water Surface: ");
Serial.print(distance);
Serial.print(" cm | Water Level: ");
Serial.print(waterLevel);
Serial.println(" cm");
delay(700);
}
How It Works (Explain to Students)
-
The ultrasonic sensor sends a sound pulse and measures how long it takes to return.
-
This time is converted into a distance from the sensor to the water surface.
-
If the tank height is known (example: 30 cm):
Water Level = Tank Height − Distance Measured -
If the water surface is close → water level is high.
-
If the distance is large → water level is low.
-
The output shows both values in the Serial Monitor.
Common Mistakes & Quick Fixes
| Issue | Cause | Fix |
|---|---|---|
| Distance always 0 or very high | TRIG/ECHO swapped | Recheck pin mapping |
| Output not updating | Simulation not running | Click Start Simulation |
| Random values | No object in front of sensor | Place a flat object in front |
| Negative water level | Wrong tankHeight | Adjust tank height value |
Viva / Check-Your-Understanding
-
What physical principle does an ultrasonic sensor use?
-
Why do we divide the pulse duration by 2?
-
How does tank height affect water level calculation?
-
Can ultrasonic sensors measure through water? Why/why not?
-
Where are ultrasonic-based water level systems used in the real world?
Extensions (Mini-Tasks)
-
Add 3 LEDs (low, medium, full) based on water level.
-
Add a buzzer when the tank is almost empty.
-
Display water level on an LCD (16×2).
-
Show the water level percentage (0–100%).
Lab Record (Suggested Headings)
-
Title
-
Objective
-
Components Used
-
Circuit Diagram (Tinkercad Screenshot)
-
Arduino Code
-
Output / Observations
-
Explanation
-
Viva Questions
-
Extensions
Comments
Post a Comment