Projects / Fridge door left-open beeper

Fridge door left-open beeper

A magnet and reed switch on a fridge door sound a beeper if the door stays open more than a minute.

Beginner1.3 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANO

    Wire the reed switch

    One side to D2, the other to GND.

  2. NANO

    Wire the buzzer

    Plus to D6, minus to GND.

  3. NANO

    Upload with WARN_AFTER_MS set to 5000

    A short wait for testing.

  4. NANO

    Hold the magnet next to the switch

    Serial monitor prints Door closed.

  5. NANO

    Move the magnet away

    Door opened prints, and after five seconds it beeps.

  6. NANO

    Bring the magnet back

    The beeping stops.

  7. NANO

    Set WARN_AFTER_MS back to 60000

    Upload again.

  8. NANO

    Fix the parts to the fridge

    Reed switch on the body, magnet on the door.

In short

How do you build a fridge door left-open beeper?

A magnet and reed switch on a fridge door sound a beeper if the door stays open more than a minute. You need Arduino Nano, Door reed switch MC-38, Passive buzzer, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 80 minutes.

Level
Beginner
Time
About 80 min
Parts
5

Parts list

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

Wiring

FromToWhy
Reed switch one terminalNano D2Internal pull-up
Reed switch other terminalNano GNDClosed when the magnet is near
MagnetFixed on the door edgeSits next to the reed switch when the door is shut
Passive buzzer plusNano D6Alarm tone
Passive buzzer minusNano GNDGround
Nano powerUSB adapter or power bankKeep it outside the cold space

Code

A reed switch has two thin metal contacts in a glass tube that close when a magnet comes near. Fix the switch on the fridge body and the magnet on the door edge so that the closed door holds the switch closed: with the internal pull-up, closed reads LOW and an open door reads HIGH. The sketch records when the door opened, and after 60 seconds starts a short beep every four seconds, then every second once it has been open for three minutes. A 100 millisecond filter stops a flicker from a door that is not quite closed. The beeper stops as soon as the door closes. For a test, change the 60000 to 5000 so you do not wait a full minute. It is a reminder aid and does not protect food: check your fridge temperature yourself. Keep the electronics outside the fridge, since cold and condensation will damage a bare Nano, and run the thin reed switch wires through the door seal gap, never through the door seal in a way that stops it closing.

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;
const uint8_t BUZ = 6;

const unsigned long WARN_AFTER_MS = 60000UL;     // first beep after 60 seconds
const unsigned long LOUD_AFTER_MS = 180000UL;    // faster beeps after 3 minutes

unsigned long openedAt = 0;
bool wasOpen = false;
unsigned long lastBeep = 0;

bool doorOpen() {
  // Magnet near the reed switch closes it, so closed reads LOW and the door is shut.
  static bool state = false;
  static unsigned long changed = 0;
  bool raw = digitalRead(REED) == HIGH;          // HIGH means the door is open
  if (raw != state && millis() - changed > 100) { state = raw; changed = millis(); }
  return state;
}

void setup() {
  pinMode(REED, INPUT_PULLUP);
  pinMode(BUZ, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  bool open = doorOpen();

  if (open && !wasOpen) { openedAt = millis(); Serial.println("Door opened"); }
  if (!open && wasOpen) { noTone(BUZ); Serial.println("Door closed"); }
  wasOpen = open;

  if (open) {
    unsigned long openFor = millis() - openedAt;
    if (openFor > WARN_AFTER_MS) {
      unsigned long gap = (openFor > LOUD_AFTER_MS) ? 1000UL : 4000UL;
      if (millis() - lastBeep > gap) {
        lastBeep = millis();
        tone(BUZ, 2200, 200);                    // short 200 ms beep
      }
    }
  }
}

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.

Door opened

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 switchDoor closed, silent
Magnet away for 10 secondsSilent, then no beep before 60 seconds
Magnet away for 70 secondsA beep every four seconds
Magnet away for over three minutesA beep every second
Magnet backBeeping stops at once

If it does not work

Beeps when the door is closed

The magnet is too far from the switch, move them closer.

Never beeps

Check the reed switch is wired to D2 and GND.

False alarms

Increase the 100 ms filter or fix the magnet more firmly.

Reed switch breaks

Glass is fragile, mount it with tape, and do not bend its leads close to the glass.

Buzzer is silent

Use a passive buzzer with tone(), and check its polarity.

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

Ask Lark AI

Common questions

What parts do I need for the fridge door left-open beeper?

Arduino Nano, Door reed switch MC-38, Passive buzzer, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the fridge door left-open beeper take to build?

About 80 minutes for a beginner maker, in 8 steps.

How do I know the fridge door left-open beeper works?

Magnet next to the switch: Door closed, silent. Magnet away for 10 seconds: Silent, then no beep before 60 seconds. Magnet away for 70 seconds: A beep every four seconds.

Beeps when the door is closed: what should I check?

The magnet is too far from the switch, move them closer.

Never beeps: what should I check?

Check the reed switch is wired to D2 and GND.

False alarms: what should I check?

Increase the 100 ms filter or fix the magnet more firmly.

Reed switch breaks: what should I check?

Glass is fragile, mount it with tape, and do not bend its leads close to the glass.