💧 Water Quality Monitoring System
(ESP32 + Analog TDS Sensor – Serial Monitor Version)
In this lesson, we will:
-
Read TDS sensor analog value
-
Convert voltage into TDS (PPM)
-
Display water quality on Serial Monitor
-
Classify water quality (Excellent / Good / Poor)
No WiFi ❌
No Bluetooth ❌
Only Serial Monitor ✔
📦 Components Used
-
ESP32
-
Analog TDS Sensor Module
-
TDS Probe
-
Water sample
-
USB cable
🔌 Pin Configuration
| TDS Module Pin | ESP32 |
|---|---|
| VCC | 3.3V |
| GND | GND |
| AO | GPIO 34 |
GPIO 34 is Analog Input pin.
💻 COMPLETE CODE
(Serial Monitor Version – TDS Sensor)
Copy & paste into Arduino IDE:
#define TDS_PIN 34
float voltage = 0;
float tdsValue = 0;
void setup() {
Serial.begin(115200);
Serial.println("=== Water Quality Monitoring System ===");
}
void loop() {
int adcValue = analogRead(TDS_PIN);
// Convert ADC value to voltage
voltage = adcValue * (3.3 / 4095.0);
// Convert voltage to TDS (ppm)
tdsValue = (133.42 * voltage * voltage * voltage
- 255.86 * voltage * voltage
+ 857.39 * voltage) * 0.5;
Serial.print("ADC Value: ");
Serial.print(adcValue);
Serial.print(" | Voltage: ");
Serial.print(voltage);
Serial.print(" V");
Serial.print(" | TDS Value: ");
Serial.print(tdsValue);
Serial.print(" ppm");
// Water Quality Classification
if (tdsValue < 50) {
Serial.println(" | Very Pure Water");
}
else if (tdsValue < 150) {
Serial.println(" | Excellent Water");
}
else if (tdsValue < 300) {
Serial.println(" | Good Water");
}
else if (tdsValue < 500) {
Serial.println(" | Fair Water");
}
else {
Serial.println(" | Poor / Unsafe Water");
}
delay(2000);
}
🧠 Code Explanation (Step-by-Step)
1️⃣ Read Analog Value
ESP32 reads analog value from GPIO 34.
Range:
-
0 – 4095 (12-bit ADC)
2️⃣ Convert ADC to Voltage
Converts ADC reading into voltage.
Example:
If ADC = 2048
Voltage ≈ 1.65V
3️⃣ Convert Voltage to TDS
This formula converts voltage into TDS (ppm).
The polynomial equation is based on calibration of TDS module.
4️⃣ Water Quality Classification
Based on TDS value:
| TDS (ppm) | Water Quality |
|---|---|
| < 50 | Very Pure |
| 50 – 150 | Excellent |
| 150 – 300 | Good |
| 300 – 500 | Fair |
| > 500 | Poor / Unsafe |
The program prints quality automatically.
📟 Example Serial Output
ADC Value: 1350 | Voltage: 1.08 V | TDS Value: 120 ppm | Excellent Water
ADC Value: 2100 | Voltage: 1.69 V | TDS Value: 340 ppm | Fair Water
🔧 Optional Improvement (More Accurate Reading)
To reduce noise, you can:
-
Take multiple readings
-
Calculate average value
-
Add temperature compensation
🎯 What Students Learn
-
Analog sensor reading
-
ESP32 ADC working
-
Voltage calculation
-
Polynomial conversion formula
-
Water quality classification
-
Environmental monitoring basics
📌 Lesson Summary
In this lesson, students built a complete:
💧 Serial Monitor-Based Water Quality Monitoring System
The system:
✔ Reads TDS sensor
✔ Converts voltage into PPM
✔ Classifies water quality
✔ Displays results in real time
This is the foundation for:
-
Bluetooth version
-
WiFi version
-
Blynk IoT version