India experiences some of the most severe weather events in the world — flash floods in Mumbai, cyclones along the Odisha coast, and thunderstorms that can knock out power grids for days. Building a local IoT weather alert flood warning system gives communities early warning minutes or hours before official alerts reach them. In this project guide, we will build a comprehensive IoT weather monitoring and alert system using ESP32, multiple sensors, and cloud integration that sends alerts via WhatsApp, SMS, and buzzer.
System Overview and Components
Our IoT weather alert system has four main layers:
- Sensing Layer — Multiple sensors measuring temperature, humidity, barometric pressure, rainfall, and water level
- Processing Layer — ESP32 microcontroller that reads sensor data, applies alert thresholds, and makes decisions
- Communication Layer — WiFi to send data to cloud and trigger alerts
- Alert Layer — Local buzzer/LED + remote WhatsApp/MQTT/email notifications
Complete Bill of Materials
| Component | Purpose | Approx. Cost (INR) |
|---|---|---|
| ESP32 Development Board | Main controller | ₹350-500 |
| BME280 Sensor | Temp, Humidity, Pressure | ₹180-250 |
| JSN-SR04T Waterproof Ultrasonic | Water level (flood) | ₹220-350 |
| Tipping Bucket Rain Gauge Module | Rainfall measurement | ₹800-1200 |
| Active Buzzer | Local alarm | ₹30-50 |
| 18650 Battery Shield + Cells | Backup power | ₹400-600 |
| Waterproof Junction Box | Weather protection | ₹150-300 |
Choosing the Right Weather Sensors
For a weather alert system, sensor selection is critical. You need reliable readings in harsh outdoor conditions. Here is what each sensor type measures and why it matters for weather alerts:
Barometric Pressure — The Key to Thunder and Storm Prediction
Rapidly falling barometric pressure (more than 3 hPa per hour) is one of the most reliable indicators of an approaching storm or heavy rainfall. Professional weather stations rely heavily on this metric. A BME280 sensor provides temperature, humidity, and pressure in a single compact I2C package and is perfect for this application.
GY-BME280-3.3 Precision Altimeter Atmospheric Pressure Sensor Module
Measures temperature, humidity, and barometric pressure with ±1 hPa accuracy. Rapid pressure drops detected by this sensor can alert you to incoming storms minutes before they arrive.
Water Level Sensing — Flood Detection
For flood warning, you need a sensor that can reliably measure the water level in a river, drainage channel, or low-lying area without being submerged. The JSN-SR04T waterproof ultrasonic sensor is ideal for this — it can be mounted above the water surface and measures the distance to the water level from above, without any part of the electronics touching water.
A86 JSN-SR04T Waterproof Ultrasonic Rangefinder Module Version 3.0
Weatherproof ultrasonic sensor for measuring water levels in canals, rivers, and drainage systems. IP67 rated probe can be mounted above floodwater for safe, reliable distance measurement.
Temperature and Humidity — Heat Wave and Discomfort Index
High humidity combined with high temperature creates dangerous heat index conditions. India regularly experiences heat waves exceeding 45°C with high humidity in states like Rajasthan, UP, and Bihar. The DHT20 sensor provides faster and more accurate readings than the older DHT11/DHT22 and uses I2C for easy integration.
DHT20 SIP Packaged Temperature and Humidity Sensor
Next-generation I2C temperature and humidity sensor with ±0.5°C accuracy. More reliable than DHT11 and ideal for computing heat index alerts in your weather monitoring system.
Circuit Design and Connections
Here are the pin connections for all sensors to the ESP32:
| Sensor/Device | ESP32 Pin | Notes |
|---|---|---|
| BME280 SDA | GPIO 21 | I2C bus |
| BME280 SCL | GPIO 22 | I2C bus |
| JSN-SR04T TRIG | GPIO 5 | Digital output |
| JSN-SR04T ECHO | GPIO 18 | Digital input (5V→3.3V divider) |
| Rain Gauge Signal | GPIO 4 | Interrupt pin, pull-up enabled |
| Buzzer | GPIO 2 | Via NPN transistor |
| Alert LED (Red) | GPIO 15 | Via 220Ω resistor |
Important: The JSN-SR04T operates on 5V. The ECHO output is 5V, which will damage the ESP32’s 3.3V GPIO. Use a voltage divider (10kΩ and 20kΩ) to bring it down to ~3.3V before connecting to the ESP32.
Firmware: Reading Sensors and Detecting Alerts
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <WiFi.h>
#include <PubSubClient.h>
// Pins
#define TRIG_PIN 5
#define ECHO_PIN 18
#define RAIN_PIN 4
#define BUZZER_PIN 2
#define ALERT_LED_PIN 15
// Alert thresholds
#define FLOOD_LEVEL_CM 30.0 // Alert if water level rises within 30cm of sensor
#define PRESSURE_DROP_HPA_HR 3.0 // Alert if pressure drops >3 hPa/hour (storm coming)
#define HEAVY_RAIN_MM_HR 50.0 // Alert if >50mm/hour (heavy rain)
#define HEAT_INDEX_DANGER 41.0 // Alert if heat index >41°C (danger zone)
Adafruit_BME280 bme;
volatile int rainTipCount = 0;
float pressureHistory[60]; // 1 reading per minute, 60 min history
int pressureIndex = 0;
void IRAM_ATTR onRainTip() {
rainTipCount++; // Each tip = 0.2794mm of rain (standard bucket size)
}
float measureWaterLevel() {
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
long duration = pulseIn(ECHO_PIN, HIGH, 30000);
float distanceCm = duration * 0.034 / 2.0;
return distanceCm; // Return distance from sensor to water surface
}
float calculateHeatIndex(float tempC, float humidity) {
// Simplified Rothfusz equation (US NWS formula)
float T = tempC * 9.0/5.0 + 32.0; // Convert to Fahrenheit
float R = humidity;
float HI = -42.379 + 2.04901523*T + 10.14333127*R
- 0.22475541*T*R - 0.00683783*T*T
- 0.05481717*R*R + 0.00122874*T*T*R
+ 0.00085282*T*R*R - 0.00000199*T*T*R*R;
return (HI - 32.0) * 5.0/9.0; // Back to Celsius
}
float getPressureDropRate() {
// Calculate pressure change over last hour
float oldest = pressureHistory[(pressureIndex + 1) % 60];
float newest = pressureHistory[pressureIndex];
if (oldest == 0) return 0; // Not enough data yet
return oldest - newest; // Positive = dropping (storm warning!)
}
void checkAndTriggerAlerts(float waterLevelCm, float pressureDrop,
float rainfallMmHr, float heatIndex) {
bool alertTriggered = false;
String alertMessage = "";
if (waterLevelCm < FLOOD_LEVEL_CM && waterLevelCm > 0) {
alertMessage += "FLOOD ALERT: Water level critical (" + String(waterLevelCm, 1) + "cm)! ";
alertTriggered = true;
}
if (pressureDrop >= PRESSURE_DROP_HPA_HR) {
alertMessage += "STORM ALERT: Rapid pressure drop (" + String(pressureDrop, 1) + " hPa/hr)! ";
alertTriggered = true;
}
if (rainfallMmHr >= HEAVY_RAIN_MM_HR) {
alertMessage += "HEAVY RAIN: " + String(rainfallMmHr, 1) + "mm/hr! ";
alertTriggered = true;
}
if (heatIndex >= HEAT_INDEX_DANGER) {
alertMessage += "HEAT DANGER: Heat index " + String(heatIndex, 1) + "°C! ";
alertTriggered = true;
}
if (alertTriggered) {
digitalWrite(BUZZER_PIN, HIGH);
digitalWrite(ALERT_LED_PIN, HIGH);
sendWhatsAppAlert(alertMessage);
Serial.println("ALERT: " + alertMessage);
} else {
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(ALERT_LED_PIN, LOW);
}
}
Alert System: WhatsApp, MQTT, and Buzzer
The alert delivery system is what makes this project truly useful. We use a combination of local and remote alerts:
WhatsApp Alerts via Twilio or CallMeBot
CallMeBot provides a free WhatsApp notification API that is easy to integrate with ESP32:
void sendWhatsAppAlert(String message) {
if (WiFi.status() != WL_CONNECTED) return;
HTTPClient http;
// URL encode the message
String encodedMsg = message;
encodedMsg.replace(" ", "+");
encodedMsg.replace(":", "%3A");
String url = "https://api.callmebot.com/whatsapp.php?phone="
+ PHONE_NUMBER + "&text=" + encodedMsg
+ "&apikey=" + CALLMEBOT_API_KEY;
http.begin(url);
http.setTimeout(10000);
int responseCode = http.GET();
Serial.printf("WhatsApp alert sent, response: %dn", responseCode);
http.end();
}
MQTT for Home Assistant Integration
For users running Home Assistant (very popular among Indian smart home enthusiasts), publishing to MQTT allows you to create rich dashboards and automations:
void publishToMQTT(WeatherData &data) {
char payload[256];
snprintf(payload, sizeof(payload),
"{"temp":%.1f,"humidity":%.1f,"pressure":%.1f,"
""water_level":%.1f,"rainfall_hr":%.2f,"alert":%s}",
data.temperature, data.humidity, data.pressure,
data.waterLevelCm, data.rainfallMmHr,
data.alertActive ? "true" : "false"
);
mqttClient.publish("weather/station/data", payload, true); // Retained
if (data.alertActive) {
mqttClient.publish("weather/station/alert", data.alertMessage.c_str(), false);
}
}
Field Deployment Tips for India
Deploying outdoor IoT sensors in India requires special attention to environmental conditions:
Enclosure and Weather Protection
- Use IP65 or higher rated junction boxes available at electrical supply stores
- Add silica gel desiccant packets inside the enclosure — Indian monsoons can saturate sealed boxes with moisture over weeks
- Mount the BME280 in a Stevenson screen (louvered shield) to prevent direct sun from affecting temperature readings
- Use marine-grade silicone to seal cable entry points
Power Design
- Use 18650 Li-ion batteries with a solar charging circuit for off-grid deployments
- In remote areas without WiFi, use a SIM800L GSM module for 2G SMS alerts
- Implement deep sleep between readings to extend battery life — wake up every 5 minutes for routine readings, but keep one interrupt pin active for the rain gauge tip
Connectivity Alternatives
In flood-prone rural areas where WiFi is unavailable, consider:
- LoRa (SX1278): Range up to 5km, no SIM needed, ideal for village flood networks
- SIM800L/A7672: 2G/4G GSM for nationwide SMS alerts
- ESP-NOW: ESP32 mesh network for sensor nodes relaying data to a central gateway
2 x 18650 Lithium Battery Shield V8 Mobile Power Expansion Board Module 5V/3A for Arduino ESP32
Power your outdoor weather station continuously with dual 18650 cells. Provides both 5V/3A and 3.3V outputs — perfect for powering the ESP32 and sensors during extended power cuts during storms.
Frequently Asked Questions
Q: How accurate is barometric pressure for storm prediction?
A pressure drop of 3 hPa or more within a single hour is a reliable indicator of an approaching storm or squall. A drop of 6+ hPa/hour indicates a rapidly intensifying storm. However, this is a local indicator — large-scale monsoon systems approaching from hundreds of kilometres away may not show local pressure drops until just a few hours before arrival. Combine pressure data with IMD API weather forecasts for best results.
Q: What is the maximum range of the JSN-SR04T for water level measurement?
The JSN-SR04T has a measuring range of 20cm to 600cm (2cm to 6 metres). The minimum distance of 20cm means the sensor cannot detect water that comes closer than 20cm to it. Plan your mounting height so that even at maximum flood level, the water surface remains at least 25cm from the sensor. The sensor works reliably outdoors in rain as the probe is IP67 rated.
Q: Can this system work during a power outage?
Yes, if you use a UPS or battery backup. An 18650 dual-cell shield gives approximately 5000-6000 mAh, which can power an ESP32 + sensors for 12-18 hours with 5-minute deep sleep intervals. For longer autonomy, add a small 5W solar panel and MPPT charging circuit. During actual flood emergencies, power outages are common, so battery backup is essential.
Q: How do I calibrate the rain gauge?
Standard tipping bucket rain gauges produce one tip (interrupt pulse) per 0.2794mm of rainfall, but cheap modules from China often use 0.25mm or 0.5mm per tip. Check your module’s datasheet or calibrate manually: pour exactly 100mL of water over the 200cm² collection funnel (= 5mm of rainfall) and count the tips. Adjust your conversion factor accordingly.
Q: Is this suitable for connecting to India Meteorological Department systems?
IMD has a citizen science program and accepts data from AWS (Automatic Weather Stations) that meet their technical specifications. For official integration, you need additional sensors (wind speed/direction, solar radiation) and data transmission to their GPRS-based system. The system described here is more suitable as a local community alert system or for research/educational purposes.
All sensors, ESP32 boards, and power modules needed to build this IoT flood warning system are available at Zbotic.in. We ship fast across India — order today and start protecting your community!
Add comment