Community project

Flood Early-Warning Alarm

Photo of Flood Early-Warning Alarm
Generated with AI

Coolaxc

Last updated November 13, 2026

This flood early-warning alarm uses a water level sensor connected to an Arduino Uno to monitor rising water and alert users before dangerous levels are reached. The system displays three status states with LEDs (green for safe, yellow for warning, red for danger) and triggers an active buzzer when water reaches critical thresholds.

The guide provides a complete wiring diagram showing how to connect the water sensor to the analog input, wire the three status LEDs to digital outputs, and safely drive the buzzer using an NPN transistor with a flyback diode for protection. Assembly involves removing unused components, connecting the sensor directly, installing the status lights, and calibrating the warning thresholds by measuring actual water levels at your installation site. The included firmware handles sensor filtering and hysteresis to prevent false alarms.

Wiring diagram

Wiring diagram for Flood Early-Warning Alarm
Loading diagram…

Gather all the parts

QtyComponent
1

Water Level Sensor

An analog water level sensor module that outputs a voltage proportional to the water level. It uses ten interleaved copper traces and an S8050 NPN transistor to convert water conductivity into an analog voltage signal. The higher the water level, the higher the output voltage. Operates on 3.3V to 5V. To extend sensor lifespan, it is recommended to power the sensor only during readings by controlling the VCC pin via a digital output pin rather than connecting it permanently to 5V.

1

NPN Transistor (2N2222 / BC547)

General-purpose NPN bipolar junction transistor (BJT) in TO-92 package. Used as a low-side switch to drive loads (e.g. buzzers) whose current exceeds ESP32 GPIO source capability (~12 mA). A ~1 kΩ base resistor is placed between the ESP32 GPIO and the transistor base. The collector connects to the load negative terminal (buzzer –), and the emitter connects to GND. When the GPIO goes HIGH (3.3 V), the transistor saturates and switches the load on. Compatible with both 2N2222/2N2222A and BC547/BC547B variants. Add a flyback diode (e.g. 1N4148) across inductive load terminals.

1

5 V two-pin active buzzer, maximum 30 mA

Self-oscillating polarized buzzer; not a passive piezo.

1

Resistor

560 ohm

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

10k ohm

Through-hole resistor (current-limiting in series with an LED)

1

1N4007 flyback diode

Reverse biased across buzzer, not a series power supply. Banded cathode to 5V.

1

LED

green

Standard 3mm/5mm through-hole LED. A current-limiting series resistor is added automatically.

1

Resistor

220 ohm

Through-hole resistor (current-limiting in series with an LED)

1

LED

yellow

Standard 3mm/5mm through-hole LED. A current-limiting series resistor is added automatically.

1

Resistor

220 ohm

Through-hole resistor (current-limiting in series with an LED)

1

LED

red

Standard 3mm/5mm through-hole LED. A current-limiting series resistor is added automatically.

1

Resistor

220 ohm

Through-hole resistor (current-limiting in series with an LED)

Assemble it in 5 steps

1. Remove the unused display and boards

With USB disconnected, remove the seven-segment display and its seven resistors. Remove the LM358, ADS1115, MCP4725, their wiring, five signal-conditioning resistors and two capacitors. Keep the three LEDs and buzzer driver. Do not leave old wires connected to Uno pins.

2. Connect the water sensor directly

Connect sensor + to Uno 5V (power), - to GND (ground), and S to A0 (water reading). All ground connections can share one breadboard ground rail.

  • Keep the header and electronics dry. Only the exposed sensing traces go in water. Disconnect power and rinse and dry the sensor after demonstrations to limit corrosion.

3. Connect the three status lights

Connect D10 through its own 220 ohm resistor to the green LED long leg (anode). Connect D11 through 220 ohms to the yellow long leg, and D12 through 220 ohms to the red long leg. Each short leg (cathode) goes to GND. Only one light is on at a time; green includes a dry sensor.

  • Do not omit the LED resistors; excess current can damage LEDs or the Uno.

4. Keep the safe buzzer driver

Disconnect the base resistor from the removed DAC. Connect D9 through the existing 560 ohm resistor to transistor BASE. Keep the 10k resistor from BASE to GND. Connect EMITTER to GND and COLLECTOR to buzzer minus. Buzzer plus goes to 5V. Keep the diode across the buzzer with its banded cathode at 5V and anode at COLLECTOR. The buzzer pulses only in danger.

  • Check the actual transistor pinout; 2N2222 and BC547 packages can have different leg orders. A reversed transistor can fail or leave the alarm silent.
  • Use the specified 5V active buzzer rated at no more than 30mA. Do not connect it directly to D9.

