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

Arduino Nano-Based Water Quality Monitoring System with GSM Alert

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Based Water Quality Monitoring System with GSM Alert

Circuit Documentation

Summary

The circuit is designed to monitor water quality parameters including pH, turbidity, and temperature. It utilizes an Arduino Nano as the central microcontroller to interface with a turbidity module, a pH meter, a DS18B20 temperature sensor, and a SIM900A GSM module for communication. The system reads the sensor values, compares them against predefined thresholds, and sends an SMS alert if any of the readings exceed these thresholds.

Component List

Wiring Details

Arduino Nano

Turbidity Module

SIM900A

PH Meter

DS18B20 1-Wire Temperature Sensor Probe Cable

Resistor (4.7 Ohms)

USB male 2 pin connection

9V Battery

LCD screen 16x2 I2C

Documented Code

#include <DallasTemperature.h>
#include <OneWire.h>
#include <SoftwareSerial.h>

// Pin Definitions
#define PH_SENSOR_PIN A0
#define TURBIDITY_SENSOR_PIN A1
#define ONE_WIRE_BUS 2  // DS18B20 sensor pin
#define SIM900_TX 7
#define SIM900_RX 8

// Thresholds
#define PH_THRESHOLD 8.5   // Adjust based on HAB pH trigger
#define TURBIDITY_THRESHOLD 100  // Adjust based on HAB turbidity level
#define TEMP_THRESHOLD 25  // Set appropriate temperature threshold

// Sensor Initialization
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
SoftwareSerial sim900(SIM900_TX, SIM900_RX);

// Variables for readings
float pHValue = 0.0;
float turbidityValue = 0.0;
float temperatureC = 0.0;

void setup() {
  // Initialize Serial, GSM, and sensors
  Serial.begin(9600);
  sim900.begin(9600);
  sensors.begin();

  Serial.println("HAB Monitoring System Initialized");
  delay(2000);
}

void loop() {
  // Read pH Sensor
  pHValue = readPH(PH_SENSOR_PIN);

  // Read Turbidity Sensor
  turbidityValue = readTurbidity(TURBIDITY_SENSOR_PIN);

  // Read Temperature Sensor
  sensors.requestTemperatures();
  temperatureC = sensors.getTempCByIndex(0);

  // Print readings to Serial Monitor
  Serial.print("pH: ");
  Serial.print(pHValue);
  Serial.print(" | NTU: ");
  Serial.print(turbidityValue);
  Serial.print(" | Temp: ");
  Serial.print(temperatureC);
  Serial.println(" C");

  // Check thresholds and send SMS if needed
  if (pHValue > PH_THRESHOLD || turbidityValue > TURBIDITY_THRESHOLD || temperatureC > TEMP_THRESHOLD) {
    sendAlert();
  }

  delay(5000);  // Update every 5 seconds
}

// Function to read pH sensor
float readPH(int pin) {
  int phValue = analogRead(pin);
  return (phValue * (5.0 / 1023.0)) * 3.5;  // Convert to pH
}

// Function to read turbidity sensor
float readTurbidity(int pin) {
  int turbidity = analogRead(pin);
  return turbidity * (5.0 / 1023.0) * 100.0;  // Convert to NTU
}

// Function to send SMS alert
void sendAlert() {
  sim900.print("AT+CMGF=1\r");  // Set SMS to Text Mode
  delay(100);
  sim900.println("AT+CMGS=\"+1234567890\"");  // Replace with phone number
  delay(100);
  sim900.print("HAB Alert!\n");
  sim900.print("pH: ");
  sim900.print(pHValue);
  sim900.print(" | NTU: ");
  sim900.print(turbidityValue);
  sim900.print(" | Temp: ");
  sim900.print(temperatureC);
  sim900.println(" C");
  delay(100);
  sim900.write(26);  // End AT command with a ^Z, ASCII code 26
  delay(1000);
}

This code is responsible for initializing the sensors and the SIM900 module, reading sensor data, and sending an SMS alert if any of the readings exceed the predefined thresholds. The readPH and readTurbidity functions convert the raw analog readings to pH and NTU (Nephelometric Turbidity Units) respectively. The sendAlert function sends an SMS message with the current sensor readings.