PIR Intruder Alarm (Arduino)
Sound an active buzzer and flash an LED when a PIR sensor sees motion. A complete little security alarm.
Beginner20 min
What you need
Wiring
Hover a pin or a wire to trace the connection.
Code
intruder_alarm.ino
// Alarm: PIR motion triggers an active buzzer + LED for a couple seconds.
const int pirPin = 2;
const int buzzer = 8; // active buzzer (beeps on HIGH)
const int ledPin = 13;
void setup() {
pinMode(pirPin, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
if (digitalRead(pirPin) == HIGH) { // motion!
digitalWrite(buzzer, HIGH);
digitalWrite(ledPin, HIGH);
delay(2000); // hold the alarm 2s
} else {
digitalWrite(buzzer, LOW);
digitalWrite(ledPin, LOW);
}
}
Steps
- Wire the PIR: VCC to 5V, OUT to D2, GND to GND.
- Wire an active buzzer: + to D8, − to GND. LED on D13 through a 220Ω resistor.
- Upload, let the PIR settle ~30–60s.
- Walk past — the buzzer sounds and the LED lights for two seconds.