Build it step by step
0 of 6 doneFit the reed and magnet
Reed on the frame and magnet on the door, so they touch when closed.
Wire the reed and snooze
Reed to D2 and GND, button to D3 and GND.
Add the buzzer
Buzzer between D8 and GND.
Test with a short limit
Set OPEN_LIMIT to 10 seconds, upload and open the door.
Check snooze
Press the button during the alarm. The sound stops for the snooze time.
Set real times
Restore 5 minutes and 10 minutes, then power from a USB adapter.
How do you build a garage car door ajar alarm?
A reed switch on a garage or car boot warns if it stays open for more than 5 minutes, with a snooze button. You need Arduino Nano, Door reed switch MC-38, Active buzzer 5 V, Tactile push button 6 mm, 5 V 2 A USB adapter, USB A to micro-USB cable (data) and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 30 minutes.
- Level
- Beginner
- Time
- About 30 min
- Parts
- 7
Wiring
| From | To | Why |
|---|---|---|
| Reed switch | Nano D2 and GND | Closed (LOW) when the door is shut |
| Snooze button | Nano D3 and GND | Silence for 10 minutes |
| Buzzer + | Nano D8 | Alarm |
| Buzzer - | Nano GND | Return |
| USB adapter | Nano USB port | 5 V supply |
Code
Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones). No libraries. For testing set OPEN_LIMIT to 10 seconds. A garage has mains, but this build uses only a USB adapter plugged into an existing socket, so no mains wiring is needed.
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 byte REED = 2, SNOOZE = 3, BUZZ = 8;
const unsigned long OPEN_LIMIT = 5UL * 60UL * 1000UL; // 5 minutes
const unsigned long SNOOZE_MS = 10UL * 60UL * 1000UL; // 10 minutes
unsigned long openSince = 0, snoozeUntil = 0;
void setup() {
pinMode(REED, INPUT_PULLUP);
pinMode(SNOOZE, INPUT_PULLUP);
pinMode(BUZZ, OUTPUT);
}
void loop() {
bool open = digitalRead(REED) == HIGH; // magnet away from the reed
if (!open) { openSince = 0; digitalWrite(BUZZ, LOW); }
else if (openSince == 0) openSince = millis();
if (digitalRead(SNOOZE) == LOW) snoozeUntil = millis() + SNOOZE_MS;
if (open && millis() - openSince > OPEN_LIMIT && millis() > snoozeUntil) {
digitalWrite(BUZZ, (millis() / 500) % 4 == 0); // a short beep every two seconds
} else digitalWrite(BUZZ, LOW);
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 |
|---|---|
| Door closed | Silent |
| Door open under 5 minutes | Silent |
| Door open longer | Beep every two seconds |
| Press snooze | Silent for 10 minutes |
If it does not work
Alarm with the door closed
The magnet is too far from the reed switch.
Never beeps
OPEN_LIMIT is long or the reed switch wire is not on D2.
Beeps too quietly
Use an active buzzer with more volume or a small speaker driver.
Snooze ignored
Check the button wires to D3 and ground.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the garage car door ajar alarm?
Arduino Nano, Door reed switch MC-38, Active buzzer 5 V, Tactile push button 6 mm, 5 V 2 A USB adapter, USB A to micro-USB cable (data) and Jumper wires male to male (40 pcs, 20 cm).
How long does the garage car door ajar alarm take to build?
About 30 minutes for a beginner maker, in 6 steps.
How do I know the garage car door ajar alarm works?
Door closed: Silent. Door open under 5 minutes: Silent. Door open longer: Beep every two seconds.
Alarm with the door closed: what should I check?
The magnet is too far from the reed switch.
Never beeps: what should I check?
OPEN_LIMIT is long or the reed switch wire is not on D2.
Beeps too quietly: what should I check?
Use an active buzzer with more volume or a small speaker driver.
Snooze ignored: what should I check?
Check the button wires to D3 and ground.
