Community project

Flood Early-Warning Alarm

Photo of Flood Early-Warning Alarm
Generated with AI

Coolaxc

Published November 12, 2026

This flood early-warning alarm detects rising water levels using a capacitive sensor and alerts users with visual and audible warnings. The system conditions the sensor signal through an operational amplifier circuit, displays water depth on a seven-segment display, and triggers a buzzer and status LEDs when water reaches warning and danger thresholds.

Builders will receive a complete wiring diagram, parts list, calibration procedure, and Arduino firmware with moving-average filtering for stable readings. The guide covers constructing the analog signal conditioning stage, building the buzzer driver circuit with flyback protection, connecting the display and indicator LEDs, and calibrating the sensor across a known water depth range for accurate measurements.

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

LM358 Dual Operational Amplifier

Dual op-amp in 8-pin DIP (or breakout module exposing the same pinout via headers). Operates from a 3–32 V single supply (or ±1.5 V to ±16 V dual supply); output swings near GND on the low side and to about VCC−1.5 V on the high side. The breakout-module form factor shares the same pinout as the bare LM358 DIP-8.

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

5161AS common-cathode display

Front view decimal point lower right: pin 1 bottom left; 1=e,2=d,3=CC,4=c,5=DP,6=b,7=a,8=CC,9=f,10=g. DP unused.

1

Resistor

10k 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

Resistor

2.2k 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

Resistor

10k ohm

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

1

Resistor

1k ohm

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

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

10uF 16V electrolytic capacitor

10uF 16V

Polarized filter capacitor. Positive to signal; negative to ground.

1

10uF 16V electrolytic capacitor

10uF 16V

Polarized filter capacitor. Positive to signal; negative to ground.

1

Ceramic Capacitor

100nF (104)

Through-hole ceramic capacitor bought by value, such as 22 pF, 10 nF or 100 nF (0.1 µF). It is non-polarised, so either lead can go to either net. Its most common job is decoupling: a 100 nF capacitor between an IC's supply pin and ground, placed as close to the chip as possible.

1

Resistor

220 ohm

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

1

Resistor

220 ohm

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

1

Resistor

220 ohm

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

1

Resistor

220 ohm

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

1

Resistor

220 ohm

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

1

Resistor

220 ohm

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

1

Resistor

220 ohm

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

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 6 steps

1. Prepare the dry electronics area

Keep the Uno and breadboard above the tray in a larger catch tub. Disconnect USB before wiring. Use the Uno 5V and GND rails; join every ground.

  • Educational model only; never rely on this to protect people or property.

2. Build the sensor conditioner

Sensor + to 5V, - to GND. Signal passes through 10k to LM358 pin 3, with another 10k from pin 3 to GND. Pin 1 connects through 2.2k to pin 2; pin 2 connects through 10k to GND. Pin 1 then passes through 10k to A0. Connect sensor filter 10uF positive to A0, negative to GND. LM358 pin 8 to 5V, pin 4 to GND, 104 capacitor across pins 8 and 4.

  • DIP pins count counterclockwise from the notch; pin 1 is upper left with notch at top.
  • Sensor remains powered so the slow filter can settle; remove power and rinse/dry after demonstrations.

3. Build the DAC and buzzer driver

D9 through 1k to LM358 pin 5. Connect DAC 10uF positive to pin 5 and negative to GND. Join pins 7 and 6. Pin 7 through 560 ohms to transistor base; base through 10k to GND. Emitter to GND, collector to buzzer minus, buzzer plus to 5V. Diode banded cathode to 5V, anode to collector.

  • Check the actual transistor manufacturer pinout; 2N2222 variants are not all ordered alike.
  • Electrolytic negative stripe must face GND; reversed capacitors can fail.

4. Connect the seven segment display

5161AS front faces you, decimal point bottom right: bottom row left to right pins 1 to 5, top row left to right 10 to 6. Wire D2 through 220 ohms to pin 7 (a), D3 to pin 6 (b), D4 to pin 4 (c), D5 to pin 2 (d), D6 to pin 1 (e), D7 to pin 9 (f), D8 to pin 10 (g), each through its own 220 ohm resistor. Pins 3 and 8 to GND. Pin 5 decimal point unused.

5. Connect the status LEDs

D10 through 220 ohms to green anode, D11 through 220 ohms to yellow anode, D12 through 220 ohms to red anode. Each short cathode leg goes to GND.

