Projects / Door left-ajar chime

Door left-ajar chime

Beginner1.7 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANO

    Wire the sensor

    Pin 1 to 5V, pin 2 to GND, pin 3 to D2.

  2. NANO

    Add the pull-up

    10 kilohm from D2 to 5V.

  3. NANO

    Wire the buzzer

    Plus to D6, minus to GND.

  4. NANO

    Upload the sketch

    Serial monitor waits for door events.

  5. NANO

    Hold the magnet to the flat face

    "Door closed" appears when it is near.

  6. NANO

    Move the magnet away

    "Door opened" appears.

  7. NANO

    Wait 30 seconds

    The buzzer gives three beeps and repeats.

  8. NANO

    Bring the magnet back

    The chime stops.

In short

How do you build a door left-ajar chime?

A Hall sensor and a magnet detect an open door and sound a chime when it is left open. You need Arduino Nano, Hall Effect Sensor A3144, Neodymium magnets (10 × 3 mm), Active buzzer 5 V, Resistor 10 kΩ and Breadboard 830 Tie Points. It takes 8 steps and about 100 minutes.

Level
Beginner
Time
About 100 min
Parts
6

Parts list

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

Wiring

FromToWhy
Hall sensor pin 1 (VCC)Nano 5VPower, flat face toward you shows pin 1 on the left
Hall sensor pin 2 (GND)Nano GNDGround
Hall sensor pin 3 (output)Nano D2Goes LOW when the magnet is near
10 kilohmBetween D2 and 5VPull-up for the open-collector output
Active buzzer plusNano D6Chime
Active buzzer minusNano GNDGround

Code

The A3144 is a Hall-effect switch. Its output is an open collector that pulls low when a magnetic field of the right polarity is close, and lets go when the field goes away, so it needs a pull-up resistor to give a clean high. The chip only reacts to one pole of a magnet, the south pole facing the printed face of the sensor, so if nothing happens flip the magnet over. Stick the sensor on the door frame and the magnet on the door so they line up within a centimetre or so when the door is shut. The sketch records when the door opens and sounds a three-beep chime once it has been open for 30 seconds, then repeats every ten seconds until the door is shut. Because the Hall sensor has no moving parts it does not wear out like a reed switch, but a strong nearby magnet, for example a fridge door seal, can confuse it. Use a small enclosure and low-voltage wiring only; this is a convenience chime, not a security alarm.

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 int HALL = 2;
const int BUZZER = 6;
const unsigned long OPEN_LIMIT_MS = 30000;   // chime after the door has been open this long
const unsigned long REPEAT_MS = 10000;       // repeat every 10 seconds

unsigned long openedAt = 0;
unsigned long lastChime = 0;
bool wasClosed = true;

void chime() {
  for (int i = 0; i < 3; i++) {
    digitalWrite(BUZZER, HIGH); delay(120);
    digitalWrite(BUZZER, LOW);  delay(120);
  }
}

void setup() {
  pinMode(HALL, INPUT);                     // the external 10 kilohm pulls it up
  pinMode(BUZZER, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  bool closed = (digitalRead(HALL) == LOW); // magnet near the sensor = door closed
  unsigned long now = millis();

  if (closed && !wasClosed) {
    Serial.println("Door closed");
  }
  if (!closed && wasClosed) {
    openedAt = now;
    lastChime = now;
    Serial.println("Door opened");
  }
  wasClosed = closed;

  if (!closed && now - openedAt > OPEN_LIMIT_MS && now - lastChime > REPEAT_MS) {
    Serial.println("Door left open");
    chime();
    lastChime = millis();
  }
  delay(20);
}

Test checklist

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

CheckExpected
Magnet near the flat faceClosed
Magnet removedOpened
Open for 30 secondsChime
Closed againChime stops
Magnet reversedNo reaction, flip it

If it does not work

No reaction

Flip the magnet, only one pole works, and check the pin order.

Always reads closed

Check the 10 kilohm pull-up and pin 3 wire.

Chimes too early

Raise OPEN_LIMIT_MS.

False openings

The magnet is too far, move it closer.

Buzzer silent

Check it is an active buzzer and the polarity.

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

Ask Lark AI

Common questions

What parts do I need for the door left-ajar chime?

Arduino Nano, Hall Effect Sensor A3144, Neodymium magnets (10 × 3 mm), Active buzzer 5 V, Resistor 10 kΩ and Breadboard 830 Tie Points.

How long does the door left-ajar chime take to build?

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

How do I know the door left-ajar chime works?

Magnet near the flat face: Closed. Magnet removed: Opened. Open for 30 seconds: Chime.

No reaction: what should I check?

Flip the magnet, only one pole works, and check the pin order.

Always reads closed: what should I check?

Check the 10 kilohm pull-up and pin 3 wire.

Chimes too early: what should I check?

Raise OPEN_LIMIT_MS.

False openings: what should I check?

The magnet is too far, move it closer.