Building a motion sensor alarm with Arduino is an easy and inexpensive way to add security to your home or office. With just a few electronic components, you can construct a system that will sound an audible alarm and flash lights when motion is detected. The whole project can be completed in around 15 minutes.

What You Will Need

To build the motion sensor alarm, you will need:

Hardware

Tools

Circuit Diagram

The circuit diagram below shows how all the components are connected.

The PIR motion sensor has three pins - VCC, OUT and GND. VCC and GND are connected to 5V and GND on the Arduino. The OUT pin is connected to Arduino digital pin 2.

The buzzer positive leg is connected to Arduino pin 3 and the negative leg is connected to GND.

The LED positive legs are connected through resistors to Arduino pins 4, 5 and 6. The negative legs are connected to GND.

Setting Up the Hardware

Follow these steps to setup the motion sensor alarm circuit on a breadboard:

  1. Insert the Arduino into the breadboard. Connect the GND pin to the negative rail and the 5V pin to the positive rail.

  2. Insert the PIR sensor into the breadboard. Connect the VCC pin to the positive rail and the GND pin to the negative rail.

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

  4. Insert the buzzer into the breadboard. Connect the positive leg to Arduino pin 3 and the negative leg to the negative rail.

  5. Insert the LEDs into the breadboard. Connect the positive legs through resistors to Arduino pins 4, 5 and 6. Connect the negative legs to the negative rail.

  6. Connect the 9V battery to the Arduino VIN and GND pins to power the circuit.

Once the hardware is setup, you are ready to program the alarm.

Arduino Motion Sensor Alarm Code

The Arduino sketch to program the motion sensor alarm is simple. It sets the sensor pin and buzzer pin as outputs, and the LED pins as inputs.

In the loop(), the code reads the state of the sensor. If motion is detected (sensor pin is HIGH), it sounds the buzzer and turns on the LEDs.

Here is the full Arduino code:

```cpp
// Motion Sensor Alarm

int buzzer = 3; // buzzer pin
int redLed = 4; // red LED pin
int greenLed = 5; // green LED pin
int blueLed = 6; // blue LED pin

int sensor = 2; // sensor pin

void setup() {

pinMode(buzzer, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);

pinMode(sensor, INPUT);
}

void loop(){

if (digitalRead(sensor) == HIGH) {

// sound alarm
digitalWrite(buzzer, HIGH);

// flash LEDs      
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, HIGH);  
digitalWrite(blueLed, HIGH);
delay(200);

digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW); 
digitalWrite(blueLed, LOW);
delay(200);

}
else {
noTone(buzzer); // turn off alarm

digitalWrite(redLed, LOW); // turn off leds
digitalWrite(greenLed, LOW);
digitalWrite(blueLed, LOW);

}
}
```

Upload this code to your Arduino board and open the serial monitor. Whenever motion is detected by the sensor, the alarm will sound and the LEDs will flash!

Testing and Using the Motion Sensor Alarm

Once the code is uploaded, do a quick test to ensure it works correctly:

Some ways you can use your DIY motion sensor alarm:

The great thing about this project is that it takes just 15 minutes to assemble, but has dozens of practical uses around the home and office!

Conclusion

Building a motion sensor alarm with Arduino is simple and requires minimal components. Within 15 minutes you can construct the hardware circuit and write a basic Arduino program to have it up and running. This is a great beginner Arduino project to learn about inputs, outputs and Arduino code.

The alarm can easily be expanded by adding a camera to take photos, WiFi module to send alerts to your phone, or speakers to play custom alarm sounds. Endless possibilities!

Let me know in the comments if you build this motion sensor alarm or need any help with the project. Now get detecting!