ESP32-Based Smart Water Quality Monitoring System with LCD Display and Relay Control
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to monitor various water quality parameters using an ESP32 microcontroller. It reads data from multiple sensors including TDS, Turbidity, PH, Flow Meter, and Temperature sensors. The sensor readings are displayed on a 16x2 LCD display. Additionally, the circuit controls a solenoid valve and a water pump via a relay based on the sensor values.
Component List
ESP32 38 PINS
- Description: A powerful microcontroller with built-in Wi-Fi and Bluetooth capabilities.
- Pins: GND, 23, 22/SCL, 1, 2, 21/SDA, 19, 18, 5, 17/TX2, 16/RX2, 4, 0, 15, D1, D0, CLK, 3V3, EN, VP, VN, 34, 35, 32, 33, 25, 26, 27, 14, 12, 13, D2, D3, 11, 5V/VIN
TDS-sensor, voor waterkwaliteit
- Description: Measures the Total Dissolved Solids (TDS) in water.
- Pins: gnd, v, analog pin
Turbidity
- Description: Measures the turbidity (cloudiness) of water.
- Pins: OUT, VCC, GND
PH Meter
- Description: Measures the pH level of water.
- Pins: Signal, VCC, GND
YF-S201 Water Flow Meter
- Description: Measures the flow rate of water.
- Pins: SIG, GND, VCC
DS18B20 1-Wire Temperature Sensor Probe Cable
- Description: Measures the temperature of water.
- Pins: shield, GND, DQ, VDD
Plastic Solenoid Valve
- Description: Controls the flow of water.
- Pins: pin1, pin2
Mini Diaphragm Water Pump
- Description: Pumps water through the system.
- Pins: Positive (+), Negative (-)
1 Channel Relay 5V
- Description: Controls high voltage devices like the solenoid valve and water pump.
- Pins: VCC, GND, IN, NC, COM, NO
Battery 12V
- Description: Provides power to the water pump.
- Pins: +, -
LCD 16x2 (Wokwi Compatible)
- Description: Displays sensor readings.
- Pins: VSS, VDD, V0, RS, RW, E, D0, D1, D2, D3, D4, D5, D6, D7, A, K
Wiring Details
ESP32 38 PINS
- Pin 4: Connected to DS18B20 Temperature Sensor (DQ)
- Pin 3V3: Connected to VCC of YF-S201 Water Flow Meter, TDS-sensor, Turbidity, PH Meter, DS18B20 Temperature Sensor, and LCD (VDD, A)
- Pin GND: Connected to GND of TDS-sensor, Turbidity, PH Meter, DS18B20 Temperature Sensor, YF-S201 Water Flow Meter, LCD (RW, VSS, K), and 1 Channel Relay
- Pin 23: Connected to LCD (E)
- Pin 22/SCL: Connected to LCD (RS)
- Pin 19: Connected to LCD (D4)
- Pin 18: Connected to LCD (D5)
- Pin 5: Connected to LCD (D6)
- Pin 17/TX2: Connected to LCD (D7)
- Pin 34: Connected to PH Meter (Signal)
- Pin 35: Connected to Turbidity (OUT)
- Pin 32: Connected to TDS-sensor (analog pin)
- Pin 33: Connected to YF-S201 Water Flow Meter (SIG)
- Pin 13: Connected to 1 Channel Relay (IN)
- Pin 5V/VIN: Connected to 1 Channel Relay (VCC)
DS18B20 1-Wire Temperature Sensor Probe Cable
- DQ: Connected to ESP32 (Pin 4)
- VDD: Connected to ESP32 (Pin 3V3)
- GND: Connected to ESP32 (Pin GND)
TDS-sensor, voor waterkwaliteit
- analog pin: Connected to ESP32 (Pin 32)
- v: Connected to ESP32 (Pin 3V3)
- gnd: Connected to ESP32 (Pin GND)
Turbidity
- OUT: Connected to ESP32 (Pin 35)
- VCC: Connected to ESP32 (Pin 3V3)
- GND: Connected to ESP32 (Pin GND)
PH Meter
- Signal: Connected to ESP32 (Pin 34)
- VCC: Connected to ESP32 (Pin 3V3)
- GND: Connected to ESP32 (Pin GND)
YF-S201 Water Flow Meter
- SIG: Connected to ESP32 (Pin 33)
- VCC: Connected to ESP32 (Pin 3V3)
- GND: Connected to ESP32 (Pin GND)
Plastic Solenoid Valve
- pin1: Connected to 1 Channel Relay (IN)
- pin2: Connected to 1 Channel Relay (GND)
Mini Diaphragm Water Pump
- Positive (+): Connected to 1 Channel Relay (NO)
- Negative (-): Connected to Battery 12V (-)
1 Channel Relay 5V
- VCC: Connected to ESP32 (Pin 5V/VIN)
- GND: Connected to ESP32 (Pin GND)
- IN: Connected to ESP32 (Pin 13)
- NO: Connected to Mini Diaphragm Water Pump (Positive +)
- COM: Connected to Battery 12V (+)
Battery 12V
- +: Connected to 1 Channel Relay (COM)
- -: Connected to Mini Diaphragm Water Pump (Negative -)
LCD 16x2 (Wokwi Compatible)
- VSS: Connected to ESP32 (Pin GND)
- VDD: Connected to ESP32 (Pin 3V3)
- RS: Connected to ESP32 (Pin 22/SCL)
- RW: Connected to ESP32 (Pin GND)
- E: Connected to ESP32 (Pin 23)
- D4: Connected to ESP32 (Pin 19)
- D5: Connected to ESP32 (Pin 18)
- D6: Connected to ESP32 (Pin 5)
- D7: Connected to ESP32 (Pin 17/TX2)
- A: Connected to ESP32 (Pin 3V3)
- K: Connected to ESP32 (Pin GND)
Code Documentation
ESP32 Code
/*
* This Arduino Sketch reads data from various water quality sensors
* (TDS, Turbidity, PH, Flow Meter, and Temperature) connected to an ESP32.
* The sensor readings are displayed on a 16x2 LCD display.
* Additionally, it controls a solenoid valve and a water pump via a relay.
*/
#include <Wire.h>
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// LCD pins
const int rs = 22, en = 23, d4 = 19, d5 = 18, d6 = 5, d7 = 17;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// DS18B20 Temperature Sensor
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// Sensor pins
const int tdsPin = 32;
const int turbidityPin = 35;
const int phPin = 34;
const int flowMeterPin = 33;
// Relay and solenoid valve pins
const int relayPin = 13;
void setup() {
lcd.begin(16, 2);
sensors.begin();
pinMode(tdsPin, INPUT);
pinMode(turbidityPin, INPUT);
pinMode(phPin, INPUT);
pinMode(flowMeterPin, INPUT);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // Ensure relay is off initially
}
void loop() {
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
int tdsValue = analogRead(tdsPin);
int turbidityValue = analogRead(turbidityPin);
int phValue = analogRead(phPin);
int flowMeterValue = digitalRead(flowMeterPin);
lcd.clear();
lcd.setCursor(0, 0);