How to Build a Simple Arduino-Based Motion Sensor Alarm That Will Keep Your Home Safe

Using an Arduino microcontroller and a few basic components, you can build an inexpensive motion sensor alarm that will alert you when it detects movement in your home. This type of alarm is perfect for providing an extra layer of security and peace of mind.

What You Will Need

Building a motion sensor alarm with an Arduino is a pretty straightforward electronics project. Here are the main components you will need:

Arduino Microcontroller

The Arduino is the brain of the alarm system. I used an Arduino Uno, but any Arduino board should work for this project. The Arduino will monitor the sensor and activate the alarm when motion is detected.

PIR Motion Sensor

A passive infrared (PIR) motion sensor is used to actually detect movement and send a signal to the Arduino. This type of sensor works by detecting infrared radiation emitted by warm objects like people and animals. They are inexpensive and easy to integrate with an Arduino.

Buzzer or Speaker

You'll need some kind of audio output device like a buzzer or speaker to serve as the alarm. When the Arduino detects motion, it will activate this component to create sound.

Jumper wires

Jumper wires are used to connect the various components together. Male-to-female jumper wires work well for bridging the Arduino and other components.

Breadboard

A breadboard provides a convenient way to prototype circuits without soldering. With a breadboard, components like the PIR sensor can simply be plugged in with jumper wires.

9V Battery Pack

An Arduino can be powered directly through its USB port when connected to a computer. But for a standalone alarm, you'll want a portable power source like a 9V battery pack.

Circuit Diagram

Here is a circuit diagram showing how to connect the components:

The PIR motion sensor has three pins: 5V power, ground, and a signal pin. The signal pin connects to a digital input on the Arduino, in this case pin 2. The buzzer or speaker connects between pin 3 on the Arduino and ground.

Setting Up the Sensor

PIR motion sensors are easy to set up with an Arduino. Here are the basic steps:

  1. Connect the +5V and GND pins on the sensor to the corresponding power pins on the Arduino.

  2. Connect the signal pin on the sensor to a digital I/O pin on the Arduino. I used pin 2 in the diagram above.

  3. The PIR sensor requires a short warm up period before it will detect motion accurately. Allow 1-2 minutes warmup time when first powered on.

  4. The PIR sensor has a field of view of about 120 degrees, so position it strategically to cover the area you want to monitor.

  5. Adjust the sensitivity dial on the PIR sensor as needed. Turning it clockwise increases sensitivity.

Arduino Sketch to Detect Motion

The Arduino needs to be programmed to watch for a signal from the PIR sensor and trigger the alarm when motion is detected.

Include the Required Libraries

```c

include

```

The Adafruit_SleepyDog library is used for managing power savings.

Initialize Constants

c
const int motionSensor = 2; // PIR connected to digital pin 2
const int alarm = 3; // Buzzer/speaker on digital pin 3

Set up constants for the pin numbers used.

Setup Function

The setup() function initializes the pins:

```c
void setup(){

pinMode(motionSensor, INPUT); // Set motion sensor pin as input
pinMode(alarm, OUTPUT); // Set buzzer/speaker as output

Watchdog.enable(8000); // Enable watchdog timer
}
```

This sets pin 2 as an input to monitor the PIR sensor, and sets pin 3 as an output to activate the alarm buzzer/speaker. It also enables the watchdog timer to manage the sleep mode.

Main Loop

The main program loop checks the PIR sensor for motion and triggers the alarm if detected:

```c
void loop(){

if(digitalRead(motionSensor) == HIGH){ // If motion detected

digitalWrite(alarm, HIGH); // Sound alarm

delay(2000); // Keep alarm on for 2 seconds

}

digitalWrite(alarm, LOW); // Turn alarm off

Watchdog.sleep(10000); // Sleep for 10 seconds

}
```

This simple loop checks the sensor pin every 10 seconds. If motion is detected, it sounds the alarm for 2 seconds by setting the buzzer pin HIGH.

Testing and Using the Motion Sensor Alarm

Once you have everything assembled and the sketch uploaded to the Arduino, test the alarm:

That's it! You now have a working motion sensor alarm for your home using an Arduino, PIR sensor, and a few other simple components. This project can easily be expanded by adding additional sensors, a microSD card to log activity, or integrating it with home automation systems.