5. Calibrate and test the warning levels

Secure the sensor vertically. Record filtered serial readings with water at your chosen warning and danger marks. Replace WARNING_COUNTS and DANGER_COUNTS in the firmware with these measurements, keeping danger higher than warning. The example settings 180 and 320 are not calibrated depths. Slowly raise and lower water to verify green, yellow, red and buzzer operation. Hysteresis of 15 counts prevents flickering near a threshold.

  • This is a demonstration, not a life-safety flood alarm. Conductivity, contamination and corrosion change the readings; a disconnected sensor can look dry and show green.

Review all connections

1. Connections between "sensor" and "Arduino"

FunctionsensorArduino
power+5V
ground-GND
analogSGPIO 14

2. Connections between "r_green" and "Arduino"

Functionr_greenArduino
digitalP1GPIO 10
digitalP2 → LED ANODEEXT

3. Connections between "green" and "Arduino"

FunctiongreenArduino
groundGNDGND

4. Connections between "r_yellow" and "Arduino"

Functionr_yellowArduino
digitalP1GPIO 11
digitalP2 → LED ANODEEXT

5. Connections between "yellow" and "Arduino"

FunctionyellowArduino
groundGNDGND

6. Connections between "r_red" and "Arduino"

Functionr_redArduino
digitalP1GPIO 12
digitalP2 → LED ANODEEXT

7. Connections between "red" and "Arduino"

FunctionredArduino
groundGNDGND

8. Connections between "r_base" and "Arduino"

Functionr_baseArduino
digitalP1GPIO 9
digitalP2 → NPN Transistor (2N2222 / BC547) BASEEXT

9. Connections between "r_pulldown" and "Arduino"

Functionr_pulldownArduino
digitalP1 → NPN Transistor (2N2222 / BC547) BASEEXT
groundP2GND

10. Connections between "q1" and "Arduino"

Functionq1Arduino
groundEMITTERGND
digitalCOLLECTOR → 5 V two-pin active buzzer, maximum 30 mA -EXT

11. Connections between "buzzer" and "Arduino"

FunctionbuzzerArduino
power+5V

12. Connections between "flyback" and "Arduino"

FunctionflybackArduino
dataAnode → NPN Transistor (2N2222 / BC547) COLLECTOREXT
powerCathode5V

Deploy the firmware

#include <Arduino.h>
// Demonstration only: conductivity sensors cannot measure flood depth reliably.
constexpr uint8_t GREEN=10, YELLOW=11, RED=12, BUZZER=9;
// Uncalibrated examples in Uno ADC counts (0..1023), NOT millimetres.
// Measure readings at your actual warning/danger water marks and replace these.
constexpr int WARNING_COUNTS=180, DANGER_COUNTS=320, HYSTERESIS=15;
enum State { NORMAL, WARNING, DANGER };
State state=NORMAL;
float filtered=0;
uint32_t lastSample=0,lastPrint=0;
void setup(){
  digitalWrite(BUZZER,LOW); pinMode(BUZZER,OUTPUT);
  pinMode(GREEN,OUTPUT);pinMode(YELLOW,OUTPUT);pinMode(RED,OUTPUT);
  Serial.begin(115200);
  delay(100);
  filtered=analogRead(A0);
  Serial.println(F("DEMO ONLY: calibrate warning/danger counts. raw,filtered,state"));
}
void loop(){
  uint32_t now=millis();
  if(now-lastSample>=50){
    lastSample=now;
    int raw=analogRead(A0);
    filtered+=0.2f*(raw-filtered);
    if(filtered>=DANGER_COUNTS)state=DANGER;
    else if(state==DANGER){
      if(filtered<DANGER_COUNTS-HYSTERESIS)
        state=filtered>=WARNING_COUNTS-HYSTERESIS?WARNING:NORMAL;
    } else if(filtered>=WARNING_COUNTS)state=WARNING;
    else if(filtered<WARNING_COUNTS-HYSTERESIS)state=NORMAL;
    digitalWrite(GREEN,state==NORMAL);
    digitalWrite(YELLOW,state==WARNING);
    digitalWrite(RED,state==DANGER);
    if(now-lastPrint>=500){
      lastPrint=now;Serial.print(raw);Serial.print(',');
      Serial.print(filtered,1);Serial.print(',');
      Serial.println(state==NORMAL?F("LOW"):state==WARNING?F("WARNING"):F("DANGER"));
    }
  }
  digitalWrite(BUZZER,state==DANGER && (now%500)<250);
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik