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

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

Building a motion sensor alarm with an Arduino and PIR sensor is an easy and fun electronics project. Here is a step-by-step guide on how I built my own motion alarm using these components.

What You Need

To build the motion sensor alarm, you will need:

How a PIR Motion Sensor Works

A PIR motion sensor allows you to sense movement and detect objects. It works by detecting infrared radiation that is emitted by objects in its field of view.

The PIR sensor has a pyroelectric sensor inside that generates energy when exposed to infrared radiation. The sensor has a Fresnel lens that focuses infrared signals onto the element.

When something moves, it emits slightly more or less IR radiation than the background. This change triggers the sensor to generate an output signal indicating motion is detected.

The PIR sensor has 2-3 output pins - VCC, GND, and OUT (signal). The OUT pin outputs a HIGH signal when motion is detected. We'll connect this pin to the Arduino.

Circuit Diagram

Here is the circuit diagram for connecting the components:

The PIR sensor, buzzer, and Arduino all share the same 5V power from the Arduino board. The PIR OUT pin connects to a digital input on the Arduino. The buzzer connects between a digital output and GND.

Setting up the Circuit

Follow these steps to set up the motion sensor alarm circuit:

  1. Insert the Arduino into the breadboard. Connect the 5V and GND pins to power rails on the breadboard.

  2. Connect the PIR sensor's VCC pin to 5V and GND pin to the Arduino GND.

  3. Connect the PIR OUT pin to digital pin 2 on the Arduino.

  4. Connect the positive lead of the buzzer to digital pin 8. Connect the negative lead to GND.

  5. Connect the 9V battery to power the Arduino.

Once everything is wired up, your circuit should look similar to the diagram. Double check the connections before powering it up!

Uploading the Code

With the hardware ready, it's time to program the alarm. I used the following Arduino sketch:

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

void setup() {
pinMode(pirPin, INPUT);
pinMode(buzzer, OUTPUT);
}

void loop() {
if(digitalRead(pirPin) == HIGH) {
// Motion detected
digitalWrite(buzzer, HIGH);
}
else {
digitalWrite(buzzer, LOW);
}
delay(500); // Delay to avoid overloading
}
```

This initializes the PIR sensor pin and buzzer as inputs/outputs. It reads the PIR sensor pin state continuously in a loop. If motion is detected (HIGH state), it triggers the buzzer on.

Upload this code to your Arduino board and open the serial monitor.

Testing It Out

Now you're ready to test your DIY motion sensor alarm!

When you walk in front of the PIR sensor, the buzzer should sound. The buzzer alarm will turn on whenever motion is detected.

Try adjusting the PIR sensor distance and sensitivity as needed. You may need to tweak the code delay or change the buzzer type for better response.

Some ideas for enhancing this project:

That wraps up this tutorial on building a simple motion sensor alarm with an Arduino and PIR sensor. Let me know in the comments if you have any questions!