Flood Monitoring System Using GSM And ESP8266
Flood Monitoring System Using ESP8266
Introduction
In this article, we will explore the design and implementation of a Flood Monitoring System using various components such as a 16×2 LCD display with I2C, ultrasonic sensor, float sensor, and SIM800L module. This system aims to provide real-time flood level monitoring and alert notifications to receive Text Messages.
Components Needed
S.N | Component | Quantity |
1 | ESP8266 | 1 |
2 | GSM module (SIM800l) | 1 |
3 | Ultrasonic Sensor | 1 |
4 | Float Sensor | 1 |
5 | 16x2 LCD Display With I2C | 1 |
6 | Zero PCB | 1 |
7 | 5v Power Supply | 1 |
ESP8266
ESP8266 is a Wi-Fi module developed by Espressif Microcontroller Systems. In the board is a microcontroller unit And a built-in Wi-Fi Chip, It is the low-cost solution for Wi-Fi connectivity to various projects.
16×2 LCD Display
- This is a basic 16-character by 2 lines Alphanumeric display. Black text on Green background. Utilises the extremely common HD44780 parallel interface chipset. Interface code is freely available.
GSM module (SIM800l)
GSM SIM800L is a popular module that enables communication over GSM (Global System for Mobile Communications) networks. It Sends a text message and calls to the particular Mobile Number. and is necessary to put a valid sim card in the gsm module.
- The module requires a power supply of 3.7 volts. It can be powered using an external Battery.
Ultrasonic Sensor
- Ultrasonic sensors find out the distance of the water level of the dam. And the Sensor mount on the top of the dam.
- Ultrasonic Sensor required a 5v power supply.
Float Sensor
Float sensors to detect Water levels. They consist of a float, on the water and when the water level increases the float mechanism goes to the Top and is given the alert information.
Specifications of Float Sensors
- Cable Length: 30.(cm)
- Maximum Load: 51 W
- Max Switching Voltage: 90V DC
- Minimum Voltage: 240V DC
- Maximum Switching Current: 0.6 A
- Max Load Current: 1.0 A
Circuit Diagram
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
//Prateek //https://justdoelectronics.com //https://www.youtube.com/c/JustDoElectronics/videos #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <NewPing.h> #include <SoftwareSerial.h> // LCD Display LiquidCrystal_I2C lcd(0x27, 16, 2); // Ultrasonic Sensor #define TRIGGER_PIN 12 #define ECHO_PIN 11 #define MAX_DISTANCE 200 NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // Float Sensor #define FLOAT_SENSOR_PIN 10 // GSM Module SoftwareSerial gsmSerial(8, 9); // RX, TX #define GSM_BAUDRATE 9600 // Thresholds #define FLOOD_THRESHOLD 50 // Example threshold in cm // Phone Numbers String phoneNumbers[] = { "+9188305848xx", "+9188305848xx" }; // Example phone numbers void setup() { // Initialize LCD Display lcd.begin(16, 2); lcd.backlight(); // Initialize GSM Module gsmSerial.begin(GSM_BAUDRATE); delay(2000); // Give GSM module time to initialize sendCommand("AT"); // Check communication sendCommand("AT+CMGF=1"); // Set SMS text mode // Display Initialization Message lcd.clear(); lcd.setCursor(0, 0); lcd.print("Flood Monitoring"); lcd.setCursor(0, 1); lcd.print("System"); delay(3000); // Display initialization message for 3 seconds } void loop() { // Read Ultrasonic Sensor unsigned int distance = sonar.ping_cm(); // Read Float Sensor int floatSensorValue = digitalRead(FLOAT_SENSOR_PIN); // Calculate Flood Level int floodLevel = distance; // Update LCD Display lcd.clear(); lcd.setCursor(0, 0); lcd.print("Water Level: "); lcd.print(floodLevel); lcd.print("cm"); // Check Flood Threshold if (floodLevel > FLOOD_THRESHOLD && floatSensorValue == HIGH) { // Send Alert SMS sendAlertSMS(floodLevel); } delay(500); // Delay for stability } void sendAlertSMS(int floodLevel) { String message = "Flood Alert! Water level is "; message += floodLevel; message += "cm. Take necessary actions."; for (int i = 0; i < sizeof(phoneNumbers) / sizeof(phoneNumbers[0]); i++) { sendCommand("AT+CMGS=\"" + phoneNumbers[i] + "\""); delay(1000); sendCommand(message); delay(100); sendCommand((String) char(26)); delay(1000); } } void sendCommand(String command) { gsmSerial.println(command); delay(1000); while (gsmSerial.available()) { gsmSerial.read(); } } |
Include Libraries
-
- LiquidCrystal_I2C.h: Library for interfacing with the 16×2 LCD display using I2C.
- NewPing.h: Library for working with the ultrasonic sensor.
1 2 3 4 |
#include <Wire.h> #include <LiquidCrystal_I2C.h> #include <NewPing.h> #include <SoftwareSerial.h> |
Initialize Variables and Objects
-
- Define the pins for the ultrasonic sensor (TRIGGER_PIN and ECHO_PIN) and the maximum distance to measure (MAX_DISTANCE).
- Define the pin for the float sensor (FLOAT_SENSOR_PIN).
- Create an instance of the SoftwareSerial library named “gsmSerial” using the RX and TX pins for the GSM module.
- Define the flood threshold (FLOOD_THRESHOLD) in centimetres.
- Define the phone numbers (phone numbers) to which alert SMS will be sent.
1 2 3 4 5 6 7 8 |
// Ultrasonic Sensor #define TRIGGER_PIN 12 #define ECHO_PIN 11 #define MAX_DISTANCE 200 NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); #define FLOAT_SENSOR_PIN 10 #define FLOOD_THRESHOLD 50 |
Setup Function
-
- Initialize the LCD display with the I2C address (0x27) and the number of columns and rows (16, 2).
- Initialize the GSM module with the defined baud rate.
- Send AT commands to check communication with the GSM module and set the SMS text mode.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
void setup() { // Initialize LCD Display lcd.begin(16, 2); lcd.backlight(); // Initialize GSM Module gsmSerial.begin(GSM_BAUDRATE); delay(2000); // Give GSM module time to initialize sendCommand("AT"); // Check communication sendCommand("AT+CMGF=1"); // Set SMS text mode // Display Initialization Message lcd.clear(); lcd.setCursor(0, 0); lcd.print("Flood Monitoring"); lcd.setCursor(0, 1); lcd.print("System"); delay(3000); // Display initialization message for 3 seconds } |
Loop Function
-
- Read the distance from the ultrasonic sensor using the sonar.ping_cm() function.
- Read the state of the float sensor using digitalRead(FLOAT_SENSOR_PIN).
- Clear the LCD display and update it with the current water level.
- Check if the flood level exceeds the defined threshold and the float sensor is triggered.
- If the conditions are match, call the sendAlertSMS() function to send alert SMS to the predefined phone numbers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
void loop() { // Read Ultrasonic Sensor unsigned int distance = sonar.ping_cm(); // Read Float Sensor int floatSensorValue = digitalRead(FLOAT_SENSOR_PIN); // Calculate Flood Level int floodLevel = distance; // Update LCD Display lcd.clear(); lcd.setCursor(0, 0); lcd.print("Water Level: "); lcd.print(floodLevel); lcd.print("cm"); // Check Flood Threshold if (floodLevel > FLOOD_THRESHOLD && floatSensorValue == HIGH) { // Send Alert SMS sendAlertSMS(floodLevel); } delay(500); // Delay for stability } |
sendAlertSMS Function
-
- Create a message string with the flood alert information.
- Iterate through each phone number in the phone numbers array.
- Send AT commands to the GSM module to set the recipient phone number (AT+CMGS), delay, send the message, send the message termination character (char(26)), and delay again.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
void sendAlertSMS(int floodLevel) { String message = "Flood Alert! Water level is "; message += floodLevel; message += "cm. Take necessary actions."; for (int i = 0; i < sizeof(phoneNumbers) / sizeof(phoneNumbers[0]); i++) { sendCommand("AT+CMGS=\"" + phoneNumbers[i] + "\""); delay(1000); sendCommand(message); delay(100); sendCommand((String) char(26)); delay(1000); } } |
sendCommand Function
-
- Send a command string to the GSM module using gsmSerial.println().
- Check if there is any available data from the GSM module using gsmSerial.available() and read it using gsmSerial.read() to clear the serial buffer.
1 2 3 4 5 6 7 |
void sendCommand(String command) { gsmSerial.println(command); delay(1000); while (gsmSerial.available()) { gsmSerial.read(); } } |
Video
Conclusion
This system enables early detection of floods, allowing authorities to take immediate action and mitigate potential risks. By leveraging the capabilities of these components, we can build an effective flood monitoring system to enhance disaster management and safeguard lives and property.
ESP8266 Related More Projects