The Flood Alert System is designed to monitor water levels using a sensor and to provide alerts when the water level exceeds a certain threshold. The system uses an Arduino UNO as the main controller, interfaced with a Water Level Sensor for detecting water levels, a SIM800L GSM Module for sending SMS alerts and making calls, and an LCD Display for real-time water level display. The Arduino UNO is programmed to read the water level, display it on the LCD, and use the GSM module to communicate alerts.
// Flood Alert System
// This Arduino sketch monitors water levels using a sensor connected to A3.
// If the water level exceeds a threshold, it sends an SMS alert and makes a call
// using the GSM module. The water level is also displayed on an LCD.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include "Adafruit_FONA.h"
#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4
int resval = 25; // holds the value
int respin = A3; // Water Level Sensor Pin
int SDA_PIN = A4;
int SCL_PIN = A5;
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define FONA_RI_INTERRUPT 0
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
char PHONE_1[21] = "+919732329418"; // Enter your Mobile Number
char tempalert[141] = "Flood Alert";
void setup() {
Wire.begin();
lcd.init();
lcd.backlight();
Serial.begin(115200);
Serial.println(F("Initializing....(May take 3 seconds)"));
delay(5000);
fonaSS.begin(9600); // if you're using software serial
if (!fona.begin(fonaSS)) { // can also try fona.begin(Serial1)
Serial.println(F("Couldn't find FONA"));
while (1);
}
fona.print("AT+CSMP=17,167,0,0\r");
Serial.println(F("FONA is OK"));
}
void loop() {
resval = analogRead(respin);
Serial.print("Water Level:");
Serial.println(resval);
if (resval > 50) {
Serial.println("Flood Alert");
lcd.setCursor(0, 0);
lcd.print("Water Level:");
lcd.print(resval);
lcd.setCursor(0, 1);
lcd.print("Calling....");
make_multi_call();
send_multi_sms();
} else {
lcd.setCursor(0, 0);
lcd.print("Water Level:");
lcd.print(resval);
}
}
void send_multi_sms() {
if (PHONE_1 != "") {
Serial.print("Phone 1: ");
fona.sendSMS(PHONE_1, tempalert);
delay(20000);
}
}
void make_multi_call() {
if (PHONE_1 != "") {
Serial.print("Phone 1: ");
make_call(PHONE_1);
delay(20000);
}
}
void make_call(String phone) {
Serial.println("calling....");
lcd.setCursor(0, 1);
lcd.print("Calling....");
fona.println("ATD" + phone + ";");
delay(20000); // 20 sec delay
fona.println("ATH");
delay(1000); // 1 sec delay
}
Note: The code provided is for the Arduino UNO microcontroller. It includes libraries for the LCD display and GSM module, defines pin connections, and contains functions for reading the water level sensor, displaying information on the LCD, and communicating via SMS and calls using the GSM module. The code is set up to trigger alerts when the water level exceeds a predefined threshold.