Build it step by step
0 of 8 doneWire the sensor
Pin 1 to 5V, pin 2 to GND, pin 3 to D2.
Add the pull-up
10 kilohm from D2 to 5V.
Wire the buzzer
Plus to D6, minus to GND.
Upload the sketch
Serial monitor waits for door events.
Hold the magnet to the flat face
"Door closed" appears when it is near.
Move the magnet away
"Door opened" appears.
Wait 30 seconds
The buzzer gives three beeps and repeats.
Bring the magnet back
The chime stops.
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
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- Mechanical & Hardware
- Motors & ActuatorsBuy
- PassivesBuyResistor 10 kΩ × 1
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Hall sensor pin 1 (VCC) | Nano 5V | Power, flat face toward you shows pin 1 on the left |
| Hall sensor pin 2 (GND) | Nano GND | Ground |
| Hall sensor pin 3 (output) | Nano D2 | Goes LOW when the magnet is near |
| 10 kilohm | Between D2 and 5V | Pull-up for the open-collector output |
| Active buzzer plus | Nano D6 | Chime |
| Active buzzer minus | Nano GND | Ground |
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.
| Check | Expected |
|---|---|
| Magnet near the flat face | Closed |
| Magnet removed | Opened |
| Open for 30 seconds | Chime |
| Closed again | Chime stops |
| Magnet reversed | No 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 →
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.
