Projects / Reed switch door chime

Reed switch door chime

Beginner50 minGuided buildReviewed

Build it step by step

0 of 6 done
  1. NANO

    Wire the switch

    One wire to D2 and one to GND.

  2. NANO

    Wire the buzzer

    Plus to D8, minus to GND.

  3. NANO

    Upload the sketch

    Nothing sounds while the magnet is next to the switch.

  4. NANO

    Pull the magnet away

    A two-note chime plays once.

  5. NANO

    Bring it back and pull away again

    After four seconds it chimes again.

  6. NANO

    Fix the parts on a door

    Switch on the frame, magnet on the door, within about a centimetre.

In short

How do you build a reed switch door chime?

A magnetic reed switch on a cupboard or room door makes a short two-note chime whenever the door opens. It is a friendly doorbell for a shop corner or a pantry. It is not a security alarm. 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 6 steps and about 50 minutes.

Level
Beginner
Time
About 50 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 wire 1Nano D2Input with the internal pull-up
Reed switch wire 2Nano GNDCloses to ground when the magnet is near
Buzzer plusNano D8Passive buzzer driven with tone
Buzzer minusNano GNDCommon ground

Code

The reed switch is two thin metal blades in a glass tube that touch when a magnet is close. With the Nano's internal pull-up turned on, the pin reads low while the magnet is next to the switch (door closed) and high when the door swings away. The sketch waits sixty milliseconds for the reading to settle so a rattle does not count, then plays two short notes once per opening and stays quiet for four seconds so a door left swinging does not chime again and again. Fix the switch on the frame and the magnet on the door so they are within about a centimetre when the door is shut. This is a chime for convenience only. It is not a burglar alarm and must not be relied on for security or safety.

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).

// Reed switch door chime. The switch is closed (LOW) while the magnet sits next to it,
// which is the closed-door position. When the door opens the pin goes HIGH.
const uint8_t REED_PIN = 2;
const uint8_t BUZZER_PIN = 8;
const unsigned long SETTLE_MS = 60;     // ignore contact bounce
const unsigned long QUIET_MS = 4000;    // no second chime for four seconds

bool doorOpen = false;
bool lastRead = false;
unsigned long changedAt = 0;
unsigned long lastChime = 0;

void chime() {
  tone(BUZZER_PIN, 988, 120);           // B5
  delay(150);
  tone(BUZZER_PIN, 1319, 220);          // E6
  delay(250);
  noTone(BUZZER_PIN);
}

void setup() {
  pinMode(REED_PIN, INPUT_PULLUP);
  pinMode(BUZZER_PIN, OUTPUT);
  doorOpen = digitalRead(REED_PIN) == HIGH;
  lastRead = doorOpen;
}

void loop() {
  bool reading = digitalRead(REED_PIN) == HIGH;    // HIGH means the magnet is away
  if (reading != lastRead) {
    lastRead = reading;
    changedAt = millis();
  }
  if (millis() - changedAt > SETTLE_MS && reading != doorOpen) {
    doorOpen = reading;
    if (doorOpen && millis() - lastChime > QUIET_MS) {
      chime();
      lastChime = millis();
    }
  }
}

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 switchSilent
Magnet pulled awayChime once
Door held openNo repeat
Open again after four secondsChime
Gap too wide when closedChimes by mistake, so move the parts closer

If it does not work

Chimes all the time

The magnet is too far from the switch when closed, or the wires are loose.

Never chimes

Swap the switch wires to check them or test with a jumper to GND.

Chimes twice

Raise SETTLE_MS or QUIET_MS.

Buzzer silent

Check it is a passive buzzer and the plus wire is on D8.

Chimes when you touch the wires

Keep the wires short and fixed.

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

Ask Lark AI

Common questions

What parts do I need for the reed switch door chime?

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 reed switch door chime take to build?

About 50 minutes for a beginner maker, in 6 steps.

How do I know the reed switch door chime works?

Magnet next to the switch: Silent. Magnet pulled away: Chime once. Door held open: No repeat.

Chimes all the time: what should I check?

The magnet is too far from the switch when closed, or the wires are loose.

Never chimes: what should I check?

Swap the switch wires to check them or test with a jumper to GND.

Chimes twice: what should I check?

Raise SETTLE_MS or QUIET_MS.

Buzzer silent: what should I check?

Check it is a passive buzzer and the plus wire is on D8.