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.
Arduino UNO
TDS Sensor 2
16x2 I2C LCD
SIM900A
LED: Two Pin (green)
/*
* 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.