Course Content
IoT Engineering Course using ESP32 with 12 Real-World Projects

💧 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

  1. Click New Template

  2. Template Name:

     
     
    Smart Water System
     
  3. Hardware: ESP32

  4. Connection Type: WiFi

  5. 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

  1. Go to Devices

  2. Click New Device

  3. From Template

  4. Select Smart Water System

  5. 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

 
 
analogRead(WATER_SENSOR);
 

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

  1. ESP32 connects to WiFi

  2. Connects to Blynk Cloud

  3. Reads water level

  4. Checks mode

  5. Controls motor

  6. Updates dashboard


🎯 What Students Learn

  • IoT cloud architecture

  • Virtual pins concept

  • Remote automation

  • Real-time data monitoring

  • Auto + Manual embedded system design



Scroll to Top