This project develops a real-time flood monitoring system using water level, humidity, rain, and IoT sensors connected to the FAVORIOT platform via a GSM/4G module (SIM800L/SIM7600). It is ideal for deployment in remote areas without WiFi connectivity.


1. System Architecture

1.1. Workflow

  1. Data Collection – Sensors measure water level, humidity, temperature, and rain detection.
  2. Data Processing – The microcontroller (ESP32/Arduino) receives the data.
  3. Cloud Transmission – Data is uploaded to FAVORIOT using 4G LTE via GSM modules (SIM800L/SIM7600).
  4. Analysis & Visualization – The FAVORIOT dashboard displays real-time monitoring data.
  5. Early Warning System – If the water level exceeds the threshold, FAVORIOT sends an SMS or Telegram alert.

2. Recommended Hardware Components

Component Function
ESP32 / Arduino Mega 2560 Main processor
GSM 4G Module (SIM800L / SIM7600) Data transmission to cloud
Ultrasonic Sensor (HC-SR04) Measures water level
Soil Moisture Sensor (YL-69) Detects soil moisture level
Rain Sensor (FC-37) Detects rainfall presence
DHT11 / DHT22 Measures temperature & humidity
Relay Module Controls siren or water pump
LiPo Battery + Solar Panel Power supply for off-grid deployment

3. Hardware Setup & Wiring

3.1. Connection Overview

Component ESP32/Arduino Pin
Ultrasonic Sensor (Trig / Echo) GPIO 5, GPIO 18
Rain Sensor (Digital Out) GPIO 15
Soil Moisture Sensor (Analog Out) GPIO 34
DHT11 / DHT22 (Data Pin) GPIO 4
GSM Module (TX/RX) GPIO 16, GPIO 17
Relay Module GPIO 23

4. Software Development

4.1. Install Required Libraries

For ESP32/Arduino, ensure the following libraries are installed in the Arduino IDE:

#include <SoftwareSerial.h>
#include <DHT.h>


4.2. Connecting to FAVORIOT IoT Cloud via 4G GSM

SoftwareSerial gsmSerial(16, 17); // TX to 16, RX to 17 (adjust for GSM module)

String apiKey = "your_favoriot_api_key";
String deviceId = "your_device_id";
String serverURL = "https://apiv2.favoriot.com/v2/streams";


4.3. Flood Detection & Data Transmission to FAVORIOT via GSM

#include <SoftwareSerial.h>
#include <DHT.h>

#define TRIG_PIN 5
#define ECHO_PIN 18
#define DHTPIN 4
#define DHTTYPE DHT11
#define RAIN_SENSOR 15
#define SOIL_SENSOR 34
#define RELAY_PIN 23

DHT dht(DHTPIN, DHTTYPE);
SoftwareSerial gsmSerial(16, 17); // TX to 16, RX to 17

String apiKey = "your_favoriot_api_key";
String deviceId = "your_device_id";
String serverURL = "https://apiv2.favoriot.com/v2/streams";

void setup() {
    Serial.begin(115200);
    gsmSerial.begin(9600);
    
    pinMode(TRIG_PIN, OUTPUT);
    pinMode(ECHO_PIN, INPUT);
    pinMode(RAIN_SENSOR, INPUT);
    pinMode(SOIL_SENSOR, INPUT);
    pinMode(RELAY_PIN, OUTPUT);
    dht.begin();

    Serial.println("Initializing GSM...");
    sendATCommand("AT", "OK");
    sendATCommand("AT+CSQ", "OK");
    sendATCommand("AT+CREG?", "OK");
    sendATCommand("AT+CGATT=1", "OK");
    sendATCommand("AT+CSTT=\"internet\"", "OK"); // Ensure correct APN
    sendATCommand("AT+CIICR", "OK");
    sendATCommand("AT+CIFSR", ".");
    Serial.println("GSM Connection Established!");
}

void sendATCommand(String command, String expectedResponse) {
    gsmSerial.println(command);
    delay(1000);
    while (gsmSerial.available()) {
        String response = gsmSerial.readString();
        if (response.indexOf(expectedResponse) != -1) {
            Serial.println(response);
            break;
        }
    }
}

float getWaterLevel() {
    digitalWrite(TRIG_PIN, LOW);
    delayMicroseconds(2);
    digitalWrite(TRIG_PIN, HIGH);
    delayMicroseconds(10);
    digitalWrite(TRIG_PIN, LOW);
    float duration = pulseIn(ECHO_PIN, HIGH);
    return (duration * 0.034 / 2); // Distance in cm
}

void sendDataToFavoriot(float waterLevel, float temp, float humidity, int rain, int soil) {
    String jsonData = "{\"device_developer_id\":\"" + deviceId + 
                      "\", \"data\": {\"water_level\":\"" + String(waterLevel) + 
                      "\", \"temperature\":\"" + String(temp) + 
                      "\", \"humidity\":\"" + String(humidity) + 
                      "\", \"rain_detected\":\"" + String(rain) + 
                      "\", \"soil_moisture\":\"" + String(soil) + "\"}}";

    String command = "AT+HTTPPARA=\"URL\",\"" + serverURL + "\"";
    sendATCommand(command, "OK");
    sendATCommand("AT+HTTPPARA=\"CONTENT\",\"application/json\"", "OK");
    sendATCommand("AT+HTTPDATA=" + String(jsonData.length()) + ",10000", "DOWNLOAD");
    
    gsmSerial.println(jsonData);
    delay(5000);
    
    sendATCommand("AT+HTTPACTION=1", "OK");
}

void loop() {
    float waterLevel = getWaterLevel();
    float temperature = dht.readTemperature();
    float humidity = dht.readHumidity();
    int rainDetected = digitalRead(RAIN_SENSOR);
    int soilMoisture = analogRead(SOIL_SENSOR);

    Serial.print("Water Level: "); Serial.println(waterLevel);
    Serial.print("Temperature: "); Serial.println(temperature);
    Serial.print("Humidity: "); Serial.println(humidity);
    Serial.print("Rain Detected: "); Serial.println(rainDetected);
    Serial.print("Soil Moisture: "); Serial.println(soilMoisture);

    if (waterLevel > 50) {
        digitalWrite(RELAY_PIN, HIGH); // Activate siren or pump
    } else {
        digitalWrite(RELAY_PIN, LOW);
    }

    sendDataToFavoriot(waterLevel, temperature, humidity, rainDetected, soilMoisture);

    delay(60000); // Send data every 1 minute
}


5. Benefits of Using 4G LTE

Ideal for remote locations without WiFi
Can function even during extreme weather
Real-time flood alerts sent directly to FAVORIOT


Conclusion

By integrating a GSM 4G LTE module, smart sensors, and the FAVORIOT platform, this system enables real-time flood monitoring, early warning alerts, and supports disaster risk management for enhanced safety.

References

Disclaimer

This article provides a step-by-step guide. The source code may need adjustments to fit the final project design.

Podcast also available on PocketCasts, SoundCloud, Spotify, Google Podcasts, Apple Podcasts, and RSS.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share This

Share this post with your friends!

Discover more from IoT World

Subscribe now to keep reading and get access to the full archive.

Continue reading