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:
-
An Arduino microcontroller board - I used the Arduino Uno, but others like the Arduino Nano will also work. The Arduino is the brain of the alarm.
-
A PIR motion sensor - This sensor detects motion by measuring infrared radiation. It has a range of several meters.
-
A buzzer - This will sound the alarm when motion is detected.
-
A breadboard and jumper wires for connecting the components.
-
A 9V battery and battery clip (or USB cable) to power the Arduino.
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:
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:
-
Insert the Arduino into the breadboard. Connect the GND pin to ground, and VCC pin to 5V power.
-
Connect the PIR sensor's power pin to 5V and ground pin to GND.
-
Connect the PIR output pin to Arduino pin 2. This is the input we will monitor.
-
Connect one pin of the buzzer to Arduino pin 3, and the other pin to GND.
-
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:
-
Download the code from this link or copy it from the code snippet below.
-
Open the Arduino IDE and paste the code into a new sketch.
-
Verify and upload the code to your Arduino board.
```cpp
// 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:
-
Add a timeout after triggering to avoid repeated alarms.
-
Integrate it with home automation platforms like Home Assistant using MQTT.
-
Connect a louder siren instead of a buzzer for better audible range.
-
Use a solar panel or battery pack to avoid continuous external power.
-
Add a camera module to capture images when intrusion is detected.
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.