ESP8266 Flood Monitoring System Using Water Level Sensor, Rain Sensor & KiwisIoT

by ananthi rk in Circuits > Sensors

23 Views, 0 Favorites, 0 Comments

ESP8266 Flood Monitoring System Using Water Level Sensor, Rain Sensor & KiwisIoT

flood_monitoring_6x5_no_crop.png
  1. Flooding is a serious environmental problem that can affect residential areas, agricultural fields, roads, and other infrastructure. Heavy rainfall and rising water levels can create dangerous situations, especially in locations where continuous monitoring is difficult.
  2. An IoT-based flood monitoring system provides a simple way to observe water levels and rainfall conditions remotely. By combining sensors, a Wi-Fi-enabled microcontroller, and a cloud dashboard, sensor information can be collected and viewed without being physically present near the monitoring location.
  3. In this project, we are building an ESP8266-based Flood Monitoring System using a water level sensor, a rain sensor module, and the KiwisIoT platform.
  4. The water level sensor measures the water level and provides an analog reading. The rain sensor detects the presence of water droplets on its sensing plate. The NodeMCU ESP8266 processes these readings and sends the information to the KiwisIoT dashboard using a Wi-Fi connection.
  5. The dashboard displays the water sensor value, rain status, water level classification, and flood warning status.
  6. The circuit is assembled using direct jumper wire connections without a breadboard, making it a simple and affordable project for students, beginners, and IoT enthusiasts.

Project Features

  1. Real-time water level monitoring.
  2. Rain detection using a digital rain sensor output.
  3. Three water level categories: LOW, MEDIUM, and HIGH.
  4. Three flood status categories: SAFE, WARNING, and DANGER.
  5. Wireless monitoring through the KiwisIoT dashboard.
  6. Automatic sensor reading and cloud data publishing every five seconds.
  7. Simple hardware setup without a breadboard.

How the System Works

  1. The water level sensor continuously provides an analog signal to the NodeMCU. The rain sensor provides a digital signal indicating whether rain is detected.
  2. The ESP8266 reads both sensors and compares the water sensor reading with predefined thresholds.
  3. If the water reading is below the warning threshold and no rain is detected, the system reports SAFE.
  4. If the water reading reaches the warning threshold or rain is detected, the system reports WARNING.
  5. If the water reading reaches the danger threshold, the system reports DANGER.
  6. The ESP8266 sends these values to KiwisIoT, where they are displayed through dashboard widgets.

Supplies

Components Required

The following hardware and software components are required for this project.


| No. | Component | Quantity | Purpose |
| --- | --------------------------------- | ----------- | --------------------------------------- |
| 1 | NodeMCU ESP8266 ESP-12E | 1 | Main controller and Wi-Fi communication |
| 2 | Water Level Sensor | 1 | Measures water level |
| 3 | Rain Sensor Module with DO output | 1 | Detects rain or water droplets |
| 4 | Female-to-Female Jumper Wires | As required | Connects sensors to NodeMCU |
| 5 | USB Data Cable | 1 | Programming and power |
| 6 | Computer or Laptop | 1 | Arduino programming |

A breadboard is not required. The sensor connections are made directly to the NodeMCU using jumper wires.

Software Requirements

  1. Arduino IDE installed on the computer.
  2. ESP8266 board package installed in Arduino IDE.
  3. KiwisIoT library.
  4. Arduino library.
  5. Wi-Fi network or mobile hotspot with internet access.

The NodeMCU connects to the Wi-Fi network and uses the KiwisIoT library to send sensor readings to the cloud dashboard.

A breadboard is not required. The sensor connections are made directly to the NodeMCU using jumper wires.


Circuit Connections

circuit_image (2).png

Circuit Diagram and Wiring

  1. The circuit is assembled by connecting the sensor pins directly to the NodeMCU using jumper wires.
  2. No breadboard is required.

Water Level Sensor Connections

| Water Level Sensor Pin | NodeMCU Pin |
| -------------------------- | ----------- |
| S / Signal / Analog Output | A0 |
| VCC / + | 3V3 |
| GND / - | GND |

The signal pin sends the analog water level reading to A0.

Rain Sensor Connections

| Rain Sensor Module Pin | NodeMCU Pin |
| ---------------------- | ----------- |
| DO (Digital Output) | D5 (GPIO14) |
| VCC | 3V3 |
| GND | GND |

