Part 5: Sensor Calibration and Troubleshooting
Guides you through calibrating pH and turbidity, checking TDS, and fixing common issues when sensor data is unstable.
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
| Symptom | Possible Cause | Fix |
|---|---|---|
| DS18B20 reports -127°C | Wrong DATA wire, missing pull-up resistor | Check GPIO4 and the 4.7kΩ resistor. |
| ADC always reads 0 | The sensor isn't powered, or the AO pin is wrong | Check VCC, GND, and the signal wire. |
| ADC near 4095 | The analog voltage is too high | Use a voltage divider before feeding it into the ESP32. |
| pH is way off | Not calibrated, or the probe is dirty | Recalibrate and clean the probe. |
| Data jumps around wildly | Noise source, long wires, or an unstable ADC | Use a good power supply, short wires, and averaging. |
| The ESP32 resets | Weak power supply | Use a stable 5V adapter. |
