ESP32-Based Water Quality Monitoring System with DS18B20 and Turbidity Sensor
View and Edit Project In Cirkit Designer
Water Quality Monitoring System Documentation
Summary
This document provides a detailed overview of a water quality monitoring system that uses an ESP32 microcontroller to monitor TDS, pH, temperature, and turbidity of water. The system displays the data on a 16x2 I2C LCD. The components used in this circuit include various sensors and a start switch, all interconnected to the ESP32 microcontroller.
Component List
DS18B20 Temperature Sensor
- Description: Measures temperature.
- Pins: GND, VCC, OUT
START SWITCH
- Description: Used to start the monitoring process.
- Pins: NO 1, NC 1, NO 2, NC 2
Turbidity Module
- Description: Measures the turbidity of water.
- Pins: VCC, GND, OUT
ESP32-WROOM-32UE
- Description: Microcontroller used to process sensor data and display it on the LCD.
- Pins: 3v3, EN, VP, VN, 34, 35, 32, 33, 25, 26, 27, 14, 12, GND, 13, D2, D3, 5V, 23, 22, TX, RX, 21, 19, 18, 5, 17, 16, 4, 0, 2, 15, D1, D0, CKL
TDS Sensor
- Description: Measures the Total Dissolved Solids (TDS) in water.
- Pins: P1, P2, +, -, A
RTD PT100
- Description: Measures temperature.
- Pins: 1, 2
DS18B20 1-Wire Temperature Sensor Probe Cable
- Description: Measures temperature.
- Pins: shield, GND, DQ, VDD
PH Meter
- Description: Measures the pH level of water.
- Pins: Signal, VCC, GND
Turbidity
- Description: Measures the turbidity of water.
- Pins: OUT, VCC, GND
Wiring Details
DS18B20 Temperature Sensor
- VCC connected to ESP32-WROOM-32UE 5V
- GND connected to ESP32-WROOM-32UE GND
- OUT connected to ESP32-WROOM-32UE 26
START SWITCH
- NO 1 connected to ESP32-WROOM-32UE 13
- NC 2 connected to TDS Sensor -
- NC 2 connected to Turbidity Module GND
- NC 2 connected to DS18B20 Temperature Sensor GND
- NC 2 connected to ESP32-WROOM-32UE GND
Turbidity Module
- VCC connected to ESP32-WROOM-32UE 5V
- GND connected to START SWITCH NC 2
- OUT connected to ESP32-WROOM-32UE 34
ESP32-WROOM-32UE
- 5V connected to DS18B20 Temperature Sensor VCC
- 5V connected to TDS Sensor +
- 5V connected to Turbidity Module VCC
- GND connected to START SWITCH NC 2
- GND connected to Turbidity Module GND
- GND connected to DS18B20 Temperature Sensor GND
- 34 connected to Turbidity Module OUT
- 35 connected to TDS Sensor A
- 26 connected to DS18B20 Temperature Sensor OUT
- 13 connected to START SWITCH NO 1
TDS Sensor
- + connected to ESP32-WROOM-32UE 5V
- - connected to START SWITCH NC 2
- A connected to ESP32-WROOM-32UE 35
RTD PT100
- 1 not connected
- 2 not connected
DS18B20 1-Wire Temperature Sensor Probe Cable
- shield not connected
- GND not connected
- DQ not connected
- VDD not connected
PH Meter
- Signal not connected
- VCC not connected
- GND not connected
Turbidity
- OUT not connected
- VCC not connected
- GND not connected
Code Documentation
/*
* Water Quality Monitoring System
* This Arduino sketch monitors TDS, pH, temperature, and turbidity of water
* using an ESP32 microcontroller. The data is displayed on a 16x2 I2C LCD.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Pin definitions
#define TDS_PIN 35
#define PH_PIN 12
#define TURBIDITY_PIN 34
#define TEMP_PIN 26
#define SWITCH_PIN 13
#define ONE_WIRE_BUS TEMP_PIN
// LCD address and dimensions
LiquidCrystal_I2C lcd(0x27, 16, 2);
// OneWire and DallasTemperature instances
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Initialize LCD
lcd.init();
lcd.backlight();
// Initialize sensors
sensors.begin();
// Initialize pins
pinMode(TDS_PIN, INPUT);
pinMode(PH_PIN, INPUT);
pinMode(TURBIDITY_PIN, INPUT);
pinMode(SWITCH_PIN, INPUT);
// Display startup message
lcd.setCursor(0, 0);
lcd.print("Water Quality");
lcd.setCursor(0, 1);
lcd.print("Monitoring");
delay(2000);
lcd.clear();
}
void loop() {
// Read temperature
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
// Read TDS, pH, and turbidity values
int tdsValue = analogRead(TDS_PIN);
int phValue = analogRead(PH_PIN);
int turbidityValue = analogRead(TURBIDITY_PIN);
// Display values on LCD
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("TDS: ");
lcd.print(tdsValue);
lcd.print(" PH: ");
lcd.print(phValue);
lcd.print(" Turb: ");
lcd.print(turbidityValue);
// Print values to serial monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");
Serial.print("TDS: ");
Serial.println(tdsValue);
Serial.print("pH: ");
Serial.println(phValue);
Serial.print("Turbidity: ");
Serial.println(turbidityValue);
// Wait before next reading
delay(2000);
}
This code initializes the ESP32 microcontroller, sets up the sensors and LCD, and continuously reads and displays the water quality parameters. The data is also printed to the serial monitor for debugging and logging purposes.