The analog output AO of the rain sensor is not used in this project.

Wiring Explanation

  1. The VCC connections supply power to the sensors. The GND connections provide a common ground reference between the sensors and the NodeMCU.
  2. The water level sensor uses the analog input A0, while the rain sensor uses the digital input D5.
  3. Check the pin labels on your actual sensor modules before making the connections, as pin arrangements can vary between manufacturers.

Important Electrical Safety

  1. The ESP8266 GPIO pins are designed for 3.3V logic and are not 5V tolerant.
  2. Verify the maximum input voltage supported by your particular NodeMCU A0 pin. Some NodeMCU development boards include an onboard voltage divider, while a bare ESP8266 ADC input has a lower voltage limit.
  3. Do not connect a sensor's 5V analog or digital output directly to an ESP8266 input unless the signal is properly voltage-limited.
  4. Keep the NodeMCU and other non-waterproof electronics away from the water during testing.

Installing Arduino IDE and KiwisIoT Library

Installing Arduino IDE

Arduino IDE is used to write, compile, and upload the program to the NodeMCU ESP8266.

  1. Download Arduino IDE from the official Arduino website.
  2. Install it on your computer.
  3. Open Arduino IDE.
  4. Open File → Preferences.
  5. Add the ESP8266 Boards Manager URL if it is not already configured.
  6. Open Tools → Board → Boards Manager.
  7. Search for ESP8266 and install the ESP8266 platform.
  8. Connect the NodeMCU to the computer using a USB data cable.
  9. Select Tools → Board → ESP8266 Boards → NodeMCU 1.0 (ESP-12E Module).
  10. Select the appropriate COM port under Tools → Port.

If the COM port does not appear, check the USB cable and install the appropriate USB-to-serial driver for your board.

Installing the KiwisIoT Library

The KiwisIoT library is used to connect the ESP8266 to the cloud dashboard.

  1. Open Arduino IDE.
  2. Select Sketch → Include Library → Manage Libraries.
  3. Search for the KiwisIoT library.
  4. Install the library if it is listed.
  5. If it is not listed, follow the installation instructions provided with the official KiwisIoT library.

After installation, the code can include the KiwisIoT header file:

#include <KiwisIoT.h>

This library provides the functions required to initialize the connection, maintain communication, and send values to the dashboard.

KiwisIoT Dashboard Setup

KiwisloIT_832x551.png
Screenshot_832x551(2).png
ChatGPT Image Sep 28, 2026, 08_17_11 PM.png
ChatGPT Image Sep 28, 2026, 08_18_46 PM.png
ChatGPT Image Sep 28, 2026, 11_03_10 PM.png
ChatGPT Image Sep 28, 2026, 10_32_52 PM.png

KiwisIoT Dashboard Setup

KiwisIoT is used to receive and display the sensor information sent by the ESP8266.

Create a Dashboard or Topic

  1. Open the KiwisIoT website.
  2. Log in to your account. https://kiwisiot.in/login
  3. Create a new dashboard or topic for the flood monitoring project.
  4. Give the project a suitable name, such as ESP8266 Flood Monitoring.
  5. Copy the Topic ID associated with the dashboard.

The Topic ID is used by the ESP8266 to identify the destination for the sensor data.

Keep the Topic ID private if your dashboard uses it as an access credential.

Configure Dashboard Channels

The Arduino code sends four data values using the following channel IDs.

| Channel ID | Variable | Data Type | Suggested Widget |
| ---------- | ------------------ | --------- | ------------------------ |
| 0 | Water Sensor Value | Numeric | Gauge or Numeric Display |
| 1 | Rain Status | Text | Text Display |
| 2 | Flood Status | Text | Text Display |
| 3 | Water Level | Text | Text Display |

The channel IDs configured in the dashboard must match the IDs used in the Arduino code.

Channel 0 – Water Sensor Value

This channel displays the raw analog value received from the water level sensor.

A gauge or numeric widget can be used to display the reading.

Channel 1 – Rain Status

This channel displays the rain sensor status.

Possible values:

  1. RAIN DETECTED
  2. NO RAIN

Channel 2 – Flood Status

This channel displays the current flood warning category.

Possible values:

  1. SAFE
  2. WARNING
  3. DANGER

Channel 3 – Water Level

This channel displays the water level classification.

Possible values:

  1. LOW
  2. MEDIUM
  3. HIGH

