💧 Smart Water Management System
(ESP32 + Water Level Sensor + Relay + Blynk IoT)
This version supports:
-
✅ AUTO Mode
-
✅ MANUAL Mode
-
✅ Motor ON/OFF from Blynk dashboard
-
✅ Real-time water level monitoring
-
✅ Tank FULL warning
-
✅ Cloud control from anywhere
Internet required ✔
Blynk IoT Cloud required ✔
📦 Components Required
-
ESP32
-
Water Level Sensor (Analog)
-
Single Channel Relay
-
DC Water Pump
-
WiFi Connection
-
Blynk IoT Account
🔌 Connections
🔹 Water Level Sensor
| Sensor Pin | ESP32 |
|---|---|
| VCC | 3.3V |
| GND | GND |
| AO | GPIO 34 |
🔹 Relay Module
| Relay Pin | ESP32 |
|---|---|
| VCC | 5V |
| GND | GND |
| IN | GPIO 26 |
⚠ Relay Active LOW
LOW → Motor ON
HIGH → Motor OFF
🌐 Blynk IoT Setup (Step-by-Step)
Go to:
👉 https://blynk.cloud
Login and follow below steps.
🔹 Step 1 – Create Template
-
Click New Template
-
Template Name:
Smart Water System -
Hardware: ESP32
-
Connection Type: WiFi
-
Click Done
🔹 Step 2 – Create Datastreams
Go to Datastreams → New Datastream
1️⃣ V0 – Auto/Manual Mode Switch
-
Type: Virtual Pin
-
Pin: V0
-
Data Type: Integer
-
Min: 0
-
Max: 1
-
Default: 1
👉 1 = AUTO
👉 0 = MANUAL
2️⃣ V1 – Motor Control Button
-
Type: Virtual Pin
-
Pin: V1
-
Data Type: Integer
-
Min: 0
-
Max: 1
👉 1 = Motor ON
👉 0 = Motor OFF
3️⃣ V2 – Water Level Value
-
Type: Virtual Pin
-
Pin: V2
-
Data Type: Integer
Used to display sensor reading.
4️⃣ V3 – Tank Full LED
-
Type: Virtual Pin
-
Pin: V3
-
Data Type: Integer
👉 1 = Tank Full
👉 0 = Normal
🔹 Step 3 – Create Device
-
Go to Devices
-
Click New Device
-
From Template
-
Select Smart Water System
-
Copy Auth Token
You will paste it in code.
📱 Dashboard Setup (Mobile App)
Open Blynk App.
Add Widgets:
🔘 Switch (Auto/Manual)
-
Datastream: V0
-
Mode: Switch
🔘 Button (Motor Control)
-
Datastream: V1
-
Mode: Switch
📊 Value Display (Water Level)
-
Datastream: V2
💡 LED Widget (Tank Full)
-
Datastream: V3
-
ON Color: Red
-
OFF Color: Green
💻 COMPLETE FINAL CODE (Blynk IoT Version)
Install Libraries:
-
Blynk
Replace credentials before uploading.
#define BLYNK_TEMPLATE_ID "YOUR_TEMPLATE_ID"
#define BLYNK_DEVICE_NAME "Smart Water System"
#define BLYNK_AUTH_TOKEN "YOUR_AUTH_TOKEN"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#define WATER_SENSOR 34
#define RELAY_PIN 26
char ssid[] = "YOUR_WIFI_NAME";
char pass[] = "YOUR_WIFI_PASSWORD";
bool autoMode = true;
bool motorState = false;
int lowLevel = 1000;
int fullLevel = 3000;
BLYNK_WRITE(V0) {
autoMode = param.asInt();
}
BLYNK_WRITE(V1) {
if (!autoMode) {
int value = param.asInt();
if (value == 1) {
turnMotorOn();
} else {
turnMotorOff();
}
}
}
void setup() {
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop() {
Blynk.run();
int waterValue = analogRead(WATER_SENSOR);
Blynk.virtualWrite(V2, waterValue);
if (autoMode) {
if (waterValue < lowLevel && !motorState) {
turnMotorOn();
}
if (waterValue > fullLevel && motorState) {
turnMotorOff();
Blynk.virtualWrite(V3, 1);
} else {
Blynk.virtualWrite(V3, 0);
}
}
}
void turnMotorOn() {
digitalWrite(RELAY_PIN, LOW);
motorState = true;
Blynk.virtualWrite(V1, 1);
}
void turnMotorOff() {
digitalWrite(RELAY_PIN, HIGH);
motorState = false;
Blynk.virtualWrite(V1, 0);
}
🧠 Code Explanation
1️⃣ BLYNK_WRITE(V0)
Controls Auto/Manual mode from dashboard.
2️⃣ BLYNK_WRITE(V1)
Controls motor manually when Auto mode is OFF.
3️⃣ Water Level Reading
Sends value to V2 for display.
4️⃣ Auto Mode Logic
If water LOW → Motor ON
If tank FULL → Motor OFF + LED ON
5️⃣ Blynk.virtualWrite()
Updates dashboard widgets in real time.
📟 System Working Flow
-
ESP32 connects to WiFi
-
Connects to Blynk Cloud
-
Reads water level
-
Checks mode
-
Controls motor
-
Updates dashboard
🎯 What Students Learn
-
IoT cloud architecture
-
Virtual pins concept
-
Remote automation
-
Real-time data monitoring
-
Auto + Manual embedded system design