How to Build a Simple Motion Sensor Alarm with Arduino and PIR Sensor

Making a simple motion sensor alarm using an Arduino and a PIR sensor is an easy DIY electronics project that can be completed in an afternoon. With just a few components, I can build a device that will detect movement in a room and sound an audible alarm. Here is a step-by-step guide on how I built my own motion sensor alarm.

What You Will Need

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

How a PIR Motion Sensor Works

Before assembling the alarm, it helps to understand how a PIR sensor detects motion.

The PIR sensor has a pyroelectric sensor that can detect levels of infrared radiation. Everything emits some low level radiation, and the hotter something is, the more radiation is emitted. The PIR sensor has a special filter that is sensitive to infrared radiation at 8-14 μm wavelength, which is the range that humans emit.

When a human (or animal) moves within the PIR sensor's range, the amount of infrared radiation in the field of view changes quickly. The PIR sensor detects this change in infrared levels and sends a high signal to the Arduino when motion is detected.

Assembling the Motion Sensor Alarm Circuit

With an understanding of how the PIR motion sensor works, I can now assemble the alarm circuit:

1. Connect the PIR sensor to the Arduino

The PIR sensor has 3 pins - power, ground, and signal. I connected the power pin to 5V and ground to GND. The signal pin connects to a digital pin on the Arduino. I used pin 2.

2. Connect the buzzer

The buzzer also has 2 pins - positive and negative. The positive pin connects to digital pin 3 on the Arduino, and negative connects to ground.

3. Add power

With the Arduino connected by USB, I powered the circuit with a 9V battery plugged into the Vin pin. Make sure the power switch is in the "on" position!

And that's it - the motion sensor alarm hardware is assembled!

Loading the Arduino Sketch

Now I need to load a program onto the Arduino so it knows what to do when motion is detected. This program code is called a sketch.

The sketch needs to:

Here is the Arduino sketch I used:

```cpp
const int pirPin = 2; // Input for PIR sensor
const int buzzer = 3; // Output for buzzer

void setup() {

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

}

void loop() {

if(digitalRead(pirPin) == HIGH) {

// Motion detected
digitalWrite(buzzer, HIGH);

}
else {

// No motion
digitalWrite(buzzer, LOW);

}

}
```

I loaded this sketch onto the Arduino board using the Arduino IDE.

Testing and Using the Motion Sensor Alarm

After loading the sketch, it's time to test the alarm!

When I walk in front of the PIR sensor, the buzzer starts buzzing loudly to alert me of the detected motion. The alarm works!

The sensitivity can be adjusted by changing the delay in the sketch. A longer delay means the alarm will only sound if motion is detected for a longer period of time.

The alarm will run continuously on battery power, so it's easy to set up anywhere that needs motion detection. And there you have it! A simple DIY motion sensor alarm using Arduino.