Once the dashboard is configured, the ESP8266 can send values to the corresponding widgets.

Complete Arduino Code

Arduino Program

#include <ESP8266WiFi.h>
#include <KiwisIoT.h>

// Wi-Fi Settings
const char* ssid = "YOUR_WIFI_NAME";
const char* pass = "YOUR_WIFI_PASSWORD";

// KiwisIoT Topic ID
const char* topic = "YOUR_TOPIC_ID";

// KiwisIoT Object
KiwisIoT kiwisiot(ssid, pass, topic);

// Sensor Pins
#define WATER_PIN A0
#define RAIN_PIN D5

// Water Level Thresholds
int waterWarningThreshold = 400;
int waterDangerThreshold = 700;

// Rain Sensor Logic
#define RAIN_DETECTED LOW

// Variables
int waterValue = 0;
int rainValue = HIGH;

String waterLevel;
String rainStatus;
String floodStatus;

unsigned long previousMillis = 0;
const unsigned long interval = 5000;

// Setup
void setup() {
Serial.begin(115200);

pinMode(RAIN_PIN, INPUT);

Serial.println();
Serial.println("ESP8266 Flood Monitoring");

kiwisiot.begin();

Serial.println("KiwisIoT Started");
}

// Read Sensors
void readSensors() {

waterValue = analogRead(WATER_PIN);
rainValue = digitalRead(RAIN_PIN);

if (waterValue < waterWarningThreshold) {
waterLevel = "LOW";
}
else if (waterValue < waterDangerThreshold) {
waterLevel = "MEDIUM";
}
else {
waterLevel = "HIGH";
}

if (rainValue == RAIN_DETECTED) {
rainStatus = "RAIN DETECTED";
}
else {
rainStatus = "NO RAIN";
}

if (waterValue >= waterDangerThreshold) {
floodStatus = "DANGER";
}
else if (waterValue >= waterWarningThreshold ||
rainValue == RAIN_DETECTED) {
floodStatus = "WARNING";
}
else {
floodStatus = "SAFE";
}
}

// Display Readings
void displayReadings() {

Serial.println("----------------------");

Serial.print("Water Value: ");
Serial.println(waterValue);

Serial.print("Water Level: ");
Serial.println(waterLevel);

Serial.print("Rain Status: ");
Serial.println(rainStatus);

Serial.print("Flood Status: ");
Serial.println(floodStatus);

Serial.println("----------------------");
}

// Publish Data
void publishData() {

kiwisiot.send("0", waterValue);
kiwisiot.send("1", rainStatus);
kiwisiot.send("2", floodStatus);
kiwisiot.send("3", waterLevel);

Serial.println("Data sent to KiwisIoT");
}

// Main Loop
void loop() {

kiwisiot.run();

if (millis() - previousMillis >= interval) {

previousMillis = millis();

readSensors();

displayReadings();

publishData();
}
}

Code Configuration

Replace the following three lines with your own Wi-Fi and dashboard details:

const char* ssid = "YOUR_WIFI_NAME";
const char* pass = "YOUR_WIFI_PASSWORD";
const char* topic = "YOUR_TOPIC_ID";

Do not publish your Wi-Fi password or private credentials in your public project article.

Uploading the Program

  1. Connect the NodeMCU to your computer.
  2. Open the code in Arduino IDE.
  3. Enter the Wi-Fi credentials and Topic ID.
  4. Select NodeMCU 1.0 (ESP-12E Module).
  5. Select the correct COM port.
  6. Click the Upload button.
  7. Wait until the IDE displays the upload completion message.
  8. Open Serial Monitor and select 115200 baud.

The ESP8266 will start reading the sensors and sending the data to KiwisIoT.

Understanding the Program

Program Explanation

1. Library Inclusion

#include <ESP8266WiFi.h>
#include <KiwisIoT.h>

The ESP8266WiFi library supports Wi-Fi communication on the ESP8266. The KiwisIoT library provides the dashboard communication functions.

2. Sensor Pin Definitions

#define WATER_PIN A0
#define RAIN_PIN D5

The water level sensor is connected to A0. The rain sensor digital output is connected to D5.

3. Reading the Sensors

waterValue = analogRead(WATER_PIN);
rainValue = digitalRead(RAIN_PIN);

The analogRead() function reads the water sensor value, while digitalRead() reads the rain sensor's digital output.

The water reading is used to classify the water level.

