Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Based Smart Water Quality Monitoring System with LCD Display and Relay Control

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Water Quality Monitoring System with LCD Display and Relay Control

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

  1. 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
  2. TDS-sensor, voor waterkwaliteit

    • Description: Measures the Total Dissolved Solids (TDS) in water.
    • Pins: gnd, v, analog pin
  3. Turbidity

    • Description: Measures the turbidity (cloudiness) of water.
    • Pins: OUT, VCC, GND
  4. PH Meter

    • Description: Measures the pH level of water.
    • Pins: Signal, VCC, GND
  5. YF-S201 Water Flow Meter

    • Description: Measures the flow rate of water.
    • Pins: SIG, GND, VCC
  6. DS18B20 1-Wire Temperature Sensor Probe Cable

    • Description: Measures the temperature of water.
    • Pins: shield, GND, DQ, VDD
  7. Plastic Solenoid Valve

    • Description: Controls the flow of water.
    • Pins: pin1, pin2
  8. Mini Diaphragm Water Pump

    • Description: Pumps water through the system.
    • Pins: Positive (+), Negative (-)
  9. 1 Channel Relay 5V

    • Description: Controls high voltage devices like the solenoid valve and water pump.
    • Pins: VCC, GND, IN, NC, COM, NO
  10. Battery 12V

    • Description: Provides power to the water pump.
    • Pins: +, -
  11. 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

DS18B20 1-Wire Temperature Sensor Probe Cable

TDS-sensor, voor waterkwaliteit

Turbidity

PH Meter

YF-S201 Water Flow Meter

Plastic Solenoid Valve

Mini Diaphragm Water Pump

1 Channel Relay 5V

Battery 12V

LCD 16x2 (Wokwi Compatible)

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);