6. Mark and calibrate the tray

Mount only the exposed sensor traces vertically in water, keeping its header dry. Mark depths 0 to 40mm in 5mm steps with a ruler. After filling each mark slowly, wait at least 2 seconds for settling. Record average ADC counts from serial output and replace the nine placeholder calibration values in firmware. Verify all values strictly increase.

  • Calibration is essential; displayed depths and alarm thresholds are not valid with the placeholder table.

Review all connections

1. Connections between "sensor" and "Arduino"

FunctionsensorArduino
power+5V
ground-GND

2. Connections between "opamp" and "Arduino"

FunctionopampArduino
powerVCC5V
groundGNDGND
analogOUT_B → LM358 Dual Operational Amplifier IN-_BEXT

3. Connections between "r_div_top" and "Arduino"

Functionr_div_topArduino
digitalP1 → Water Level Sensor SEXT
digitalP2 → LM358 Dual Operational Amplifier IN+_AEXT

4. Connections between "r_div_bottom" and "Arduino"

Functionr_div_bottomArduino
digitalP1 → LM358 Dual Operational Amplifier IN+_AEXT
groundP2GND

5. Connections between "r_feedback" and "Arduino"

Functionr_feedbackArduino
digitalP1 → LM358 Dual Operational Amplifier OUT_AEXT
digitalP2 → LM358 Dual Operational Amplifier IN-_AEXT

6. Connections between "r_gain" and "Arduino"

Functionr_gainArduino
digitalP1 → LM358 Dual Operational Amplifier IN-_AEXT
groundP2GND

7. Connections between "r_sensor_filter" and "Arduino"

Functionr_sensor_filterArduino
digitalP1 → LM358 Dual Operational Amplifier OUT_AEXT
digitalP2GPIO 14

8. Connections between "r_dac_filter" and "Arduino"

Functionr_dac_filterArduino
digitalP1GPIO 9
digitalP2 → LM358 Dual Operational Amplifier IN+_BEXT

9. Connections between "r_base" and "Arduino"

Functionr_baseArduino
digitalP1 → LM358 Dual Operational Amplifier OUT_BEXT
digitalP2 → NPN Transistor (2N2222 / BC547) BASEEXT

10. Connections between "r_pulldown" and "Arduino"

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

11. Connections between "q1" and "Arduino"

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

12. Connections between "buzzer" and "Arduino"

FunctionbuzzerArduino
power+5V

13. Connections between "flyback" and "Arduino"

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

14. Connections between "c_sensor" and "Arduino"

Functionc_sensorArduino
power+ → Resistor P2EXT
ground-GND

15. Connections between "c_dac" and "Arduino"

Functionc_dacArduino
power+ → LM358 Dual Operational Amplifier IN+_BEXT
ground-GND

16. Connections between "c_supply" and "Arduino"

Functionc_supplyArduino
digital1 → LM358 Dual Operational Amplifier VCCEXT
ground2GND

17. Connections between "r_seg_a" and "Arduino"

Functionr_seg_aArduino
digitalP1GPIO 2
digitalP2 → 5161AS common-cathode display aEXT

18. Connections between "r_seg_b" and "Arduino"

Functionr_seg_bArduino
digitalP1GPIO 3
digitalP2 → 5161AS common-cathode display bEXT

19. Connections between "r_seg_c" and "Arduino"

Functionr_seg_cArduino
digitalP1GPIO 4
digitalP2 → 5161AS common-cathode display cEXT

20. Connections between "r_seg_d" and "Arduino"

Functionr_seg_dArduino
digitalP1GPIO 5
digitalP2 → 5161AS common-cathode display dEXT

21. Connections between "r_seg_e" and "Arduino"

Functionr_seg_eArduino
digitalP1GPIO 6
digitalP2 → 5161AS common-cathode display eEXT

22. Connections between "r_seg_f" and "Arduino"

Functionr_seg_fArduino
digitalP1GPIO 7
digitalP2 → 5161AS common-cathode display fEXT

23. Connections between "r_seg_g" and "Arduino"

Functionr_seg_gArduino
digitalP1GPIO 8
digitalP2 → 5161AS common-cathode display gEXT

24. Connections between "display" and "Arduino"

FunctiondisplayArduino
groundCC3GND
groundCC8GND

25. Connections between "r_green" and "Arduino"