4. Water Level Classification

if (waterValue < 400) {
waterLevel = "LOW";
}
else if (waterValue < 700) {
waterLevel = "MEDIUM";
}
else {
waterLevel = "HIGH";
}

This section divides the analog reading into three categories.

Values below 400 are classified as LOW. Values from 400 to 699 are classified as MEDIUM. Values of 700 and above are classified as HIGH.

These thresholds are examples and should be adjusted based on actual sensor readings.

5. Rain Detection

if (rainValue == LOW) {
rainStatus = "RAIN DETECTED";
}
else {
rainStatus = "NO RAIN";
}

The program assumes that the rain sensor digital output becomes LOW when rain is detected.

The output logic may differ depending on the rain sensor module and its configuration.

6. Flood Warning Logic

The flood status is calculated using both water level and rain detection.

If the water reading is 700 or higher, the system reports DANGER.

If the water reading is at least 400 or rain is detected, the system reports WARNING.

Otherwise, the system reports SAFE.

This is a basic demonstration of sensor-based warning logic and is not a substitute for an official flood warning system.

7. Sending Data to KiwisIoT

kiwisiot.send("0", waterValue);
kiwisiot.send("1", rainStatus);
kiwisiot.send("2", floodStatus);
kiwisiot.send("3", waterLevel);

Each send() statement publishes a value to the corresponding dashboard channel.

The kiwisiot.run() function is called repeatedly in the main loop to maintain the KiwisIoT communication process.

8. Automatic Data Publishing

const unsigned long interval = 5000;

The interval is set to 5000 milliseconds, which is five seconds.

The millis() function is used to determine when the next sensor reading should be taken and published.

This allows the system to update the dashboard periodically without using a long delay in the main loop.

Testing

Screenshot_832x551(1) (1).png
Screenshot_2241_832x551.png

Step 8: Testing the Water Level and Rain Sensors

After uploading the Arduino code, both sensors are tested to verify their readings and confirm that the data is displayed correctly on the KiwisIoT dashboard.

Testing Procedure

  1. Keep the NodeMCU and all electronic connections away from water.
  2. Connect the NodeMCU to the computer and open the Serial Monitor at 115200 baud.
  3. Observe the initial water sensor value and rain status when both sensors are dry.
  4. Gradually expose the water level sensor's sensing area to water and observe how the analog reading changes.
  5. Compare the water sensor reading with the configured thresholds of 400 and 700.
  6. Carefully place a few water droplets on the rain sensor's sensing plate.
  7. Check whether the rain status changes to RAIN DETECTED.
  8. Open the KiwisIoT dashboard and verify that the water sensor value, water level, rain status, and flood status are updated.

Expected Results

Test Condition Expected Output
Water level below 400 and no rain LOW / SAFE
Water level between 400 and 699 MEDIUM / WARNING
Water level 700 or above HIGH / DANGER
Rain detected and water level below 700 RAIN DETECTED / WARNING
Rain sensor dry NO RAIN

The water sensor thresholds are example values and should be calibrated according to the actual sensor readings. The rain sensor's output logic may vary depending on the module.

Result

Both sensors were tested successfully. The NodeMCU read the water level and rain sensor values, processed the readings, and sent the results to the KiwisIoT dashboard through Wi-Fi.

The dashboard displayed the sensor readings and corresponding water level and flood status, demonstrating the working of the IoT-based flood monitoring system.

KiwisIoT Dashboard Output

ChatGPT Image Sep 28, 2026, 11_01_35 PM.png
ChatGPT Image Sep 28, 2026, 11_32_23 PM.png

Live Dashboard Monitoring

Once the ESP8266 connects to Wi-Fi and starts publishing data, the KiwisIoT dashboard receives the sensor readings.

The dashboard provides a remote view of the monitoring system.

Water Sensor Value

The water sensor value widget displays the raw analog reading received from A0.

This value changes according to the water detected by the sensor.

Rain Status

The rain status widget displays whether the rain sensor has detected water droplets.

The displayed text is either RAIN DETECTED or NO RAIN.

Water Level

The water level widget displays LOW, MEDIUM, or HIGH based on the programmed thresholds.

Flood Status

The flood status widget displays SAFE, WARNING, or DANGER.

The status is determined by the water sensor reading and rain detection logic.

Observed Project Results

During testing, the NodeMCU read the water level sensor and rain sensor values and sent them to the KiwisIoT dashboard.

