How to Make a Simple Motion-Activated Alarm with An Arduino and a PIR Sensor
Introduction
Making a motion-activated alarm with an Arduino and a passive infrared (PIR) sensor is an easy and fun electronics project. The alarm will detect motion using the PIR sensor and sound an audible alert. This project is a great way to learn about Arduino programming and basic alarm circuits. With just a few components, I can build my own security system to protect my valuables.
In this article, I will provide a step-by-step guide on how I built the motion-activated alarm using the following components:
- Arduino Uno board
- PIR sensor
- Buzzer
- LED
- Resistors
- Jumper wires
- Breadboard
I will cover how to assemble the circuit, program the Arduino, and adjust the PIR sensor. By the end, I will have a working alarm that sounds an audible alert whenever motion is detected. Let's get started!
What I Need
To build the motion-activated alarm, I will need the following components:
Arduino Uno
The Arduino Uno is a microcontroller board that will control the alarm system. It will run the code and trigger the buzzer when motion is detected.
PIR Sensor
The PIR (passive infrared) sensor is used to detect motion. It is able to detect changes in infrared radiation levels, allowing it to sense when a human or animal passes in front of it.
Buzzer
The buzzer will provide the audible alert when motion is detected. Any small 5V buzzer will work.
LED
An LED is used to visually indicate when motion has been detected. Pick any color LED.
Resistors
- 220 ohm resistor for the buzzer
- 10k ohm resistor for the PIR sensor output pin
Jumper Wires
Jumper wires are used to connect the components to the Arduino board and breadboard.
Breadboard
A breadboard provides a convenient way to mount the circuit temporarily.
Circuit Diagram
Before assembling the circuit, here is a circuit diagram showing how all the components will be connected:
The PIR sensor, LED, buzzer, and resistor will be connected to the Arduino board via the breadboard. The Arduino will provide power and control the alarm.
Assembling the Circuit
With the components ready, it's time to assemble the alarm circuit:
Step 1: Insert the Arduino into the Breadboard
Place the Arduino board onto the breadboard. Make sure the front of the Arduino with all the labels is facing you. The Arduino will provide power to the alarm components through the 5V and GND pins.
Step 2: Connect the PIR Sensor
- Connect the VCC pin on the PIR sensor to the 5V pin on the Arduino
- Connect the GND pin on the PIR to Arduino GND
- Connect the OUT pin on the PIR to Arduino pin 2 through a 10k ohm resistor
This allows the PIR sensor to draw power from the Arduino and send motion detection signals to pin 2.
Step 3: Connect the Buzzer
- Connect the positive pin of the buzzer to Arduino pin 3
- Connect the negative pin to Arduino GND through a 220 ohm resistor
The buzzer will emit sound when activated by pin 3. The resistor limits the current flowing to the buzzer.
Step 4: Connect the LED
- Connect the positive leg of the LED to Arduino pin 4
- Connect the negative leg to GND through a 220 ohm resistor
The LED provides a visible alert whenever the PIR detects motion.
That completes the circuit! Double check that all components are securely connected.
Arduino Sketch
Now that the hardware is assembled, the Arduino needs to be programmed to trigger the alarm components when motion is detected.
I will use the Arduino IDE to write and upload the following sketch:
```cpp
// Define pins
const int pirPin = 2;
const int buzzerPin = 3;
const int ledPin = 4;
void setup() {
// Set LED and buzzer pins as Outputs
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
// Print message to serial monitor
Serial.begin(9600);
Serial.println("Motion alarm active!");
// Set PIR pin as Input
pinMode(pirPin, INPUT);
}
void loop(){
// Read PIR state
int pirValue = digitalRead(pirPin);
// If motion detected
if (pirValue == HIGH) {
// Sound buzzer
tone(buzzerPin, 1000);
// Turn on LED
digitalWrite(ledPin, HIGH);
// Print message
Serial.println("Motion Detected!");
// Delay
delay(500);
// Turn off buzzer and LED
noTone(buzzerPin);
digitalWrite(ledPin, LOW);
}
// Brief delay
delay(100);
}
```
This sketch continuously checks the PIR sensor for motion. When motion is detected, it triggers the buzzer and LED alert, then delays briefly before resetting. The serial monitor will also print out messages so I can monitor the alarm status.
After double checking the code, I can upload it to the Arduino through the USB cable.
Testing and Adjusting the PIR Sensor
Once programmed, I'm ready to test out the motion alarm!
I will need to make some adjustments to properly configure the PIR sensor:
- Adjust the sensitivity dial to control the detection range. Turning it clockwise increases sensitivity to detect motion further away.
- Adjust the time delay dial to set how long the alarm stays active after detection. Turning it clockwise lengthens the delay.
- Position and angle the PIR sensor so that it has a clear field of view to detect motion in the desired area.
I should experiment with different settings to get the alarm working just the way I want. Higher sensitivity and longer time delay can reduce false triggers, but may also miss some motions.
The PIR sensor has a detection range of up to 6 meters, but works best within 5 meters. It has a 120° field of view.
Conclusion
Building a motion-activated alarm with an Arduino and PIR sensor turned out to be both fun and informative. I learned how to connect sensor components to the Arduino and program it to control an alarm system. The finished alarm reliably detects motion and triggers visible and audible alerts.
Some ways I can expand this project include:
- Adding a second PIR sensor to cover more area
- Connecting a stronger siren instead of a buzzer for louder alarm
- Adding a kanban LED display to show alarm status messages
- Using WiFi module to send motion alerts to my phone
I now have the knowledge to build more sophisticated Arduino projects. This alarm provides a great foundation to learn and experiment!