Water Quality Monitoring System
Intermediate20/6/2026- Author: IoTSpark Maker

Water Quality Monitoring System

Build a water quality monitoring system that measures temperature, TDS, pH, and turbidity, shows an alert status, and can be extended to send real-time data over MQTT. Suited for monitoring fish tank, hydroponic, or water tank quality, or as a reference monitoring model. Note: readings from consumer-grade sensors do not replace certified testing equipment or lab analysis.

ESP32IoTWater QualityMQTTArduino IDETDSpHDS18B20
7 steps9 components
← Back to project
Detailed guide

Part 5: Sensor Calibration and Troubleshooting

Guides you through calibrating pH and turbidity, checking TDS, and fixing common issues when sensor data is unstable.

Updated 31/08/2026

Part 5: Sensor Calibration and Troubleshooting

Consumer-grade water sensors need calibration before use. Without calibration, the pH, TDS, or turbidity values can be way off from reality.

5.1. Calibrating pH

Use pH 7.0 and pH 4.0 reference solutions. Place the probe in each solution, wait for it to stabilize, then note the voltage on the Serial Monitor.

float PH7_VOLTAGE = 2.48;
float PH4_VOLTAGE = 3.02;

Linear formula:

pH = slope × voltage + intercept
slope = (7.0 - 4.0) / (voltage_pH7 - voltage_pH4)
intercept = 7.0 - slope × voltage_pH7

5.2. Calibrating Turbidity

Use one clear water sample and one reference turbid water sample. Record the sensor voltage for each case.

float CLEAR_WATER_VOLTAGE = 4.08;
float DIRTY_WATER_VOLTAGE = 2.55;

The system then converts this into a relative turbidity of 0% to 100%.

5.3. Checking TDS

TDS depends on temperature, so the firmware uses the DS18B20 for simple compensation back to a 25°C reference. For higher accuracy, use a TDS/EC reference solution and calibrate the coefficient to the actual sensor.

5.4. Common Issues Table

SymptomPossible CauseFix
DS18B20 reports -127°CWrong DATA wire, missing pull-up resistorCheck GPIO4 and the 4.7kΩ resistor.
ADC always reads 0The sensor isn't powered, or the AO pin is wrongCheck VCC, GND, and the signal wire.
ADC near 4095The analog voltage is too highUse a voltage divider before feeding it into the ESP32.
pH is way offNot calibrated, or the probe is dirtyRecalibrate and clean the probe.
Data jumps around wildlyNoise source, long wires, or an unstable ADCUse a good power supply, short wires, and averaging.
The ESP32 resetsWeak power supplyUse a stable 5V adapter.