The dashboard successfully displayed the sensor values and status information.

The system demonstrated wireless monitoring of water level and rainfall conditions using an ESP8266 and KiwisIoT.

The displayed values depend on the actual sensor readings and the thresholds configured in the code.

Troubleshooting

Troubleshooting Guide

Problem 1: NodeMCU Is Not Detected

Possible causes:

  1. USB cable supports charging only.
  2. Incorrect USB-to-serial driver.
  3. Incorrect COM port selected.

Solutions:

Use a USB data cable, verify the device in Device Manager, and select the correct COM port in Arduino IDE.

Problem 2: Water Sensor Always Shows LOW

Possible causes:

  1. Incorrect wiring to A0.
  2. Sensor is not making proper contact with water.
  3. Thresholds are not calibrated.
  4. Sensor is not receiving power.

Solutions:

Check the sensor connections, observe raw analog readings in Serial Monitor, and adjust the warning and danger thresholds according to actual measurements.

Problem 3: Rain Status Is Reversed

Possible cause:

The rain sensor module may use the opposite digital output logic.

Solution:

If the module outputs HIGH when rain is detected, change:

#define RAIN_DETECTED LOW

to:

#define RAIN_DETECTED HIGH

Test the sensor again to verify the logic.

Problem 4: Data Is Not Appearing on KiwisIoT

Possible causes:

  1. Incorrect Wi-Fi credentials.
  2. Incorrect Topic ID.
  3. Dashboard channel IDs do not match the code.
  4. Wi-Fi or internet connection is unavailable.
  5. KiwisIoT library is not installed correctly.

Solutions:

Check the Wi-Fi connection, verify the Topic ID, confirm the dashboard channel configuration, and inspect the Serial Monitor for errors.

Start by checking the numeric water sensor channel before troubleshooting the text channels.

Problem 5: Analog Readings Are Unstable

Possible causes:

  1. Sensor placement.
  2. Loose jumper wires.
  3. Electrical noise.
  4. Water droplets or corrosion on the sensing area.

Solutions:

Secure the connections, keep the sensor stable during testing, clean and dry the sensing surface when appropriate, and repeat the calibration.

Problem 6: ESP8266 Keeps Restarting

Possible causes:

  1. Unstable USB power supply.
  2. Loose wiring.
  3. Electrical short circuits.
  4. Incorrect voltage supplied to the board.

Solutions:

Disconnect the sensors and test the NodeMCU separately. Reconnect the sensors after confirming stable operation. Never expose the electronics to water during testing.

Applications

Applications

This project can be used as a foundation for several IoT monitoring applications.

1. Water Storage Monitoring

The sensor can be used to demonstrate water level monitoring in small containers or storage tanks, subject to sensor suitability and calibration.

2. Educational Flood Monitoring

Students can use the project to understand how environmental sensors and cloud dashboards can work together to monitor changing conditions.

3. Smart Agriculture

The rain sensor and water level sensor can be incorporated into an educational smart agriculture prototype for observing rainfall and water accumulation.

4. Environmental Monitoring

The system demonstrates how remote sensor monitoring can be used in environmental data collection projects.

5. IoT Learning Projects

The project helps beginners learn ESP8266 programming, analog and digital sensor interfacing, Wi-Fi connectivity, cloud dashboards, and basic condition-based alerts.

Conclusion

Conclusion

  1. In this project, we successfully developed an IoT-based Flood Monitoring System using a NodeMCU ESP8266, water level sensor, rain sensor module, and KiwisIoT dashboard.
  2. The system reads the water level and rainfall conditions, classifies the sensor readings into different categories, and publishes the information to the cloud dashboard through Wi-Fi.
  3. The project demonstrates how affordable sensors and a Wi-Fi-enabled microcontroller can be used to build a simple remote environmental monitoring prototype.
  4. By adding additional features such as mobile notifications, data logging, backup power, and improved sensor calibration, the system can be further developed into a more advanced IoT monitoring project.
  5. This project is suitable for students, beginners, and electronics enthusiasts interested in learning IoT, sensor interfacing, ESP8266 programming, and cloud dashboard integration.

Project Result: The ESP8266 Flood Monitoring System was tested, and sensor data was successfully displayed on the KiwisIoT dashboard.

Thank you for reading this project! Feel free to share your feedback, suggestions, and improvements in the comments.