IoT Water Quality Monitoring System with pH, Turbidity, & Temperature Sensing

 Circuit Diagram:



🌊 IoT Water Quality Monitoring & Management System

Real-Time pH, Turbidity, and Multi-Point Temperature Automation

This advanced IoT-based system provides continuous monitoring of vital water quality parameters. By combining chemical analysis (pH tracking), physical clarity assessment (Turbidity evaluation), and environmental logging, it ensures precise safety detection and automated structural responses when pollution levels breach safety standards.

✨ Key System Features

  • Dual Temperature Safeguards: Tracks ambient environmental conditions alongside fluid-specific internal temperatures.
  • Automated Waste-Gate Control: Instantly deploys mechanical valves to isolate unsafe fluids.
  • State-Change Indicator Triggers: Employs edge-triggered status metrics to manage visual and remote alarms without feedback loops.

🛠️ Deep-Dive Component Architecture

1. Core Processing Units (NodeMCU V3 / ESP32)

Acts as the central control hardware layer. It samples raw incoming analog voltages and synchronous digital frames, processes data mapping calculations, and manages cloud/IoT streaming configurations.

2. Analog pH Meter Circuitry

Utilizes a highly sensitive glass electrode design that tracks changing hydrogen-ion activity. An onboard amplifier driver translates minute structural millivolt variances into predictable linear scaling profiles.

3. Optical Turbidity Sensor Module

Employs a custom infrared (IR) optocoupler housing layout. By monitoring changes in raw light refraction and dispersion across light paths, the module records relative concentration levels of suspended sediment particles.

4. Submersible DS18B20 & DHT Sensors

The DS18B20 uses a waterproof stainless-steel protective probe assembly transmitting via a single-wire communication protocol, paired alongside standard ambient humidity/temperature capacitive grid sensor structures.

📟 Unified System Pinout & Signal Mapping

Peripheral Module Hardware Pin MCU GPIO Target Signal / Logic Classification
pH Sensor Board AOUT / Signal GPIO 34 / A0 Analog Input (ADC)
Turbidity Sensor AOUT / Signal GPIO 35 Analog Input (ADC)
DS18B20 Probe DQ (Yellow/White) GPIO 5 Digital 1-Wire (Pull-up req.)
DHT11 / DHT22 Data Out GPIO 4 / Pin 2 Digital Synchronous I/O
SG90 Micro Servo PWM / Signal GPIO 18 / Pin 3 Pulse Width Modulation (PWM)
Status Alarm LED Anode (+) GPIO 2 Digital Logic Output

🚀 Threshold Control Thresholds

The system automatically operates isolation matrices using the following conditional parameters:

  • Critical Safety pH Range: Allowed within normal bounds of 6.5 to 8.5.
  • Max Allowable Turbidity Ceiling: Restricted to 20% clarity drop.
  • Active Response Phase: When limits trip, the servo steps immediately to 90° to flush lines.
💾

Fritzing Schematic Download

Download the official Water_Quality_Monitor.fzz project file. You can open, modify, or view the exact breadboard connections and PCB routing using the Fritzing desktop application.

📟 ARDUINO ESP32 SOURCE CODE
#include "DHT.h"
#include <ESP32Servo.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// --- Pin Definitions ---
#define PH_PIN        34    
#define TURB_PIN      35    
#define DHT_PIN       4     
#define LED_PIN       2     
#define SERVO_PIN     18    
#define DS18B20_PIN   5     // Pin for DS18B20 Waterproof Sensor

// --- Settings ---
#define DHTTYPE       DHT22 
#define ADC_MAX       4095  // Fixed line spacing error
#define V_REF         3.3   

DHT dht(DHT_PIN, DHTTYPE);
Servo myServo;

// Setup for DS18B20 OneWire Network
OneWire oneWire(DS18B20_PIN);
DallasTemperature waterTempSensor(&oneWire);

void setup() {
  Serial.begin(115200);
  
  dht.begin();
  waterTempSensor.begin(); // Start the DS18B20 Sensor
  
  ESP32PWM::allocateTimer(0);
  ESP32PWM::allocateTimer(1);
  myServo.setPeriodHertz(50);
  myServo.attach(SERVO_PIN, 500, 2400);
  
  pinMode(LED_PIN, OUTPUT);
  Serial.println("System Initialized with Water Temp Sensor...");
  myServo.write(0);
}

void loop() {
  // 1. Read Ambient Environment (DHT22)
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // 2. Read Liquid Temperature (DS18B20)
  waterTempSensor.requestTemperatures(); 
  float waterT = waterTempSensor.getTempCByIndex(0);

  // 3. Read Sensors with 12-bit Analog Mapping
  int phRaw = analogRead(PH_PIN);
  float phValue = (phRaw / (float)ADC_MAX) * 14.0;

  int turbRaw = analogRead(TURB_PIN);
  float turbVoltage = (turbRaw / (float)ADC_MAX) * V_REF;

  // --- Output Data to Serial Monitor ---
  Serial.print("Air Temp: "); Serial.print(t);
  Serial.print("C | Water Temp: "); Serial.print(waterT);
  Serial.print("C | pH: "); Serial.print(phValue);
  Serial.print(" | Turbidity V: "); Serial.println(turbVoltage);

  // --- Automation & Threshold Logic Control ---
  if (phValue < 6.5 || phValue > 8.5 || turbVoltage < 2.0 || waterT > 30.0) { 
    digitalWrite(LED_PIN, HIGH);  // Trigger Alarm LED
    myServo.write(90);            // Open Waste Isolation Gate Valve
    Serial.println("!! WATER ALERT !!");
  } else {
    digitalWrite(LED_PIN, LOW);
    myServo.write(0);             // Return Valve to Safe Status
  }

  delay(2000); // Safe stabilization delay
}

Comments