Introduction

Motion-activated alarms are useful for home security, automating lights, and other DIY projects. With just a few components, you can build a simple alarm that detects motion using an Arduino microcontroller and a PIR (passive infrared) sensor.

This article will walk you step-by-step through selecting components, assembling the circuit, programming the Arduino, and adjusting settings to get your motion-activated alarm working. You will also learn troubleshooting tips in case you run into any issues.

Required Components

Building this motion alarm requires just a few main components:

Arduino Microcontroller

The Arduino Uno is the most popular basic Arduino board. It has 14 digital input/output pins to connect sensors and other components, as well as 6 analog inputs. The Arduino will control the alarm based on input from the PIR sensor.

PIR Motion Sensor

This sensor detects infrared radiation emitted by human bodies that come within its range. It has a 3-pin connection: power, ground, and a digital out pin that goes HIGH when motion is detected.

Buzzer

An active or passive piezo buzzer will create the alarm sound when motion is detected. An active buzzer has polarity so pay attention when connecting.

Jumper wires

Jumper wires are used to make connections between components. You will need both male-to-male and male-to-female versions.

Breadboard

A solderless breadboard has connected rows under the board to easily prototype circuits before soldering.

Resistor (optional)

A 100-470 ohm resistor can help protect the Arduino pin from too much current to the buzzer.

Circuit Assembly

Following proper circuit wiring methods is crucial for building your alarm correctly:

Carefully check all connections match the circuit diagram before powering on.

Arduino Programming

The Arduino code for this project just needs to read the state of the PIR sensor pin and trigger the buzzer when motion is detected.

Setup

In the setup() function, initialize pin 9 as an input for the sensor and pin 8 as an output for the buzzer:

c
pinMode(9, INPUT);
pinMode(8, OUTPUT);

Main Loop

The loop() function will continuously check the PIR pin state and trigger the alarm if it goes HIGH:

c
if (digitalRead(9) == HIGH) {
digitalWrite(8, HIGH); // Buzzer on
}
else {
digitalWrite(8, LOW); // Buzzer off
}

This basic code is all you need to detect motion and activate the alarm!

Adjusting Sensitivity and Delay

The PIR sensor has settings to adjust detection sensitivity and delay time.

Experiment with both pots to get the alarm working optimally for your situation. High sensitivity may cause false alarms. The time delay prevents the alarm constantly turning on and off. Start with lower sensitivity and a shorter 3-5 second delay.

Troubleshooting Issues

If your motion alarm isn't working, here are some steps to troubleshoot:

With some adjustments, you should be able to get your homemade motion alarm detecting properly. This simple Arduino project can then be expanded by adding more sensors, triggers, or an LCD display. The possibilities are endless!

Summary

Building a motion-sensing alarm with an Arduino and PIR sensor is an easy DIY security project using basic components. Follow the wiring diagram to connect the pieces on a breadboard. Program the Arduino to detect the sensor state and trigger the buzzer. Adjust the PIR settings to optimize sensitivity and delay time. With just a little bit of tweaking, you'll have a working alarm system to detect intruders or automate lights and other devices.