Introduction
Having a motion detector that can alert you when someone enters a room can be a useful home automation project. With an Arduino microcontroller and a few simple components, you can build your own motion sensing system easily.
In this article, I will walk through the full process of creating an Arduino-based motion detector from start to finish. I'll cover:
- The components you need
- How to assemble the circuit
- Coding the Arduino
- Setting up the motion detector
- Connecting it to other devices for alerts
By the end, you'll have the knowledge to build your own motion detection system using Arduino. Let's get started!
Required Components
To build the motion detector, you will need:
- An Arduino Uno or compatible microcontroller board
- A HC-SR501 PIR motion sensor module
- A breadboard and jumper wires for prototyping
- A buzzer or other alert device
- A 5V DC power supply like a USB cable or DC wall adapter
The key component is the HC-SR501 PIR (passive infrared) motion sensor. This simple module detects movement using infrared energy and outputs a digital signal when motion is detected.
The Arduino reads this signal and can trigger the buzzer or other alerts accordingly. The breadboard helps connect it all together during testing.
Assembling the Circuit
With the components ready, it's time to assemble the circuit on the breadboard. Follow these steps:
- Place the Arduino and connect to power (USB or DC adapter)
- Insert the PIR sensor - make sure it can "see" the area you want to detect motion
- Connect jumper wires from the PIR VCC pin to Arduino 5V pin
- Connect GND pin on PIR to GND on Arduino
- Connect output pin on PIR to a digital I/O pin on Arduino (e.g. pin 2)
- Connect one pin of buzzer to Arduino pin 3
- Connect the other buzzer pin to Arduino GND
That completes the basic motion detector circuit! The PIR sensor will detect motion and output a signal to the Arduino. The Arduino code will then sound the buzzer when triggered.
Coding the Arduino
Now that the hardware is set up, it's time to program the Arduino to react to motion:
```c++
// Set pin numbers
const int pirPin = 2;
const int buzzerPin = 3;
// Variables
int pirValue; // Place to store read PIR value
void setup() {
// Set buzzer and PIR pin modes
pinMode(buzzerPin, OUTPUT);
pinMode(pirPin, INPUT);
}
void loop() {
// Read PIR sensor value
pirValue = digitalRead(pirPin);
// If motion detected (HIGH signal)
if (pirValue == HIGH) {
// Sound buzzer
digitalWrite(buzzerPin, HIGH);
// Else if no motion (LOW signal)
} else {
digitalWrite(buzzerPin, LOW);
}
}
```
This simple sketch reads the PIR sensor pin, and sounds the buzzer when motion is detected. Upload it to your Arduino and you should have a working motion alarm!
Setting Up the Motion Detector
Now it's time to actually use the motion detector. Follow these tips:
- Position the PIR sensor properly to cover the area you want to monitor, like a room entrance
- Adjust PIR sensitivity and delay as needed (see module specs)
- Set up Arduino power with a wall adapter so it runs continuously
- Optionally enclose the Arduino and breadboard to protect the circuit
Make sure to test detection at various distances and positions. Adjust sensor angle or sensitivity if needed until motion is reliably detected.
Alerting You Remotely
The basic system sounds a local buzzer alarm. But you can also connect your motion detector to other devices for remote alerts when detection is triggered:
- Add a WiFi module to send push notifications to your phone
- Connect a camera to capture photos of who enters the room
- Use an IoT platform like IFTTT to activate lights, sirens, messages, etc
- Interface with a security system to trigger wider alarms
The options are endless! Use your creativity and existing smart home devices to build the ideal motion sensing system.
Conclusion
Creating a homemade Arduino-based motion detector is an easy and educational project for builders of all skill levels. With just a few common components, you can set up a sensor that reliably detects motion in any room or space. Pair it with other connected devices and you can construct a sophisticated home automation system that gives you peace of mind. I encourage you to experiment further with the code and circuit as you tailor it to your own needs.