Arduino Nano-Based Water Quality Monitoring System with GSM Alert
View and Edit Project In Cirkit Designer
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
- Arduino Nano: A compact microcontroller board based on the ATmega328P, featuring digital and analog I/O pins.
- Turbidity Module: A sensor for measuring the turbidity (cloudiness) of water, which can be an indicator of water quality.
- SIM900A: A GSM/GPRS module that allows the microcontroller to communicate over a mobile network.
- PH Meter: An electronic device used to measure the pH level (acidity or alkalinity) of water.
- DS18B20 1-Wire Temperature Sensor Probe Cable: A digital temperature sensor that uses a one-wire interface for communication.
- Resistor (4.7 Ohms): A passive two-terminal electrical component that implements electrical resistance as a circuit element.
- USB male 2 pin connection: A connector for providing power to the circuit.
- 9V Battery: A standard battery used to power the circuit.
- LCD screen 16x2 I2C: A liquid crystal display capable of displaying 16 characters per line in 2 lines, with an I2C interface for communication.
Wiring Details
Arduino Nano
- D2: Connected to the DS18B20 temperature sensor's shield wire through a 4.7 Ohm resistor.
- GND: Common ground shared with the resistor, SIM900A, pH Meter, DS18B20 temperature sensor, and turbidity module.
- D1/TX: Connected to SIM900A's 5VT pin for transmitting data.
- D0/RX: Connected to SIM900A's 5VR pin for receiving data.
- 5V: Powers the SIM900A, pH Meter, DS18B20 temperature sensor, and turbidity module.
- A1: Reads the analog output from the turbidity module.
- A0: Reads the analog signal from the pH meter.
- D10: Connected to the LCD screen's SDA pin for I2C data.
- D11/MOSI: Connected to the LCD screen's SCL pin for I2C clock.
Turbidity Module
- GND: Connected to the common ground.
- AO: Analog output connected to Arduino Nano's A1 pin.
- VCC: Power supply connected to Arduino Nano's 5V pin.
SIM900A
- GND: Connected to the common ground.
- 5VT: Transmitting data to Arduino Nano's D1/TX pin.
- 5VR: Receiving data from Arduino Nano's D0/RX pin.
- 5V: Power supply connected to Arduino Nano's 5V pin.
PH Meter
- Signal: Analog signal connected to Arduino Nano's A0 pin.
- VCC: Power supply connected to Arduino Nano's 5V pin.
- GND: Connected to the common ground.
DS18B20 1-Wire Temperature Sensor Probe Cable
- Shield: Connected to Arduino Nano's D2 pin through a 4.7 Ohm resistor.
- GND: Connected to the common ground.
- VDD: Power supply connected to Arduino Nano's 5V pin.
Resistor (4.7 Ohms)
- Pin1: Connected to Arduino Nano's D2 pin and DS18B20 temperature sensor's shield wire.
- Pin2: Connected to the common ground.
USB male 2 pin connection
- Negative -: Connected to the 9V battery's negative terminal.
- Positive +: Connected to the 9V battery's positive terminal.
9V Battery
- -: Connected to the USB male 2 pin connection's Negative -.
- +: Connected to the USB male 2 pin connection's Positive +.
LCD screen 16x2 I2C
- SCL: I2C clock connected to Arduino Nano's D11/MOSI pin.
- SDA: I2C data connected to Arduino Nano's D10 pin.
- VCC: Power supply connected to Arduino Nano's 5V pin.
- GND: Connected to the common ground.
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.