Projects / Open sump lid alarm

Open sump lid alarm

Beginner1.3 hGuided buildReviewed

Build it step by step

0 of 9 done
  1. NANO12DCLM2596

    Set the buck converter

    Connect the 12 V adapter to the LM2596 only and turn the screw until the output reads 5.0 V.

  2. NANOLM2596

    Wire the 5 V rail

    LM2596 output to the Nano 5V and GND pins, with the Nano unplugged from USB.

  3. NANO

    Wire the reed switch

    One wire to D2 and the other to GND.

  4. NANOON

    Wire the relay

    IN to D7, VCC to 5V and GND to GND.

  5. NANODC

    Wire the siren

    12 V terminal to COM, NO to the siren red wire, siren black wire to the ground terminal.

  6. NANO

    Upload the sketch

    The monitor says Sump lid alarm ready.

  7. NANO

    Hold the magnet to the switch

    The red light stays off and nothing is counted.

  8. NANO

    Take the magnet away and wait

    The light blinks for 20 seconds and then the siren sounds.

  9. NANO

    Put the magnet back

    The siren stops at once.

In short

How do you build an open sump lid alarm?

A magnetic reed switch on a water tank or sump lid sounds a 12 V siren if the lid is left open for more than 20 seconds. Closing the lid stops it, and a cut or loose sensor wire sounds the alarm too, so the alarm fails safe. Protects small children and pets from an open water tank. You need Arduino Nano, Door reed switch MC-38, Buzzer 12 V continuous (piezo alarm), Relay Module 5V, 12 V 2 A DC adapter, DC barrel to screw terminal adapter (female), LM2596 Buck Module, LED 5 mm red, Resistor 220 Ω, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 9 steps and about 75 minutes.

Level
Beginner
Time
About 75 min
Parts
11

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
12 V adapterScrew terminal adapterThe only 12 V supply
Terminal + and -LM2596 IN+ and IN-Set OUT to 5.0 V with no load first
LM2596 OUT+ and OUT-Nano 5V and GNDPowers the Nano and relay board
Reed switch, one wireNano D2Reads closed when the magnet is next to it
Reed switch, other wireNano GNDUses the internal pull-up, no resistor
Relay INNano D7Switches the siren
Relay VCC and GNDNano 5V and GNDRelay coil power
Terminal +Relay COM12 V into the relay switch
Relay NOSiren red wireThe siren sounds only when the relay is on
Siren black wireTerminal -Completes the siren circuit
Red LEDNano D13 through 220 ohms to GNDShows the alarm state at the box

Code

The reed switch has two thin metal contacts in a glass tube that touch when a magnet is close. The magnet is fixed to the lid and the switch to the frame, so with the lid shut the magnet is next to the switch and the pin reads LOW. When the lid lifts, the pin reads HIGH. The pin uses the Nano's built-in pull-up resistor, so the only wiring is the switch between D2 and ground. A very useful side effect is that a broken or unplugged wire also reads HIGH, so a cut cable sounds the alarm instead of silently disabling it. When the lid opens, the sketch remembers the time from millis() and keeps checking. Nothing happens for 20 seconds, which gives an adult time to lift the lid for a quick look, and after that the relay switches the 12 V siren on until the lid is shut. While it is counting, the red light blinks, and when the siren is on it stays lit. The sketch uses millis() rather than delay() so that closing the lid is noticed at once. Most relay boards switch on when their input goes LOW, which is why the code writes LOW to turn the siren on. If your board does the opposite, swap the two. Set the LM2596 to 5.0 V with a multimeter before connecting the Nano. For a real tank, put the Nano, relay and converter in a sealed box away from water, and run the reed switch on a cable. This is an extra layer only. Keep the lid fastened and fenced as well.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

const uint8_t REED = 2;                  // to GND: LOW means the magnet is near, lid shut
const uint8_t RELAY = 7;                 // relay board input, active LOW on most modules
const uint8_t LED = 13;
const unsigned long OPEN_DELAY = 20000;  // lid must stay open this long before the siren starts

unsigned long openSince = 0;
bool counting = false;
bool sirenOn = false;

void setSiren(bool on) {
  sirenOn = on;
  digitalWrite(RELAY, on ? LOW : HIGH);  // most relay boards switch on with LOW
  digitalWrite(LED, on ? HIGH : LOW);
}

void setup() {
  pinMode(REED, INPUT_PULLUP);
  pinMode(RELAY, OUTPUT);
  pinMode(LED, OUTPUT);
  setSiren(false);
  Serial.begin(9600);
  Serial.println(F("Sump lid alarm ready"));
}

void loop() {
  bool lidShut = (digitalRead(REED) == LOW);   // a cut wire also reads HIGH, so it counts as open

  if (lidShut) {
    if (counting || sirenOn) Serial.println(F("Lid closed"));
    counting = false;
    if (sirenOn) setSiren(false);
  } else {
    if (!counting) {
      counting = true;
      openSince = millis();
      Serial.println(F("Lid open, counting 20 s"));
    }
    if (!sirenOn && millis() - openSince >= OPEN_DELAY) {
      setSiren(true);
      Serial.println(F("ALARM: lid left open"));
    }
    digitalWrite(LED, (millis() / 500) % 2);   // blink while counting
    if (sirenOn) digitalWrite(LED, HIGH);
  }
  delay(20);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

Sump lid alarm ready
Lid open, counting 20 s

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Magnet next to the switchQuiet, light off
Magnet away for 10 secondsLight blinks, no siren yet
Magnet away for 25 secondsSiren sounds and the light stays on
Magnet back during the sirenSiren stops and the monitor says Lid closed
Unplug the reed switch wireThe 20 second timer starts and the siren sounds after it

If it does not work

Siren is on all the time

Your relay board switches on with HIGH, so swap the HIGH and LOW in setSiren().

Siren never sounds

Check the siren is wired to COM and NO, and that the 12 V adapter is plugged in.

Alarm starts with the lid shut

The magnet is too far from the switch, so bring them within a centimetre.

Nano resets when the siren starts

Keep the 5 V converter wires away from the siren wires and add a 100 uF capacitor across the Nano power.

Upload fails

Choose the Old Bootloader option for the Nano.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the open sump lid alarm?

Arduino Nano, Door reed switch MC-38, Buzzer 12 V continuous (piezo alarm), Relay Module 5V, 12 V 2 A DC adapter, DC barrel to screw terminal adapter (female), LM2596 Buck Module, LED 5 mm red, Resistor 220 Ω, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the open sump lid alarm take to build?

About 75 minutes for a beginner maker, in 9 steps.

How do I know the open sump lid alarm works?

Magnet next to the switch: Quiet, light off. Magnet away for 10 seconds: Light blinks, no siren yet. Magnet away for 25 seconds: Siren sounds and the light stays on.

Siren is on all the time: what should I check?

Your relay board switches on with HIGH, so swap the HIGH and LOW in setSiren().

Siren never sounds: what should I check?

Check the siren is wired to COM and NO, and that the 12 V adapter is plugged in.

Alarm starts with the lid shut: what should I check?

The magnet is too far from the switch, so bring them within a centimetre.

Nano resets when the siren starts: what should I check?

Keep the 5 V converter wires away from the siren wires and add a 100 uF capacitor across the Nano power.