Functionr_greenArduino
digitalP1GPIO 10
digitalP2 → LED ANODEEXT

26. Connections between "green" and "Arduino"

FunctiongreenArduino
groundGNDGND

27. Connections between "r_yellow" and "Arduino"

Functionr_yellowArduino
digitalP1GPIO 11
digitalP2 → LED ANODEEXT

28. Connections between "yellow" and "Arduino"

FunctionyellowArduino
groundGNDGND

29. Connections between "r_red" and "Arduino"

Functionr_redArduino
digitalP1GPIO 12
digitalP2 → LED ANODEEXT

30. Connections between "red" and "Arduino"

FunctionredArduino
groundGNDGND

Deploy the firmware

#include <Arduino.h>
// Flood demonstration only, not a life-safety instrument.
constexpr uint8_t SENSOR=A0, DAC=9, GREEN=10, YELLOW=11, RED=12;
constexpr uint8_t segments[]={2,3,4,5,6,7,8}; // a b c d e f g
constexpr uint8_t digits[]={0x3f,0x06,0x5b,0x4f,0x66};
// PLACEHOLDERS: replace with measured A0 counts at 0,5,...40 mm.
// Old raw sensor endpoints 30..470 do NOT apply through this circuit.
constexpr uint16_t cal[]={18,52,85,119,153,186,220,253,287};
constexpr float depths[]={0,5,10,15,20,25,30,35,40};
enum State { NORMAL, WARNING, DANGER };
State state=NORMAL;
uint16_t samples[10]; uint32_t sum=0; uint8_t idx=0;
uint32_t lastSample=0,lastPrint=0; float mm=0; uint16_t raw=0;
float depth(float adc) {
  if(adc<=cal[0]) return 0;
  for(uint8_t i=1;i<9;i++) if(adc<=cal[i])
    return depths[i-1]+(adc-cal[i-1])*(depths[i]-depths[i-1])/(cal[i]-cal[i-1]);
  return 40;
}
void show(uint8_t level) {
  static uint8_t previous=255;
  if(previous==level)return;
  previous=level;
  for(uint8_t i=0;i<7;i++)digitalWrite(segments[i],(digits[level]>>i)&1);
}
void setup(){
  pinMode(DAC,OUTPUT);analogWrite(DAC,0);
  pinMode(GREEN,OUTPUT);pinMode(YELLOW,OUTPUT);pinMode(RED,OUTPUT);
  for(uint8_t p:segments)pinMode(p,OUTPUT);
  Serial.begin(115200);
  Serial.println(F("DEMO: UNCALIBRATED table. raw,average,mm,state,display"));
  // Allow both analog filters to settle; sensor stays powered during demo.
  delay(1000);
  raw=analogRead(SENSOR);
  for(uint8_t i=0;i<10;i++)samples[i]=raw;
  sum=10UL*raw;lastSample=millis();
}
void loop(){
  uint32_t now=millis();
  if(now-lastSample>=20){ // 50 Hz; no tone(), which can interfere with PWM
    lastSample=now;raw=analogRead(SENSOR);
    sum-=samples[idx];samples[idx]=raw;sum+=raw;idx=(idx+1)%10;
    mm=depth(sum/10.0f);
    // Entry at 10/25 mm, release at 8/23 mm.
    if(mm>=25)state=DANGER;
    else if(state==DANGER){if(mm<23)state=(mm>=8?WARNING:NORMAL);}
    else if(mm>=10)state=WARNING;
    else if(mm<8)state=NORMAL;
  }
  uint8_t level=mm<1?0:mm<10?1:mm<20?2:mm<25?3:4;
  show(level);
  bool pulse=(now%200)<100; // 5 Hz pulse envelope
  digitalWrite(GREEN,level>0 && state==NORMAL);
  digitalWrite(YELLOW,state==WARNING);
  digitalWrite(RED,state==DANGER && pulse);
  // 8-bit PWM DAC: 128/255 * 5V ~=2.51V. RC + LM358B -> NPN.
  // Only danger drives buzzer; other states command zero volts.
  analogWrite(DAC,state==DANGER && pulse?128:0);
  if(now-lastPrint>=500){
    lastPrint=now;Serial.print(raw);Serial.print(',');Serial.print(sum/10.0f,1);
    Serial.print(',');Serial.print(mm,1);Serial.print(',');Serial.print((int)state);
    Serial.print(',');Serial.println(level);
  }
}

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