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

Building a simple motion sensor alarm with an Arduino and a PIR (passive infrared) sensor is an easy and fun electronics project. A motion sensor alarm can be useful for security, automation, and other applications. Here is a step-by-step guide on how I built one.

What You Will Need

To build the motion sensor alarm, you will need:

How a PIR Motion Sensor Works

A PIR (passive infrared) motion sensor detects motion by measuring infrared radiation emitted by objects in its field of view.

The sensor contains two sensitive elements that detect infrared radiation. When motion is detected, there is a difference in the infrared radiation detected by the two elements. This causes the output voltage of the sensor to change, indicating motion.

PIR sensors are often used in burglar alarms and automated lighting systems. They are easy to use with microcontroller boards like Arduino.

Circuit Diagram

Here is the circuit diagram for connecting the PIR motion sensor and buzzer to the Arduino:

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

The PIR sensor has three pins - power, ground, and output. The buzzer has two pins. We will connect them to the Arduino as shown.

Setting up the Circuit

Follow these steps to set up the circuit on a breadboard:

  1. Insert the Arduino into the breadboard. Connect the GND pin to ground, and VCC pin to 5V power.

  2. Connect the PIR sensor's power pin to 5V and ground pin to GND.

  3. Connect the PIR output pin to Arduino pin 2. This is the input we will monitor.

  4. Connect one pin of the buzzer to Arduino pin 3, and the other pin to GND.

  5. Install a 9V battery with a clip, or plug in a USB cable, to power the Arduino.

The circuit is now ready! Make sure no connections are touching to avoid shorts.

Loading the Code

Next, we need to load an Arduino sketch to monitor the PIR sensor and sound the buzzer when motion is detected. Here are the steps:

  1. Download the code from this link or copy it from the code snippet below.

  2. Open the Arduino IDE and paste the code into a new sketch.

  3. Verify and upload the code to your Arduino board.

// Motion Sensor Alarm Code

int pirPin = 2; // PIR Output pin
int buzzer = 3; // Buzzer pin

void setup() {

pinMode(pirPin, INPUT);
pinMode(buzzer, OUTPUT);


void loop() {

if(digitalRead(pirPin) == HIGH) {

tone(buzzer, 1000); // Send 1KHz sound signal

} else {

noTone(buzzer); // Stop sound



Now, whenever motion is detected by the PIR sensor, the buzzer will sound!

Testing and Using the Motion Sensor Alarm

After programming the Arduino, test the motion alarm by walking in front of the PIR sensor. The buzzer should sound as soon as motion is detected.

Try adjusting the sensitivity of the PIR sensor by turning the potentiometer. More sensitive means a larger detection range.

To use the alarm, simply power on the Arduino circuit. The buzzer will sound whenever the sensor detects movement in its range.

That's it! With just a few basic electronic components, we have built our own DIY motion sensor alarm with Arduino.

Considerations for a Robust Alarm

Here are some tips to improve the alarm for real-world uses:

By enhancing the basic alarm circuit, you can create a network-connected intrusion detection system for robust home security.

Let me know if you have any other questions! I'm happy to help guide you through Arduino projects.