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

Arduino UNO-Based Smart Water Quality Monitoring System with Wi-Fi Connectivity

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Smart Water Quality Monitoring System with Wi-Fi Connectivity

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

  1. 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
  2. HC-SR04 Ultrasonic Sensor

    • Description: Ultrasonic distance sensor.
    • Pins: VCC, TRIG, ECHO, GND
  3. Turbidity Sensor

    • Description: Sensor to measure the turbidity of water.
    • Pins: OUT, VCC, GND
  4. 12V Battery

    • Description: Power supply for the circuit.
    • Pins: -, +
  5. Temperature Sensor

    • Description: Sensor to measure temperature.
    • Pins: Temp GND Black, Temp VDD Red, Temp DQ Data Yellow
  6. Wifi module ESP8266-01

    • Description: WiFi module for wireless communication.
    • Pins: RX, GPIO0, GPIO2, GND, +3V3, Reset, CH-PD Chip power down, TX
  7. PH Meter

    • Description: Sensor to measure the pH level of a solution.
    • Pins: Signal, VCC, GND

Wiring Details

Arduino UNO

HC-SR04 Ultrasonic Sensor

Turbidity Sensor

12V Battery

Temperature Sensor

Wifi module ESP8266-01

PH Meter

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);
        }