Build a simple burglar alarm: proper instructions
This tabletop demonstration uses a normally closed magnetic door contact to start a low-voltage buzzer after an exit delay. It teaches switch inputs and timing, but is not a real burglar alarm. USB removal defeats it, and it has no backup battery, tamper loop, monitoring or certified sounder.
Choose components
- Arduino Uno, Nano or compatible board and USB cable.
- Wired normally closed magnetic reed contact and magnet.
- 5 V active buzzer within the documented Arduino pin-current limit, LED, 220 to 330 Ω resistor and momentary reset button.
Normally closed wiring is useful for a demonstration because opening the door, cutting a wire or unplugging the contact all read as an alarm. It is not, by itself, a supervised professional circuit.
Wire it
- Connect one contact lead to GND and the other to D2. Use
INPUT_PULLUP; closed contact reads LOW and open circuit HIGH. - Connect a suitable low-current buzzer from D9 to GND, and LED through its resistor from D13 to GND.
- Connect reset button from D4 to GND, also using
INPUT_PULLUP. - Align magnet and contact, testing the manufacturer’s gap before permanent mounting.
Software process
On startup set an exit delay of 20 seconds. Blink LED during the delay. Afterwards, if D2 reads HIGH, latch an alarm, set LED HIGH and use tone(9, 2200). When D4 reads LOW, stop the tone, clear the latch and start a new delay. Print status to Serial Monitor for bench debugging, but do not mistake repeated messages for a durable event log.
after 20 seconds arm; if contact opens latch alarm; sound buzzer; reset button silences and starts a fresh exit delay.
Test safely
- Start with buzzer distant from ears or disconnected, confirm closed contact is safe and opening after delay latches alarm.
- Press reset and confirm tone stops and the full delay returns.
- Use masking tape to test mounting alignment before drilling. Add strain relief so door movement cannot pull wires.
- Use a plastic enclosure only after bench testing, leaving inspection access.
Faults and security limits
| Problem | Check |
|---|---|
| Sounds while closed | Contact may be normally open, reversed in assumption, misaligned or too far apart. |
| No alarm on opening | Confirm contact goes to D2 and GND, not 5 V. |
| Board resets or buzzer weak | Stop: buzzer may exceed pin current; use a designed transistor driver. |
Never connect this project to mains, a car battery, a 12 V siren, lock solenoid or household transformer. A real intruder can cut power, remove magnet and contact together, use another entry route or wait out a buzzer. Do not use this for fire, personal safety or actual protection. Seek a reputable installer and certified equipment where security matters.
Build carefully
Disconnect USB before moving wires. Work on a dry, uncluttered bench and use only the low-voltage supply provided by USB while developing the circuit. Check each connection against the label on the actual module, because clone boards can put connectors in a different order. A breadboard is useful for experiments but its contacts can work loose; do not leave an unattended project in a place where a lead can be pulled, crushed or exposed to water.
Record what you changed between tests. Change one setting, upload one revision, then repeat the same test. This is faster and safer than changing wiring, code and sensor position at once. Once the circuit works, add strain relief and an enclosure, but keep access for inspection and do not hide untested connections.
Before relying on any result
Repeat the test after changing the final location and after a power cycle. Label leads and keep notes of settings, dates and observed behaviour. Do not extend sensor leads indefinitely or substitute a power supply without checking voltage and current requirements. If behaviour changes without an explained reason, return to the last known-good wiring rather than bypassing a protective component or increasing supply voltage.
Review the result
Hobby electronics is most reliable when its assumptions are visible. Identify what creates an input, what the board decides, and what physical output follows. Consider loss of power, disconnected cable, loose breadboard contact, wrong software port, restart, accidental adjustment and environmental change. A successful five-minute demonstration proves only that it worked for five minutes under those conditions. Repeat tests after adjustments, and keep the project clearly labelled as a low-voltage experiment where others might otherwise assume it provides protection or control.
Practical checklist
Before each use, inspect the USB lead, board, insulation and sensor cable for damage. Confirm the board is powered from the intended low-voltage source and that its indicator behaviour agrees with the latest test. Keep the instructions, component part numbers and the current program with the project so that a future repair does not depend on memory. Do not leave a breadboard assembly where children, pets, moisture, metal objects or moving furniture can reach it. Disconnect power before repositioning conductors.
When diagnosing a problem, begin with the simplest observation: power indication, physical connector orientation, measured input state and program output. Use a known-good cable and a short test setup before adding extensions, enclosures or optional modules. Do not “fix” an uncertain fault by removing resistors, joining supply rails, increasing voltage or bypassing a switch. If a component becomes hot, smells unusual, repeatedly resets the board, or has damaged insulation, disconnect power and replace or investigate it before continuing.
Document both expected and unexpected results. Note the ambient conditions, sensor placement, delay settings and test duration. That evidence makes false triggers, questionable temperature readings and intermittent connections easier to distinguish from software mistakes. The finished device remains a hobby experiment: use independent, purpose-designed equipment wherever a missed event, incorrect measurement or failure to operate could cause loss, injury, regulatory breach or an emergency response.