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

ESP32-Based Water Quality Monitoring System with DS18B20 and Turbidity Sensor

View and Edit Project In Cirkit DesignerImage of ESP32-Based Water Quality Monitoring System with DS18B20 and Turbidity Sensor

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

  1. DS18B20 Temperature Sensor

    • Description: Measures temperature.
    • Pins: GND, VCC, OUT
  2. START SWITCH

    • Description: Used to start the monitoring process.
    • Pins: NO 1, NC 1, NO 2, NC 2
  3. Turbidity Module

    • Description: Measures the turbidity of water.
    • Pins: VCC, GND, OUT
  4. 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
  5. TDS Sensor

    • Description: Measures the Total Dissolved Solids (TDS) in water.
    • Pins: P1, P2, +, -, A
  6. RTD PT100

    • Description: Measures temperature.
    • Pins: 1, 2
  7. DS18B20 1-Wire Temperature Sensor Probe Cable

    • Description: Measures temperature.
    • Pins: shield, GND, DQ, VDD
  8. PH Meter

    • Description: Measures the pH level of water.
    • Pins: Signal, VCC, GND
  9. Turbidity

    • Description: Measures the turbidity of water.
    • Pins: OUT, VCC, GND

Wiring Details

DS18B20 Temperature Sensor

START SWITCH

Turbidity Module

ESP32-WROOM-32UE

TDS Sensor

RTD PT100

DS18B20 1-Wire Temperature Sensor Probe Cable

PH Meter

Turbidity

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.