Introduction
Building a motion sensor alarm system with Arduino is an easy weekend project that can add security and convenience to your home or office. The alarm system will detect motion using a passive infrared (PIR) sensor and send you email alerts so you can respond promptly.
In this comprehensive guide, I will walk you through every step of constructing the alarm from start to finish. I'll cover:
What You Will Need
- Arduino microcontroller board
- PIR motion sensor
- LCD screen
- Buzzer
- WiFi module
- Jumper wires
- Breadboard
- 9V battery and battery clip
How It Works
- The PIR sensor detects motion and sends a signal to the Arduino
- The Arduino processes the signal and sounds the buzzer alarm
- It also sends an email alert via the WiFi module
- The LCD screen displays messages about the alarm status
Setting Up the Electronics
- Connecting the PIR sensor, buzzer, LCD and WiFi module to the Arduino
- Installing necessary libraries
Writing the Arduino Sketch
- Detecting motion with the PIR sensor
- Sounding the buzzer alarm
- Sending email alerts
- Displaying alarm status on the LCD
Completing and Installing the Alarm
By the end, you will have a fully functioning motion alarm that notifies you whenever it detects movement. Let's get started!
What You Will Need
The following components are required to build the Arduino motion alarm:
Arduino Board
The brains of the alarm is an Arduino microcontroller board. The standard Arduino Uno will work well. The Arduino processes input from the PIR sensor and controls the outputs.
Arduino Uno Board
PIR Motion Sensor
A passive infrared or PIR motion sensor detects movement and triggers the alarm. It consists of an infrared sensitive element that detects temperature changes caused by motion.
PIR Motion Sensor
The sensor has three pins - power, ground, and signal. When it detects movement, the signal pin outputs a high voltage.
LCD Display
A liquid crystal display (LCD) screen will show status messages like "System Armed" or "Motion Detected." A basic 16x2 LCD display with an I2C interface works well.
16x2 LCD Display
The I2C interface only needs 4 wires to connect to Arduino.
Buzzer
An active buzzer will sound an audible alarm when motion is detected. Connect the positive and negative pins to Arduino.
Active Buzzer
WiFi Module
To send email alerts, you need a WiFi module like the ESP8266. It will connect to your WiFi network and handle emails.
ESP8266 WiFi Module
Jumper Wires and Breadboard
Use jumper wires to make all the connections between components. A breadboard provides a convenient way to prototype.
Jumper Wires and Breadboard
9V Battery and Clip
An external 9V battery and clip will power the Arduino and other components. This provides portable operation.
9V Battery and Clip
How the Motion Alarm Works
Here is an overview of how the parts work together:
-
The PIR sensor detects motion in its field of view. It outputs a HIGH signal on its digital pin when triggered.
-
The Arduino reads this input pin. When motion is detected, it:
-
Flashes an alert message on the LCD display
- Sounds the buzzer alarm
-
Uses the WiFi module to send an email notification
-
The system will activate the alarm every time the PIR sensor detects movement.
-
The Arduino is powered from the 9V battery so the alarm works without being plugged in.
Setting Up the Electronics
With all the components ready, it's time to assemble the motion alarm on a breadboard and connect everything to the Arduino.
Breadboard Layout
Here is an example layout showing where each component goes:
Sample Breadboard Layout
- The Arduino straddles the center ditch with power and ground pins on each side
- The PIR sensor connects to power, ground, and a digital pin
- The LCD screen uses I2C pins and power/ground
- Buzzer and WiFi module also go across the side rails
Connecting Components
Next, use jumper wires to make the connections between all the electronics:
PIR Sensor
- VCC → 5V pin on Arduino
- GND → GND pin
- OUT → Digital pin 2
LCD Screen
- VCC → 5V
- GND → GND
- SDA → Analog pin 4
- SCL → Analog pin 5
Buzzer
- Positive lead → Pin 11
- Negative lead → GND
WiFi Module
- 3.3V → 3.3V pin
- GND → GND
- TX/RX pins → Arduino TX/RX pins 0 & 1
The Arduino, PIR sensor, LCD, and buzzer will be powered from the 9V battery through the Vin pin.
Now all the components are wired up and ready to be programmed!
Writing the Arduino Sketch
The Arduino software runs code called sketches to operate the motion alarm. The sketch will:
- Read the PIR sensor pin
- Detect motion and trigger the alarm
- Display status on the LCD
- Send email alerts through the WiFi module
We need to include some libraries:
```c
include // LCD library
include // WiFi module library
```
In the setup, we initialize the LCD and buzzer pin:
```c
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD address, columns and rows
pinMode(buzzer, OUTPUT);
```
The main loop will continuously check the PIR sensor for motion detection:
```c
void loop() {
if (digitalRead(pirPin) == HIGH) {
// Motion detected!
digitalWrite(buzzer, HIGH); // Sound alarm
sendEmailAlert(); // Send email
lcd.setCursor(0,0);
lcd.print("Motion Detected!"); // Print LCD alert
}
}
```
If motion is detected, it will trigger the buzzer, LCD, and email alert.
The sendEmailAlert()
function uses the WiFi module to send an email:
```c
void sendEmailAlert() {
// Connect to WiFi
// Set up SMTP server credentials
// Send email message
lcd.setCursor(0,1);
lcd.print("Email Alert Sent!");
}
```
This Arduino sketch completes the programming of the motion alarm.
Completing and Installing the Alarm
After all the electronics are assembled and programmed, there are just a few final steps:
-
Mount the PIR sensor in the desired location with line of sight to where motion needs to be detected.
-
Optionally enclose the Arduino, breadboard, and other parts in a housing for better protection and mounting.
-
Power the Arduino from the 9V battery pack.
-
Verify that the WiFi connects and test the email alerts.
-
Adjust PIR sensor orientation or sensitivity if needed.
Now you have a DIY Arduino motion alarm system that will notify you through sound, text and email whenever it detects movement!
Some ways this can be used:
- Security alarm for home, office, or shed
- Intruder alert for apartment, dorm room, etc.
- Driveway alert to indicate a car is arriving
- Barn or chicken coop alarm to detect animals
- Sensor for a more complex home automation system
The possibilities are endless for enhancing your projects with motion sensing capabilities.
In summary, the key steps to build the Arduino motion alarm are:
-
Get the components: Arduino, PIR sensor, LCD, buzzer, WiFi module, etc.
-
Assemble the circuit on a breadboard with jumper wires.
-
Program the Arduino sketch to detect motion and trigger alarms.
-
Install the sensor and test the WiFi email alerts.
With just a bit of effort, you can construct a fully-featured motion alarm system with email notifications using Arduino!