How to Build a Simple Motion Sensor Alarm Using an Arduino and PIR Sensor


Building a motion sensor alarm using an Arduino and a passive infrared (PIR) sensor is an easy and fun electronics project that can be completed in under an hour. With just a few components, you can create your own security system to detect intruders and activate an alarm.

In this guide, I will show you step-by-step how to build a simple motion sensor alarm using an Arduino Uno and a PIR sensor. I will cover how PIR sensors work, how to connect the components together on a breadboard, how to program the Arduino, and how to build the alarm system enclosure.

By the end, you will have learned:

So if you're ready to build your own motion-activated alarm, let's get started!

How PIR Sensors Work

The key component of this motion sensor alarm is the passive infrared (PIR) sensor, which detects motion using infrared radiation.

PIR sensors contain pyroelectric sensors that can detect levels of infrared radiation. Everything emits some low level of radiation, and the hotter something is, the more radiation is emitted. The human body emits a significant amount of infrared radiation, in the form of body heat.

When a human (or other heat-emitting object) passes in front of the PIR sensor, the sensor detects the sudden change in infrared radiation levels. This change triggers the output pin on the PIR sensor to go HIGH (3.3V or 5V on Arduino models).

The PIR sensor has a fresnel lens that helps focus infrared radiation on the pyroelectric sensor. It also has a dome-shaped plastic cover that helps eliminate false alarms from ambient temperature changes.

So in summary, when the PIR sensor detects a sudden change in infrared radiation levels caused by motion, its output pin is triggered HIGH to signal that motion has been detected.

Components Needed

To build the motion sensor alarm, you will need the following components:

Optionally, you can also add an LCD screen to display alarm messages.

Circuit Diagram

Here is a circuit diagram showing how to connect the components to the Arduino:

How to Build a Simple Motion Sensor Alarm Using an Arduino and PIR Sensor

The PIR sensor has three pins: GND, VCC, and OUT.

The buzzer, LED, and resistor connect to any digital GPIO pin on the Arduino.

Setting Up the Hardware

Follow these steps to setup the hardware for the motion sensor alarm:

  1. Insert the Arduino Uno into your breadboard. Make sure it is oriented with the USB port lining up with the notch on the breadboard.

  2. Connect the PIR sensor pins to the breadboard.

  3. GND to GND rail
  4. VCC to 5V rail
  5. OUT to digital pin 2

  6. Connect the positive leg of LED to digital pin 6.

  7. Connect 220ohm resistor from negative leg of LED to GND rail.

  8. Connect the positive lead of buzzer to digital pin 10.

  9. Connect negative lead of buzzer to GND rail.

Double check that all components match the circuit diagram connections.

Loading the Arduino Program

With the hardware connected up, it's time to load the Arduino program that will monitor the PIR sensor to detect motion and trigger the alarm.

Here is the full program code:

// Motion Sensor Alarm by Circuit Basics

// Attach motion sensor to pin 2
int pirPin = 2;

// Buzzer connected to pin 10
int buzzerPin = 10;

// LED on pin 6
int ledPin = 6;

void setup() {

// Init serial connection

// Set LED pin as output
pinMode(ledPin, OUTPUT);

// Set buzzer pin as output
pinMode(buzzerPin, OUTPUT);

// Set motion sensor pin as input
pinMode(pirPin, INPUT);

// Print startup message
Serial.println("Motion Sensor Alarm Active");


void loop(){

// Read motion sensor value
int sensorValue = digitalRead(pirPin);

// If motion detected
if(sensorValue == HIGH) {

// Sound alarm
digitalWrite(buzzerPin, HIGH);

// Turn on LED
digitalWrite(ledPin, HIGH);

// Print message
Serial.println("Motion Detected!");

// Delay to avoid overloading

// If no motion
} else {

// Turn off alarm
digitalWrite(buzzerPin, LOW);

// Turn off LED
digitalWrite(ledPin, LOW);



To summarize, the code first sets up the IO pins and prints a startup message. In the main loop, it reads the PIR sensor pin. If motion is detected (pin goes HIGH), it turns on the LED, sounds the buzzer, and prints a message. It delays for 500ms to avoid over triggering. If no motion is detected, it turns the LED and buzzer off.

Follow these steps to upload the program:

  1. Copy the code into the Arduino IDE.

  2. Verify the code compiles with no errors.

  3. Upload the program to your Arduino board.

  4. Open the Serial Monitor at 9600 baud to see debug messages.

Once uploaded, the alarm system will start running! Wave your hand in front of the PIR sensor to test it.

Constructing the Enclosure

To build a nice alarm system enclosure, you can follow these tips:

Positioning is important for the PIR sensor. Point it at the area you want to detect motion, keeping in mind its conical sensing pattern.

Usage Tips

Here are some tips for using your motion sensor alarm:

And that covers the basics of building your own motion sensor alarm with Arduino! Let me know if you have any other questions.