Introduction
Water tanks are commonly installed on rooftops and in residential, agricultural and industrial applications. Knowing the approximate water level helps prevent overflow and makes water management easier.
An ultrasonic sensor can measure the distance from the top of a tank to the water surface without physically touching the water.
Block Diagram
┌────────────────────┐
│ Water Tank │
│ │
│ Water Surface │
└───────────────────┘
↑
│ Ultrasonic
│ Measurement
↓
┌────────────────────┐
│ HC-SR04 │
│ Ultrasonic Sensor │
└───────────────────┘
│
↓
┌────────────────────┐
│ Arduino UNO │
│ Level Calculation │
└─────────┬──────────┘
│
↓
┌────────────────────┐
│ 16×2 LCD │
│ Water Level % │
└────────────────────┘
Hardware Requirement
| Component | Quantity | Purpose |
|---|---|---|
| Arduino UNO | 1 | Main controller |
| HC-SR04 Ultrasonic Sensor | 1 | Measures water level |
| 16×2 LCD | 1 | Displays water level |
| 10KΩ Potentiometer | 1 | LCD contrast |
| Breadboard | 1 | Circuit assembly |
| Jumper Wires | As required | Connections |
| Water Tank/Container | 1 | Testing |
Circuit Diagram
ARDUINO UNO
┌──────────────────┐
│ │
D9 ───┤ TRIG │
D10 ───┤ ECHO │
│ │
D2 ───┤ LCD RS │
D3 ───┤ LCD E │
D4 ───┤ LCD D4 │
D5 ───┤ LCD D5 │
D6 ───┤ LCD D6 │
D7 ───┤ LCD D7 │
│ │
5V ───┤ │
GND ───┤ │
└───────┬──────────┘
│
┌───────────┴───────────┐
│ │
▼ ▼
┌─────────────┐ ┌─────────────┐
│ HC-SR04 │ │ 16×2 LCD │
│ │ │ │
│ TRIG ← D9 │ │ RS ← D2 │
│ ECHO → D10 │ │ E ← D3 │
│ VCC → 5V │ │ D4 ← D4 │
│ GND → GND │ │ D5 ← D5 │
└──────┬──────┘ │ D6 ← D6 │
│ │ D7 ← D7 │
↓ └─────────────┘
Water Surface
Arduino code
#include <LiquidCrystal.h>
const int trigPin = 9;
const int echoPin = 10;
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
// Change these values according to your tank
const float emptyDistance = 100.0;
const float fullDistance = 10.0;
long duration;
float distance;
int waterLevel;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lcd.begin(16, 2);
lcd.print("Water Level");
lcd.setCursor(0, 1);
lcd.print("Monitoring...");
delay(2000);
lcd.clear();
Serial.begin(9600);
}
void loop() {
distance = getDistance();
if (distance < 0) {
lcd.clear();
lcd.print("Sensor Error");
delay(1000);
return;
}
waterLevel = calculateLevel(distance);
Serial.print("Distance: ");
Serial.print(distance);
Serial.print(" cm | Level: ");
Serial.print(waterLevel);
Serial.println("%");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Water Level:");
lcd.setCursor(0, 1);
lcd.print(waterLevel);
lcd.print("%");
delay(1000);
}
float getDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH, 30000);
if (duration == 0) {
return -1;
}
return duration * 0.034 / 2;
}
int calculateLevel(float distance) {
float level =
((emptyDistance - distance) /
(emptyDistance - fullDistance)) * 100.0;
if (level < 0) {
level = 0;
}
if (level > 100) {
level = 100;
}
return (int)level;
}
Conclusion
An Arduino-based water-level indicator is a useful project for understanding how ultrasonic sensors can be used for contactless distance measurement.
The HC-SR04 measures the distance to the water surface, Arduino converts the measurement into an approximate water-level percentage, and the LCD displays the result.
The project can be further upgraded with LEDs, a buzzer, automatic pump control and ESP32-based IoT monitoring.