Smart Water Monitoring System Using ESP32: A Complete IoT Guide
Smart water monitoring system projects built on the ESP32 are among the most practical solutions to water scarcity in India’s urban and agricultural sectors. This ESP32 smart water monitoring system tracks tank levels in real time, prevents overflow, detects pipe leaks, and automates pump control — all viewable from your smartphone via ThingSpeak. It is also one of the strongest final-year B.Tech project ideas for ECE, EEE, and CS students.
What This Smart Water Monitoring System Does
- Tank Level Monitoring: Ultrasonic sensor (HC-SR04) continuously measures water level in a tank and displays the percentage on an OLED screen.
- Automatic Pump Control: A relay-switched pump turns on when the tank drops below 20% and turns off at 90% full — no manual intervention needed.
- Overflow Prevention: Float sensor triggers an emergency shutoff when maximum level is reached, preventing wastage.
- Remote Monitoring: The smart water monitoring system publishes tank level, pump state, and flow rate data to a ThingSpeak channel. View live graphs from any smartphone or PC.
- Leak Detection: Compares pump flow rate against tank level rise. If flow is detected but level is not rising, a leak alert is triggered on Telegram.
Components Required for the Smart Water Monitoring System
| Component | Purpose | Price |
|---|---|---|
| ESP32 DevKit (WROOM-32UE) | Main controller + Wi-Fi | ₹520 |
| HC-SR04 Ultrasonic Sensor | Tank level measurement | ~₹60 |
| YF-S201 Flow Sensor | Measures water volume through pipe | ~₹150 |
| Float Sensor (vertical type) | Emergency overflow shutoff | ~₹50 |
| 4-Channel Relay Module | Controls pump, valve, and alarm | ~₹100 |
| 0.96" OLED Display (I2C) | Shows live level and pump status | ~₹120 |
| MB102 Breadboard | Prototyping connections | ₹85 |
| 12V Submersible Mini Pump + PSU | Water pump | ~₹400 |
Estimated total project cost: ₹1,485 – ₹1,600
Wiring & Pin Connections (ESP32)
| Component | Pin | ESP32 GPIO | Note |
|---|---|---|---|
| HC-SR04 | TRIG | GPIO 5 | Digital output |
| HC-SR04 | ECHO | GPIO 18 | Use 10kΩ+20kΩ voltage divider (5V → 3.3V) |
| YF-S201 Flow Sensor | Signal | GPIO 19 | Interrupt-driven pulse count |
| Float Sensor | Output | GPIO 34 | INPUT-only pin; use external pull-up resistor |
| Relay Module | IN1 (Pump) | GPIO 26 | Active LOW |
| Relay Module | IN2 (Valve) | GPIO 27 | Active LOW |
| Relay Module | IN3 (Alarm) | GPIO 25 | Active LOW |
| OLED Display | SDA | GPIO 21 | I2C default SDA |
| OLED Display | SCL | GPIO 22 | I2C default SCL |
Arduino Sketch for the Smart Water Monitoring System
Flash this to your ESP32 using the Espressif ESP32 Arduino board package and Adafruit SSD1306 library installed.
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#define TRIG_PIN 5
#define ECHO_PIN 18
#define FLOW_PIN 19
#define FLOAT_PIN 34
#define RELAY_PUMP 26
#define RELAY_VALVE 27
#define RELAY_ALARM 25
#define TANK_HEIGHT_CM 100 // adjust to your tank depth in cm
volatile int flowPulses = 0;
void IRAM_ATTR flowISR() { flowPulses++; }
Adafruit_SSD1306 display(128, 64, &Wire, -1);
float getTankLevel() {
digitalWrite(TRIG_PIN, LOW); delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
long dur = pulseIn(ECHO_PIN, HIGH, 30000);
float dist = dur * 0.034 / 2.0;
return constrain(((TANK_HEIGHT_CM - dist) / TANK_HEIGHT_CM) * 100.0, 0, 100);
}
void setup() {
pinMode(TRIG_PIN, OUTPUT); pinMode(ECHO_PIN, INPUT);
pinMode(FLOW_PIN, INPUT_PULLUP); pinMode(FLOAT_PIN, INPUT);
pinMode(RELAY_PUMP, OUTPUT); pinMode(RELAY_VALVE, OUTPUT);
pinMode(RELAY_ALARM, OUTPUT);
digitalWrite(RELAY_PUMP, HIGH); // relays OFF by default (active LOW)
digitalWrite(RELAY_VALVE, HIGH);
digitalWrite(RELAY_ALARM, HIGH);
attachInterrupt(digitalPinToInterrupt(FLOW_PIN), flowISR, RISING);
Wire.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void loop() {
float level = getTankLevel();
bool overflow = !digitalRead(FLOAT_PIN); // LOW = overflow
if (overflow) {
digitalWrite(RELAY_PUMP, HIGH); // kill pump immediately
digitalWrite(RELAY_ALARM, LOW); // sound alarm
} else if (level < 20) {
digitalWrite(RELAY_PUMP, LOW); // start pump
} else if (level >= 90) {
digitalWrite(RELAY_PUMP, HIGH); // stop pump
digitalWrite(RELAY_ALARM, HIGH); // silence alarm
}
display.clearDisplay();
display.setTextSize(1); display.setTextColor(WHITE);
display.setCursor(0, 0); display.printf("Level : %.1f%%", level);
display.setCursor(0, 16); display.printf("Pump : %s", digitalRead(RELAY_PUMP) == LOW ? "ON" : "OFF");
display.setCursor(0, 32); display.printf("Flow : %d pulses", flowPulses);
display.display();
flowPulses = 0;
delay(5000);
}
How the ESP32 Smart Water Monitoring System Works
The ESP32 polls the HC-SR04 sensor every 5 seconds to measure the distance from the sensor to the water surface. This distance is converted to a percentage using the known tank dimensions. The relay module receives digital HIGH/LOW signals on GPIO pins to switch the pump and solenoid valve. The YF-S201 flow sensor generates pulses proportional to flow rate, counted by the ESP32’s pulse counter peripheral. All readings from this smart water monitoring system are published to ThingSpeak using HTTP GET requests over Wi-Fi every 30 seconds.
Why This Smart Water Monitoring System Is Perfect for Final Year Submission
- Real-world relevance: Water conservation is a national priority. Examiners immediately understand and appreciate the problem being solved.
- Multiple technologies: Sensor fusion, relay control, Wi-Fi, cloud IoT, mobile dashboard — covers multiple syllabus topics in one project.
- Live demo: Pouring water into a container and watching the app respond in real time is a visually compelling viva demonstration.
- Scalable: Mention adding soil moisture sensors for agricultural use, or solar panel charging for off-grid deployment, to show research depth.
Get the Components from KSP Electronics
- ESP32-WROOM-32UE DevKit — ₹520
- ESP32 D1 Mini Kit — ₹496
- 4-Channel Relay Module
- MB102 Breadboard — ₹85
Frequently Asked Questions
Can I use NodeMCU ESP8266 instead of ESP32 for this smart water monitoring system?
You can use the NodeMCU ESP8266 for a basic version of the smart water monitoring system with level monitoring and pump control. However, the ESP32 is strongly recommended because it has more GPIO pins (needed for relay + sensors + OLED simultaneously), a hardware pulse counter ideal for the YF-S201 flow sensor, and dual cores — allowing sensor reading and Wi-Fi uploads to run in parallel without delays.
How accurate is the HC-SR04 for water level measurement?
The HC-SR04 has a range of 2 cm – 400 cm with ±3 mm accuracy in still conditions. Mount it directly above the water surface facing straight down, away from tank walls and inlet pipes where turbulence causes false readings. Average 3–5 consecutive readings in code to smooth out noise significantly.
How do I receive Telegram leak alerts from the ESP32?
Install the UniversalTelegramBot Arduino library. Create a Telegram bot via BotFather, get the bot token and your chat ID, then call bot.sendMessage(CHAT_ID, "Leak detected!", "") when the leak condition (flow detected but level not rising) is true. Throttle the alert to fire once every 10 minutes to avoid notification spam.