Logo

ESP32-Based Smart Water Quality Monitoring System

Introduction to Smart Water Quality Monitoring

Water quality monitoring is crucial for ensuring safe water for human consumption, agriculture, and industrial use. This project involves building a smart water quality monitoring system using the ESP32 microcontroller, which will continuously monitor parameters like pH, turbidity, temperature, and dissolved oxygen. The data will be sent to the cloud for real-time analysis and remote monitoring.

Components Required

To build the ESP32-based smart water quality monitoring system, you will need various components like an ESP32 development board, pH sensor, turbidity sensor, temperature sensor, dissolved oxygen sensor, and a Wi-Fi connection for transmitting data to the cloud.

  • Set up the ESP32 development environment with the necessary libraries.
  • Connect the pH, turbidity, temperature, and dissolved oxygen sensors to the ESP32 board.
  • Configure the Wi-Fi connection for the ESP32 to send data to the cloud.
  • Write code to collect sensor data and send it to the cloud server (e.g., ThingSpeak or a custom MQTT broker).
  • Test the system by immersing the sensors in water and monitoring the collected data.
  • Display the water quality parameters on a web or mobile interface for real-time monitoring.

Formula: Water Quality Index (WQI) = (pH * Temperature + Turbidity + DO) / 3

Components List

  • 1 × ESP32 Development Board
  • 1 × pH Sensor
  • 1 × Turbidity Sensor
  • 1 × Temperature Sensor (e.g., DS18B20)
  • 1 × Dissolved Oxygen Sensor
  • 1 × Wi-Fi Module (ESP32 has built-in Wi-Fi)
  • 1 × Power Supply (e.g., 5V adapter or Li-Po battery)
  • 1 × Jumper Wires and Breadboard

Pin Configuration

  • GPIO 34 (pH Sensor): pH sensor data pin connected to GPIO 34 of the ESP32.
  • GPIO 35 (Turbidity Sensor): Turbidity sensor connected to GPIO 35 of the ESP32.
  • GPIO 32 (Temperature Sensor): Temperature sensor (DS18B20) connected to GPIO 32 for temperature readings.
  • GPIO 33 (Dissolved Oxygen Sensor): Dissolved oxygen sensor connected to GPIO 33 of the ESP32.

Make sure to calibrate the sensors before use to ensure accurate water quality readings.

Wiring and Connections

  • -> GPIO 34 (Analog input)
  • -> GPIO 35 (Analog input)
  • -> GPIO 32 (Digital input)
  • -> GPIO 33 (Analog input)

Code for ESP32-Based Smart Water Quality Monitoring System

1#include <WiFi.h>
2#include <ThingSpeak.h>
3#include <DHT.h>
4
5const char* ssid = "Your_SSID";
6const char* password = "Your_PASSWORD";
7const unsigned long channelID = Your_ThingSpeak_Channel_ID;
8const char* writeAPIKey = "Your_ThingSpeak_Write_API_Key";
9
10#define PH_PIN 34
11#define TURBIDITY_PIN 35
12#define TEMP_PIN 32
13#define DO_PIN 33
14
15WiFiClient client;
16
17void setup() {
18  Serial.begin(115200);
19  WiFi.begin(ssid, password);
20  while (WiFi.status() != WL_CONNECTED) {
21    delay(1000);
22    Serial.println("Connecting to WiFi...");
23  }
24  Serial.println("Connected to WiFi");
25  ThingSpeak.begin(client);
26}
27
28void loop() {
29  float pH = analogRead(PH_PIN);  // Read pH sensor
30  float turbidity = analogRead(TURBIDITY_PIN);  // Read turbidity sensor
31  float temperature = analogRead(TEMP_PIN);  // Read temperature sensor
32  float dissolvedOxygen = analogRead(DO_PIN);  // Read dissolved oxygen sensor
33
34  // Send data to ThingSpeak
35  ThingSpeak.setField(1, pH);
36  ThingSpeak.setField(2, turbidity);
37  ThingSpeak.setField(3, temperature);
38  ThingSpeak.setField(4, dissolvedOxygen);
39  ThingSpeak.writeFields(channelID, writeAPIKey);
40  delay(10000);  // Wait for 10 seconds before the next data update
41}

Code Explanation

  • #include <WiFi.h>: This includes the WiFi library, allowing the ESP32 to connect to the local Wi-Fi network.
  • ThingSpeak.begin(client);: This initializes the connection with ThingSpeak, allowing the ESP32 to send data to the ThingSpeak cloud platform.
  • ThingSpeak.setField(1, pH);: This line sends the pH value to ThingSpeak. Each sensor value is mapped to a field on the ThingSpeak platform.
  • ThingSpeak.writeFields(channelID, writeAPIKey);: This sends the collected sensor data to ThingSpeak, where it will be stored and made accessible for visualization.

Applications

  • Continuous monitoring of water quality in industrial, agricultural, and municipal water supplies.
  • Remote water quality monitoring in lakes, rivers, and reservoirs.
  • Real-time tracking of key water parameters such as pH, turbidity, and dissolved oxygen.
  • Environmental monitoring for ensuring safe water conditions in urban and rural areas.

Conclusion

The ESP32-based smart water quality monitoring system offers an affordable and scalable solution for real-time water quality monitoring. By using various sensors to measure important water parameters and sending the data to the cloud, this system helps ensure water safety and quality in various applications, from agriculture to municipal water systems.