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

💧 Water Quality Monitoring System

(ESP32 + Analog TDS Sensor + Home WiFi Mode)

In this lesson, ESP32 connects to your home WiFi router.

Your mobile and ESP32 must be connected to the same WiFi network.

This version allows:

  • 📊 Real-time TDS monitoring

  • 💧 Water quality classification

  • 📱 Wireless monitoring using local network

  • 🌐 Router-based communication

Router required ✔
Internet not compulsory (local network works) ✔


📦 Components Used

  • ESP32

  • Analog TDS Sensor Module

  • TDS Probe

  • Home WiFi Router

  • Android Phone

  • TCP Terminal App

Recommended Apps:

  • TCP Telnet Terminal

  • Serial WiFi Terminal


🔌 Pin Configuration

TDS Module Pin ESP32
VCC 3.3V
GND GND
AO GPIO 34

GPIO 34 = Analog Input


💻 COMPLETE CODE

(Home WiFi Mode + TCP Server + TDS Monitoring)

Replace WiFi credentials before uploading.

#include <WiFi.h>

#define TDS_PIN 34

const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";

WiFiServer server(23);

float voltage = 0;
float tdsValue = 0;

void setup() {
Serial.begin(115200);

Serial.println("Connecting to WiFi...");
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("\nWiFi Connected!");
Serial.print("ESP32 IP Address: ");
Serial.println(WiFi.localIP());

server.begin();
Serial.println("TCP Server Started on Port 23");
}

void loop() {

WiFiClient client = server.available();

if (client) {
Serial.println("Client Connected");

client.println("=== Water Quality Monitoring ===");

while (client.connected()) {

int adcValue = analogRead(TDS_PIN);

voltage = adcValue * (3.3 / 4095.0);

tdsValue = (133.42 * voltage * voltage * voltage
- 255.86 * voltage * voltage
+ 857.39 * voltage) * 0.5;

client.print("TDS Value: ");
client.print(tdsValue);
client.print(" ppm");

if (tdsValue < 50) {
client.println(" | Very Pure Water");
}
else if (tdsValue < 150) {
client.println(" | Excellent Water");
}
else if (tdsValue < 300) {
client.println(" | Good Water");
}
else if (tdsValue < 500) {
client.println(" | Fair Water");
}
else {
client.println(" | Poor / Unsafe Water");
}

delay(2000);
}

client.stop();
Serial.println("Client Disconnected");
}
}

🧠 Code Explanation


1️⃣ Connect to Home WiFi

 
WiFi.begin(ssid, password);
 

ESP32 connects to your router.

 
WiFi.localIP();
 

Prints ESP32 IP address.

Example:

 
192.168.1.45
 

You must use this IP in mobile app.


2️⃣ Create TCP Server

 
WiFiServer server(23);
 

Creates Telnet server on Port 23.

Mobile connects using:

  • Host: ESP32 IP

  • Port: 23


3️⃣ Read Analog Value

 
int adcValue = analogRead(TDS_PIN);
 

Reads analog signal from TDS sensor.

Range:
0 – 4095


4️⃣ Convert ADC to Voltage

 
voltage = adcValue * (3.3 / 4095.0);
 

Converts ADC reading to voltage.


5️⃣ Convert Voltage to TDS

 
tdsValue = (133.42 * V³ – 255.86 * V² + 857.39 * V) * 0.5;
 

Converts voltage to PPM value.


6️⃣ Water Quality Classification

TDS (ppm) Quality
< 50 Very Pure
50–150 Excellent
150–300 Good
300–500 Fair
> 500 Poor

📱 How To Use

Step 1
Upload code

Step 2
Open Serial Monitor
Note ESP32 IP address

Step 3
Connect mobile to same WiFi

Step 4
Open TCP Terminal App

Enter:

  • Host: ESP32 IP

  • Port: 23

Step 5
View live TDS values


📟 Example Output

 
TDS Value: 120 ppm | Excellent Water
TDS Value: 280 ppm | Good Water
TDS Value: 610 ppm | Poor / Unsafe Water
 

🎯 What Students Learn

  • Home WiFi networking

  • TCP client-server communication

  • Analog sensor reading

  • Voltage to PPM conversion

  • Wireless environmental monitoring


📌 Lesson Summary

In this lesson, students built a:

💧 Home WiFi-Based Water Quality Monitoring System

The system:

✔ Measures TDS
✔ Classifies water quality
✔ Sends data wirelessly
✔ Works inside local network

Scroll to Top