Making a motion sensor alarm with an Arduino is a great electronics project for beginners. With just a few basic components, I can build an alarm that will detect movement and sound an alarm. This project is simple enough for beginners but also teaches some core concepts that can be built upon for more advanced projects.
What You Will Need
To build this motion sensor alarm, you will need:
- An Arduino Uno or compatible microcontroller board
- A PIR motion sensor to detect movement
- A buzzer to sound the alarm
- A breadboard and jumper wires to connect the components
- A 9V battery and 9V battery clip (or USB power supply)
I recommend getting an Arduino starter kit that includes many of these parts to get started. You will also need the Arduino IDE installed on your computer.
How a PIR Motion Sensor Works
The key component that makes this project work is the passive infrared (PIR) motion sensor. This simple sensor detects infrared radiation that is given off by warm bodies passing within its range.
Inside the PIR sensor are two slots that detect infrared. The slots are somewhat offset so that an infrared source passing by will trigger one slot slightly before the other. This delay causes a voltage difference that is detected by the sensor circuitry.
When motion is detected, the PIR sensor will output a short high pulse signaling that motion was found. We can detect this pulse in our Arduino code to sound the alarm.
Circuit Diagram
The circuit for this motion sensor alarm is very simple:
- The PIR Sensor connects to 5V power and ground.
- The digital output pin of the sensor connects to a digital input pin on the Arduino.
- The positive lead of the buzzer connects to Arduino pin 9. The negative lead connects to ground.
Here is a circuit diagram showing the connections:
Arduino Code to Detect Motion and Sound Alarm
With the circuit assembled, the Arduino code will detect motion and activate the alarm.
The code does the following:
- Sets the PIR sensor pin as an input
- Sets the buzzer pin as an output
- Continuously checks the PIR sensor pin
- If motion is detected, turns the buzzer on for 1 second
Here is the full Arduino code:
```cpp
// Motion Sensor Alarm
int pirPin = 3; // PIR Out pin
int buzzer = 9; // Buzzer pin
void setup() {
pinMode(pirPin, INPUT);
pinMode(buzzer, OUTPUT);
}
void loop() {
if (digitalRead(pirPin) == HIGH) {
digitalWrite(buzzer, HIGH);
delay(1000);
digitalWrite(buzzer, LOW);
}
}
```
This code is very simple but effective. Whenever motion is detected, it will sound the alarm for one second before resetting.
Putting it All Together
Follow these steps to build the motion sensor alarm with your components:
- Build the circuit as shown in the diagram above on your breadboard.
- Upload the Arduino sketch to your board.
- Open the Arduino serial monitor and ensure the code is running.
- Power your Arduino board with a 9V battery or USB supply.
- Wave your hand in front of the PIR sensor. The buzzer should sound for 1 second when motion is detected.
- Adjust the PIR sensor potentiometer as needed to change sensitivity.
- Optionally enclose your project in a box or casing for a self-contained alarm.
And that's it! With just a simple Arduino circuit, we can detect motion and sound an alarm. This is a great starter project to learn the basics of Arduino, sensors, and alarm systems.
Some ways you could expand this project further:
- Add an LCD display to show motion alerts
- Connect it to WiFi to send motion alerts to your phone
- Record motion timestamp data to an SD card
- Add a remote control to arm/disarm the alarm
The possibilities are endless! With the core concepts from this project you'll be able to create much more advanced motion sensing projects.
Let me know in the comments if you have any questions about building your own motion sensing alarm with Arduino!