Making your own DIY motion sensor alarm with an Arduino is an easy and affordable way to add an extra layer of security to your home. With just a few simple components, you can build a device that will detect movement and sound an alarm, alerting you to any unwanted intruders.
What You Will Need
To build your Arduino motion sensor alarm, you will need the following components:
Arduino Board
The Arduino is the microcontroller board that will control the alarm. Any model will work, but the Arduino Uno is a good choice as it is inexpensive and widely available.
Passive Infrared (PIR) Motion Sensor
A PIR sensor detects motion by picking up changes in infrared radiation. When something moves within its range, like a person walking by, it will send a signal to the Arduino. You can get these very cheaply online.
Buzzer
A buzzer or small speaker will provide the audible alarm sound when motion is detected. A simple piezo buzzer that operates at 5V will work perfectly.
Jumper Wires
You'll need jumper wires to make all the connections between components. Both male-to-male and male-to-female wires will be useful.
Breadboard
A breadboard allows you to prototyped and connect everything without soldering. A half or full size breadboard will work.
9V Battery and Wire
An external 9V battery will power the Arduino and other components. Battery wires connect the battery to the breadboard rails.
Circuit Diagram
Here is a circuit diagram showing how everything needs to be connected:
The PIR motion sensor has three pins - 5V power, ground, and a signal pin that will input to a digital pin on the Arduino when motion is detected. The buzzer simply connects between a digital output pin on the Arduino and ground.
Setting Up the Hardware
Follow these steps to setup up the hardware for your Arduino motion alarm:
-
Insert the Arduino into the breadboard, straddling the center divide.
-
Connect the red battery wire to the 5V rail on the breadboard and the black wire to ground. This will power the Arduino when switched on.
-
Insert the PIR sensor into the breadboard. Link its 5V and ground pins to 5V and ground on the breadboard.
-
Connect the signal pin on the PIR to digital pin 2 on the Arduino.
-
Insert the buzzer into the breadboard and connect one leg to digital pin 3 on the Arduino. Connect the other leg to ground.
Once everything is wired up as shown in the diagram, you are ready to move on to loading the alarm code onto the Arduino.
Uploading the Arduino Sketch
The Arduino needs to be programmed with code to monitor the PIR sensor pin and trigger the buzzer when motion is detected.
Install the Required Libraries
You'll need to have the Arduino IDE installed on your computer. Also, install the following libraries:
- LowPower.h - used to put the Arduino into sleep between motion checks to conserve battery life.
Arduino Motion Alarm Code
Here is the full Arduino code needed for the motion sensing alarm:
```cpp
/ Motion Sensor Alarm Code /
// Include required libraries
include
// Pin definitions
const int pirPin = 2; // PIR Out pin
const int buzzer = 3; // Buzzer pin
void setup() {
// Set buzzer as output
pinMode(buzzer, OUTPUT);
// Set PIR pin as input
pinMode(pirPin, INPUT);
// Start serial monitor
Serial.begin(9600);
}
void loop() {
// Read PIR state
int sensorStatus = digitalRead(pirPin);
// Print results to serial monitor
Serial.print("Sensor status: ");
Serial.println(sensorStatus);
// If motion detected
if (sensorStatus == HIGH) {
// Sound alarm
digitalWrite(buzzer, HIGH);
// Delay to avoid rapid fire alarms
delay(500);
} else {
// No motion, turn off alarm
digitalWrite(buzzer, LOW);
// Enter low power sleep mode until motion detected
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}
}
```
The key points are:
- The PIR sensor state is read each loop iteration and saved to
sensorStatus
- If motion detected (
HIGH
value) the buzzer is turned on - A delay avoids multiple rapid alarms
- With no motion, the buzzer is off and the Arduino sleeps to conserve battery
Upload Sketch to Arduino
-
Copy the code into a new sketch in the Arduino IDE. Save it.
-
Make sure your Arduino is connected to your computer via USB.
-
Select the correct board type and COM port.
-
Click upload to compile and upload the code.
Once complete, the Arduino will run this motion sensing sketch whenever powered on.
Using Your Motion Alarm
You now have a fully functional DIY security alarm with the Arduino and PIR motion sensor!
To use it:
-
Make sure the 9V battery is connected and switched on to power the Arduino and components.
-
Place the PIR sensor in the location you want to detect motion. Adjust its directional range as needed.
-
Whenever the PIR detects movement, the buzzer will loudly sound, alerting you.
-
The alarm will trigger for a few seconds before resetting.
-
Between alarms, the Arduino will sleep to conserve battery life so it can run for long periods.
You can enhance the alarm further by:
-
Adding a second PIR sensor to cover a larger area
-
Using a louder buzzer or adding a bright LED
-
Connecting the alarm to automatically SMS text you
-
Linking it to existing home automation systems
So with very little effort you now have a smart motion detecting alarm system to improve security using DIY Arduino technology!