Projects / PIR intruder alarm with arm button

PIR intruder alarm with arm button

Beginner50 minGuided buildReviewed

Build it step by step

0 of 5 done
  1. UNOmotion

    Set the PIR

    Put the jumper on H (repeat trigger). Turn the time trimmer fully anticlockwise (shortest) and sensitivity to the middle.

  2. UNOmotion

    Wire the PIR

    VCC, GND, OUT to D2.

  3. UNO16.2 mA

    Wire the button and lights

    Button from D3 to GND, buzzer on D8, red LED on D9, green LED on D10.

  4. UNOmotion

    Upload and wait

    Upload and leave the room still for one minute while the PIR settles.

  5. UNO

    Arm and walk

    Press the button, leave within 10 s, then walk back in front of the sensor.

In short

How do you build a PIR intruder alarm with arm button?

A PIR sensor guards a room. Press the button to arm it, and any movement after a 10-second exit delay sounds the alarm. You need Arduino Uno R3, PIR Motion Sensor HC-SR501, Active buzzer 5 V, Tactile push button 6 mm, LED 5 mm red, LED 5 mm green, Resistor 220 Ω × 2, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 5 steps and about 50 minutes.

Level
Beginner
Time
About 50 min
Parts
9

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
PIR VCC / GNDUno 5V / GNDSensor power
PIR OUTUno D2HIGH while motion is seen
ButtonUno D3 and GNDArm and disarm (internal pull-up)
Uno D8Buzzer + (− to GND)Siren
Uno D9 / D10220 Ω, red / green LED, GNDArmed / disarmed lights

Code

Arduino IDE, board "Arduino Uno". No extra libraries. The HC-SR501 needs about a minute after power-up before its output is reliable.

Runs on a virtual Arduino Uno 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 PIR = 2, BTN = 3, BUZZER = 8, RED = 9, GREEN = 10;
enum State { DISARMED, ARMING, ARMED, ALARM };
State state = DISARMED;
unsigned long since = 0;

bool pressed() {
  static bool last = HIGH;
  bool now = digitalRead(BTN);
  bool fell = last == HIGH && now == LOW;
  last = now;
  if (fell) delay(30);           // simple debounce
  return fell;
}

void setup() {
  pinMode(PIR, INPUT); pinMode(BTN, INPUT_PULLUP);
  pinMode(BUZZER, OUTPUT); pinMode(RED, OUTPUT); pinMode(GREEN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  bool p = pressed();
  unsigned long t = millis() - since;
  switch (state) {
    case DISARMED: digitalWrite(GREEN, HIGH); digitalWrite(RED, LOW); digitalWrite(BUZZER, LOW);
      if (p) { state = ARMING; since = millis(); Serial.println("Arming"); } break;
    case ARMING: digitalWrite(GREEN, LOW); digitalWrite(RED, (t / 250) % 2);
      if (p) state = DISARMED;
      else if (t > 10000) { state = ARMED; Serial.println("Armed"); } break;
    case ARMED: digitalWrite(RED, HIGH);
      if (p) state = DISARMED;
      else if (digitalRead(PIR)) { state = ALARM; since = millis(); Serial.println("ALARM"); } break;
    case ALARM: digitalWrite(BUZZER, (t / 300) % 2); digitalWrite(RED, (t / 150) % 2);
      if (p) { state = DISARMED; Serial.println("Disarmed"); } break;
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
After power-upGreen LED on, buzzer silent
Button pressedRed LED blinks for 10 s, then stays on (armed)
Movement while armedBeeping siren and fast red blink
Button pressed during the alarmSilent, green LED on

If it does not work

Alarm goes off as soon as it arms

You were still in view. Lengthen the exit delay or point the sensor away from the door.

False alarms with nobody there

Keep the PIR away from heaters, sunlight and AC vents, and lower its sensitivity.

Button does nothing

Check it spans the breadboard gap and goes to GND.

PIR output stays HIGH for long

Turn the time trimmer fully anticlockwise.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the PIR intruder alarm with arm button?

Arduino Uno R3, PIR Motion Sensor HC-SR501, Active buzzer 5 V, Tactile push button 6 mm, LED 5 mm red, LED 5 mm green, Resistor 220 Ω × 2, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the PIR intruder alarm with arm button take to build?

About 50 minutes for a beginner maker, in 5 steps.

How do I know the PIR intruder alarm with arm button works?

After power-up: Green LED on, buzzer silent. Button pressed: Red LED blinks for 10 s, then stays on (armed). Movement while armed: Beeping siren and fast red blink.

Alarm goes off as soon as it arms: what should I check?

You were still in view. Lengthen the exit delay or point the sensor away from the door.

False alarms with nobody there: what should I check?

Keep the PIR away from heaters, sunlight and AC vents, and lower its sensitivity.

Button does nothing: what should I check?

Check it spans the breadboard gap and goes to GND.

PIR output stays HIGH for long: what should I check?

Turn the time trimmer fully anticlockwise.