Door Intruder Alarm
Explorer Β· Ages 7β9
- 1Read the conceptLearn the big idea behind this project.
- 2Check the partsSee which parts the robot needs.
- 3Follow the build stepsBuild it step by step, then test it.
- 4Answer the quizTap one answer for each of the 10 questions to earn XP.
π‘ The concept
A door alarm knows when a door opens. A magnetic reed switch is held closed while the door is shut. When the door opens, the switch releases, the microcontroller notices the change, and the buzzer sounds. Sensing a change and reacting to it is the heart of every alarm system.
Parts you need
- Buzzer
- Magnetic reed switch (or button)
- Microcontroller
- Battery
- Jumper wires
π Parts specification
Exactly what each part is, which models to buy, and what it does.
MicrocontrollerβΈ
Suggested models: BBC micro:bit V2 or Arduino Uno R3
Features: Needs just 2 pins: one digital input for the switch and one digital output for the buzzer. It checks the switch hundreds of times every second.
BuzzerβΈ
Suggested models: Active piezo buzzer (3β5V)
Features: Makes a sound all by itself when you give it power β no tunes needed. It has + and β legs, so polarity matters. A longer beep pattern makes a better siren.
SwitchβΈ
Suggested models: Magnetic reed switch MC-38, or a mini push button
Features: A reed switch is two contacts in a sealed tube that touch when a magnet is near. Stick the magnet on the door and the switch on the frame β opening the door separates them and the circuit 'sees' it.
Battery / powerβΈ
Suggested models: 2ΓAA pack or 9V with clip
Features: 3Vβ9V depending on your board. Keep it off while wiring.
π» Program the microcontroller
π² App to use: Microsoft MakeCode for micro:bit, or Arduino IDE for Arduino Uno
MakeCode version: forever β if P0 pressed (button released) β play tone high pitch, else β rest.
// Arduino IDE (C++) β Door Alarm
const int SWITCH = 2; // reed switch
const int BUZZ = 8; // active buzzer
void setup() {
pinMode(SWITCH, INPUT_PULLUP);
pinMode(BUZZ, OUTPUT);
}
void loop() {
if (digitalRead(SWITCH) == HIGH) {
tone(BUZZ, 1000); // door open: alarm!
} else {
noTone(BUZZ); // door closed: quiet
}
}π§ How it works: INPUT_PULLUP makes the pin read HIGH when the switch is loose (door open) and LOW when it's held down (door closed by the magnet). The loop checks the switch constantly β the moment it goes HIGH, tone() beeps the buzzer at 1000 Hz. Turn the beep on and off in a pattern to make a wee-woo siren.
π οΈ Build it step by step
Press Play to watch every part go into place and every wire connect. Ask a grown-up to help with real wiring!
Step 1 of 6
π Power the board
Connect the battery to the microcontroller. Battery OFF until everything is wired and checked.