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

ESP32-Based Water Quality Monitoring System with Ultrasonic Level Sensing

View and Edit Project In Cirkit DesignerImage of ESP32-Based Water Quality Monitoring System with Ultrasonic Level Sensing

Circuit Documentation

Summary

This circuit is designed to interface an ESP32 Devkit V1 microcontroller with an HC-SR04 Ultrasonic Sensor, a TDS Sensor Module, and a pH Degree Sensor Module for the purpose of measuring water level, total dissolved solids (TDS), and pH level. The circuit is powered by a 5V battery. The ESP32 reads the sensors' outputs and processes the data, which is then available for monitoring or further processing.

Component List

ESP32 Devkit V1

HC-SR04 Ultrasonic Sensor

TDS Sensor Module

pH Degree Sensor Module

5V Battery

Wiring Details

ESP32 Devkit V1

HC-SR04 Ultrasonic Sensor

TDS Sensor Module

pH Degree Sensor Module

5V Battery

Documented Code

// Include necessary libraries
#include <Arduino.h>

// Define pins
#define TRIG_PIN 23 // Trigger pin for HC-SR04
#define ECHO_PIN 22 // Echo pin for HC-SR04
#define TDS_PIN 34  // Analog pin for TDS sensor
#define PH_PIN 35   // Analog pin for pH sensor

void setup() {
    Serial.begin(115200); // Start serial communication
    pinMode(TRIG_PIN, OUTPUT); // Set trigger pin as output
    pinMode(ECHO_PIN, INPUT);  // Set echo pin as input
}

void loop() {
    // Read water level using ultrasonic sensor
    long duration, distance;
    
    // Clear the trigger
    digitalWrite(TRIG_PIN, LOW);
    delayMicroseconds(2);
    
    // Set trigger high for 10 microseconds
    digitalWrite(TRIG_PIN, HIGH);
    delayMicroseconds(10);
    digitalWrite(TRIG_PIN, LOW);
    
    // Read the echo pin
    duration = pulseIn(ECHO_PIN, HIGH);
    
    // Calculate distance in cm (speed of sound = 340 m/s)
    distance = (duration * 0.034) / 2; // Divide by 2 because the sound travels to the object and back
    
    // Read TDS and pH values
    int tdsValue = analogRead(TDS_PIN); // Read TDS value
    int phValue = analogRead(PH_PIN);   // Read pH value

    // Print values to Serial Monitor
    Serial.print("Water Level (cm): ");
    Serial.println(distance);
    Serial.print("TDS Value: ");
    Serial.println(tdsValue);
    Serial.print("pH Value: ");
    Serial.println(phValue);
    
    // Wait for a second before the next reading
    delay(1000);
}

This code is designed to be uploaded to the ESP32 Devkit V1. It initializes the pins connected to the sensors, reads the distance from the HC-SR04 Ultrasonic Sensor, and the TDS and pH values from their respective sensors. The results are printed to the Serial Monitor every second.