Arduino UNO-Based Smart Water Quality Monitoring System with Wi-Fi Connectivity
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to read data from various sensors including a turbidity sensor, pH meter, temperature sensor, and an HC-SR04 ultrasonic sensor. The data is processed by an Arduino UNO microcontroller and sent to a server via a WiFi module (ESP8266-01). The circuit also includes a 12V battery for power supply. Alerts are sent if sensor values are out of specified ranges.
Component List
Arduino UNO
- Description: Microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
HC-SR04 Ultrasonic Sensor
- Description: Ultrasonic distance sensor.
- Pins: VCC, TRIG, ECHO, GND
Turbidity Sensor
- Description: Sensor to measure the turbidity of water.
- Pins: OUT, VCC, GND
12V Battery
- Description: Power supply for the circuit.
- Pins: -, +
Temperature Sensor
- Description: Sensor to measure temperature.
- Pins: Temp GND Black, Temp VDD Red, Temp DQ Data Yellow
Wifi module ESP8266-01
- Description: WiFi module for wireless communication.
- Pins: RX, GPIO0, GPIO2, GND, +3V3, Reset, CH-PD Chip power down, TX
PH Meter
- Description: Sensor to measure the pH level of a solution.
- Pins: Signal, VCC, GND
Wiring Details
Arduino UNO
- D6 connected to ECHO of HC-SR04 Ultrasonic Sensor
- D7 connected to TRIG of HC-SR04 Ultrasonic Sensor
- A4 not connected
- 5V connected to:
- VCC of Turbidity Sensor
- VCC of PH Meter
- VCC of HC-SR04 Ultrasonic Sensor
- Temp VDD Red of Temperature Sensor
- A3 connected to Signal of PH Meter
- A2 connected to OUT of Turbidity Sensor
- A1 connected to Temp DQ Data Yellow of Temperature Sensor
- GND connected to:
- GND of HC-SR04 Ultrasonic Sensor
- Temp GND Black of Temperature Sensor
- GND of PH Meter
- GND of Turbidity Sensor
- 3.3V connected to +3V3 of Wifi module ESP8266-01
- GND connected to:
- GND of Wifi module ESP8266-01
- - of 12V Battery
- Vin connected to + of 12V Battery
HC-SR04 Ultrasonic Sensor
- ECHO connected to D6 of Arduino UNO
- TRIG connected to D7 of Arduino UNO
- VCC connected to 5V of Arduino UNO
- GND connected to GND of Arduino UNO
Turbidity Sensor
- OUT connected to A2 of Arduino UNO
- VCC connected to 5V of Arduino UNO
- GND connected to GND of Arduino UNO
12V Battery
- + connected to Vin of Arduino UNO
- - connected to GND of Arduino UNO
Temperature Sensor
- Temp GND Black connected to GND of Arduino UNO
- Temp VDD Red connected to 5V of Arduino UNO
- Temp DQ Data Yellow connected to A1 of Arduino UNO
Wifi module ESP8266-01
- +3V3 connected to 3.3V of Arduino UNO
- GND connected to GND of Arduino UNO
PH Meter
- Signal connected to A3 of Arduino UNO
- VCC connected to 5V of Arduino UNO
- GND connected to GND of Arduino UNO
Documented Code
Arduino UNO Code
/*
* This Arduino Sketch reads data from various sensors (turbidity, pH,
* temperature, and distance) and sends the data to a server. It also
* sends alerts if sensor values are out of specified ranges. The code
* ensures functionality even when WiFi is disconnected.
*/
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
const char* serverName = "http://yourserver.com/api/data";
const char* alertServerName = "http://yourserver.com/api/alert";
const int turbidityPin = A2; // Turbidity sensor output connected to A2
const int phPin = A3; // pH meter signal connected to A3
const int tempPin = A1; // Temperature sensor data connected to A1
const int trigPin = 7; // HC-SR04 TRIG pin connected to D7
const int echoPin = 6; // HC-SR04 ECHO pin connected to D6
unsigned long previousMillis = 0;
const long interval = 1800000; // 30 minutes
void setup() {
Serial.begin(9600);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
int turbidityValue = analogRead(turbidityPin);
int phValue = analogRead(phPin);
float voltage = phValue * (5.0 / 1023.0);
float ph = 7 + ((2.5 - voltage) / 0.18);
int tempValue = analogRead(tempPin);
float tempVoltage = tempValue * (5.0 / 1023.0);
float temperature = (tempVoltage - 0.5) * 100.0;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
float distance = (duration * 0.034) / 2;
Serial.print("Turbidity Value: ");
Serial.println(turbidityValue);
Serial.print("pH Value: ");
Serial.println(ph);
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(serverName);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String httpRequestData = "turbidity=" + String(turbidityValue) + "&ph=" +
String(ph) + "&temperature=" + String(temperature) +
"&distance=" + String(distance);
int httpResponseCode = http.POST(httpRequestData);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
} else {
Serial.print("Error on sending POST: ");
Serial.println(httpResponseCode);
}
http.end();
} else {
Serial.println("WiFi Disconnected");
}
if (ph < 6.5 || ph > 8.5 || turbidityValue > 5 || distance < 50) {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(alertServerName);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String alertData = "alert=1&turbidity=" + String(turbidityValue) + "&ph=" +
String(ph) + "&temperature=" + String(temperature) +
"&distance=" + String(distance);
int alertResponseCode = http.POST(alertData);
if (alertResponseCode > 0) {
String response = http.getString();
Serial.println(alertResponseCode);
Serial.println(response);
}