πΏ Smart Garden Manager in C++ with Robotics, UI, Drones, and Sound "A Rainwater Conservation System for Tomorrow’s Farms"

Floods are among the most devastating natural disasters, causing massive loss to life, property, and infrastructure. In many flood-prone regions, early detection and alert systems can save lives and minimize damage. In this blogpost, we’ll build a C++-based smart flood detection system using robotic sensors, targeting microcontroller platforms like Arduino or Raspberry Pi.
This project, named FloodGuard, will monitor water levels, send real-time alerts, and act as a preventive measure in rural and urban flood zones. We'll write and explain the entire C++ code, integrate real sensors, and simulate outputs. The blog is designed for developers, students, and educators.
To create a flood monitoring system that detects rising water levels and alerts users via LED, buzzer, and SMS using a GSM module.
Monitor water level using ultrasonic/water-level sensor
Trigger buzzer/LED when dangerous level is reached
Send SMS alert using GSM module
Display sensor readings in serial monitor or optional GUI
Designed using C++ for Arduino/Raspberry Pi boards
Component | Quantity | Description |
---|---|---|
Arduino UNO/Nano | 1 | Microcontroller board |
Ultrasonic Sensor (HC-SR04) | 1 | For distance/water level measurement |
Buzzer | 1 | Audible alert |
LED (Red/Green) | 2 | Visual warning indicator |
GSM Module (SIM800L) | 1 | For sending SMS alerts |
Resistors (220 ohm) | 2 | For LEDs |
Breadboard + Wires | - | Circuit prototyping |
USB Cable | 1 | Upload code to Arduino |
Optional: Raspberry Pi instead of Arduino, LCD display, IoT cloud service (e.g., Blynk)
The system uses an ultrasonic sensor to measure the distance between the sensor and the water surface. If the distance decreases below a predefined threshold (indicating rising water level), the system:
Activates a buzzer and LED
Sends an SMS warning to a predefined phone number
Safe: Distance > 15 cm
Warning: Distance between 7–15 cm
Danger: Distance < 7 cm
#define trigPin 9
#define echoPin 10
#define buzzerPin 6
#define greenLED 5
#define redLED 4
#include <SoftwareSerial.h>
SoftwareSerial gsm(7, 8); // RX, TX for GSM
long duration;
int distance;
bool smsSent = false;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(redLED, OUTPUT);
Serial.begin(9600);
gsm.begin(9600);
delay(1000);
Serial.println("FloodGuard system starting...");
sendSMS("FloodGuard online. Monitoring initiated.");
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
Serial.print("Water Level: ");
Serial.print(distance);
Serial.println(" cm");
if (distance > 15) {
digitalWrite(greenLED, HIGH);
digitalWrite(redLED, LOW);
digitalWrite(buzzerPin, LOW);
smsSent = false;
}
else if (distance <= 15 && distance >= 7) {
digitalWrite(greenLED, LOW);
digitalWrite(redLED, HIGH);
digitalWrite(buzzerPin, LOW);
smsSent = false;
}
else if (distance < 7 && !smsSent) {
digitalWrite(buzzerPin, HIGH);
digitalWrite(greenLED, LOW);
digitalWrite(redLED, HIGH);
sendSMS("WARNING: Flood danger! Water level critical.");
smsSent = true;
}
delay(2000);
}
void sendSMS(String message) {
gsm.println("AT+CMGF=1");
delay(100);
gsm.println("AT+CMGS=\"+923001234567\""); // Replace with your number
delay(100);
gsm.println(message);
delay(100);
gsm.write(26);
delay(1000);
}
Image: Circuit showing Arduino, HC-SR04, LED, buzzer, and GSM module
Protect crops, homes, and lives during monsoon season
Deployed in underpasses, riverbanks, and drainage lines
STEM students can learn robotics, coding, and sensor interfacing
pulseIn(): Measures the duration of the ultrasonic echo
Serial.print(): Debug output to Arduino IDE
SoftwareSerial: Allows GSM communication
Digital Output: Controls LED and buzzer based on logic
Add Wi-Fi/Bluetooth module to upload data to the cloud
Use SFML in desktop simulation for real-time graphs
Use water quality sensor to detect chemical flood risks
Integrate solar panel for remote areas
FloodGuard is a powerful demonstration of using C++ and robotic sensors to combat real-world challenges like flooding. With low-cost sensors, some programming skills, and a microcontroller board, communities can take the first step toward building disaster-resilient infrastructure.
π Stay safe, stay prepared. Build smart solutions with code!
Comments
Post a Comment