Arduino UNO-Based Water Quality Monitoring System with TDS Sensor and SIM900A SMS Alerts
View and Edit Project In Cirkit Designer
Water Quality Monitoring System Documentation
Summary
This project is a Water Quality Monitoring System that uses an Arduino Uno to monitor water quality using a TDS sensor. The results are displayed on a 16x2 I2C LCD. A green LED indicates good water quality. If the water quality is poor, an SMS alert is sent using the SIM900A module.
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
TDS Sensor 2
- Description: Sensor to measure Total Dissolved Solids (TDS) in water.
- Pins: AIn, GND, 5V
16x2 I2C LCD
- Description: 16x2 character LCD with I2C interface.
- Pins: GND, VCC, SDA, SCL
SIM900A
- Description: GSM/GPRS module for sending SMS alerts.
- Pins: GND, DB9-3 (RXD), DB9-2 (TXD), 5V, 3VR, 5VR, 3VT, 5VT, VCC, Ring, RESTART, RESET, STATUS
LED: Two Pin (green)
- Description: Green LED to indicate good water quality.
- Pins: cathode, anode
Wiring Details
Arduino UNO
- 5V: Connected to 5V of TDS Sensor 2, 5V of SIM900A, and VCC of 16x2 I2C LCD.
- GND: Connected to GND of TDS Sensor 2, anode of LED, GND of SIM900A, and GND of 16x2 I2C LCD.
- A0: Connected to AIn of TDS Sensor 2.
- SCL: Connected to SCL of 16x2 I2C LCD.
- SDA: Connected to SDA of 16x2 I2C LCD.
- D2: Connected to cathode of LED.
- D1: Connected to DB9-3 (RXD) of SIM900A.
- D0: Connected to DB9-2 (TXD) of SIM900A.
TDS Sensor 2
- 5V: Connected to 5V of Arduino UNO.
- GND: Connected to GND of Arduino UNO.
- AIn: Connected to A0 of Arduino UNO.
16x2 I2C LCD
- VCC: Connected to 5V of Arduino UNO.
- GND: Connected to GND of Arduino UNO.
- SDA: Connected to SDA of Arduino UNO.
- SCL: Connected to SCL of Arduino UNO.
SIM900A
- 5V: Connected to 5V of Arduino UNO.
- GND: Connected to GND of Arduino UNO.
- DB9-3 (RXD): Connected to D1 of Arduino UNO.
- DB9-2 (TXD): Connected to D0 of Arduino UNO.
LED: Two Pin (green)
- anode: Connected to GND of Arduino UNO.
- cathode: Connected to D2 of Arduino UNO.
Code Documentation
/*
* Project: Water Quality Monitoring System
* Description: This project uses an Arduino Uno to monitor water quality using a TDS
* sensor and display the results on a 16x2 I2C LCD. A green LED indicates good
* water quality. If the water quality is poor, an SMS alert is sent using the
* SIM900A module.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
// Pin definitions
#define LED_PIN 2
#define TDS_SENSOR_PIN A0
#define SIM900_RX_PIN 1
#define SIM900_TX_PIN 0
// Threshold for water quality
#define TDS_THRESHOLD 300
// Initialize LCD (address 0x27, 16 chars, 2 lines)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Initialize SIM900A
SoftwareSerial sim900(SIM900_TX_PIN, SIM900_RX_PIN);
void setup() {
// Initialize serial communication
Serial.begin(9600);
sim900.begin(9600);
// Initialize LCD
lcd.begin();
lcd.backlight();
// Initialize LED pin
pinMode(LED_PIN, OUTPUT);
// Display startup message
lcd.setCursor(0, 0);
lcd.print("Water Quality");
lcd.setCursor(0, 1);
lcd.print("Monitoring");
delay(2000);
lcd.clear();
}
void loop() {
// Read TDS value
int tdsValue = analogRead(TDS_SENSOR_PIN);
// Display TDS value on LCD
lcd.setCursor(0, 0);
lcd.print("TDS: ");
lcd.print(tdsValue);
// Check water quality
if (tdsValue < TDS_THRESHOLD) {
// Good water quality
digitalWrite(LED_PIN, HIGH);
lcd.setCursor(0, 1);
lcd.print("Water is Good");
} else {
// Poor water quality
digitalWrite(LED_PIN, LOW);
lcd.setCursor(0, 1);
lcd.print("Water is Dirty");
sendSMSAlert(tdsValue);
}
// Wait before next reading
delay(5000);
}
void sendSMSAlert(int tdsValue) {
// Send SMS alert using SIM900A
sim900.print("AT+CMGF=1\r");
delay(100);
sim900.print("AT+CMGS=\"+1234567890\"\r");
delay(100);
sim900.print("Alert! Water is dirty. TDS: ");
sim900.print(tdsValue);
sim900.print("\r");
delay(100);
sim900.write(26); // ASCII code for CTRL+Z
delay(100);
}
This code initializes the necessary components and continuously monitors the TDS value from the sensor. It displays the TDS value on the LCD and lights up the green LED if the water quality is good. If the water quality is poor, it sends an SMS alert using the SIM900A module.