Introduction
Building a motion sensor alarm system with an Arduino is a great way to detect intruders and get notified instantly via email. With just a few components, you can set up a simple yet effective security system for your home or office.
In this comprehensive guide, I will walk you through the entire process of constructing an Arduino-based motion sensor alarm from start to finish. I will cover:
What You Will Need
- Arduino Uno board
- PIR motion sensor
- Breadboard
- Jumper wires
- Buzzer
- Resistors
- LEDs
- Ethernet shield
- SD card module
How It Works
- Overview of each component and how they work together
- Detecting motion with the PIR sensor
- Sounding the alarm with the buzzer
- Sending email alerts
- Writing the code
Assembly and Installation
- Connecting all the components on the breadboard
- Uploading the code to the Arduino
- Setting up the Ethernet shield
- Positioning the motion sensor
Usage and Customization
- Calibrating the motion sensor
- Adjusting the sensitivity
- Modifying the code
- Expanding the project
By the end of this guide, you will have a fully functional motion sensor alarm system that alerts you via email whenever the sensor detects movement. Let's get started!
What You Will Need
To build the Arduino motion sensor alarm, you will need the following components:
Arduino Uno
The Arduino Uno is the microcontroller board that will run the code and control the alarm system. This versatile board can be powered via USB or a 9V battery.
- The Arduino Uno has 14 digital input/output pins that can be used to connect sensors and other components.
PIR Motion Sensor
A passive infrared (PIR) motion sensor detects movement and changes in infrared radiation.
-
The PIR sensor will detect when a person moves within its range, allowing the Arduino to activate the alarm.
-
The exact detection range varies by model, but is commonly between 3-10 feet.
Breadboard
A breadboard provides a convenient way to prototype circuits without soldering.
-
The breadboard allows components to be interconnected by plugging jumper wires into the holes.
-
Using a breadboard makes it easy to test out the circuit before making a permanent version.
Jumper Wires
Jumper wires are used to make connections between components on a breadboard.
-
Male-to-male jumper wires transport signals and power between the Arduino and other parts of the circuit.
-
Having an assortment of jumper wires in different lengths makes wiring the circuit much easier.
Buzzer
A buzzer or piezo speaker will sound an audible alarm when motion is detected.
-
The buzzer should be rated for 5V so it can be powered directly by the Arduino.
-
The alarm volume can be controlled by adding a resistor or potentiometer.
Resistors
Resistors limit the flow of current in a circuit.
-
A 220 ohm resistor is used with the buzzer to limit current and control volume.
-
10K ohm resistors are used with the motion sensor and LEDs.
LEDs
Indicator LEDs visually show when the device is powered on and when motion is detected.
-
A green LED powered through a 10K resistor connects to the Arduino's power pin.
-
A red LED wired through a resistor lights up when motion is sensed.
Ethernet Shield
The Ethernet shield allows the Arduino to connect to the internet via Ethernet.
-
The Ethernet shield enables the Arduino to send email alerts when motion is detected.
-
The shield fits directly onto the Arduino board and is compatible with the Arduino Uno.
SD Card Module
A micro SD card module is used to store email credentials and the recipient address.
-
The SD module communicates with the Arduino over SPI communication.
-
A library makes it easy to read and write data on the SD card.
How It Works
Now that we have covered the main components, let's take a look at how the motion sensor alarm system works.
Detecting Motion with the PIR Sensor
The passive infrared (PIR) motion sensor is the key component that detects movement and triggers the alarm.
-
The PIR sensor has two slots carved in it, each with a pyroelectric sensor.
-
These sensors detect levels of infrared radiation emitted by bodies at room temperature.
-
When a person moves within the PIR's range, the sensor detects the change in IR levels, causing its output pin to go HIGH.
-
This change signals to the Arduino that motion has been detected.
Sounding the Alarm with the Buzzer
When the Arduino receives a HIGH signal from the PIR sensor, indicating motion, it activates the buzzer to sound the audible alarm.
-
The Arduino sends power to the buzzer, causing it to emit a loud beeping sound.
-
A 220 ohm resistor is connected in series with the buzzer to limit the current and control the volume.
-
The alarm continues sounding until the Arduino stops powering the buzzer.
Sending Email Alerts
In addition to the audible alarm, the system can send an email alert when motion is detected.
-
The Ethernet shield allows the Arduino to connect to the internet over Ethernet.
-
Using the Ethernet library, the Arduino can then interact with an SMTP server to send emails.
-
The recipient address, subject, and message are stored on the SD card module.
-
When motion is detected, the Arduino reads this data from the SD card and emails an alert.
Writing the Code
The Arduino code brings the whole system together by controlling each component.
-
The code initializes the motion sensor, buzzer, LEDs, Ethernet shield, and SD card.
-
In the main loop, it continually checks the PIR sensor for motion.
-
If motion is detected, it activates the buzzer and LEDs, and sends the email alert by connecting to the SMTP server.
-
The sketch also handles calibrating the motion sensor and reading data from the SD card module.
Assembly and Installation
Now that we understand how each piece works, let's put the motion sensor alarm circuit together on a breadboard and install the code.
Connecting the Components
We will be using the Arduino Uno, so make sure it is powered off to start. Here are the steps to assemble the circuit:
-
Insert the PIR motion sensor into the breadboard. Connect the power pin to 5V and ground pin to GND.
-
Connect the output pin of the PIR sensor to digital pin 2 on the Arduino.
-
Place the buzzer in the breadboard. Connect one leg to digital pin 3 and the other leg to ground through a 220 ohm resistor.
-
Insert the green LED and connect the short leg to ground through a 10K resistor. Connect the long leg to the Arduino's 5V pin.
-
Insert the red LED and connect it similarly to the green LED, with the long leg going to Arduino pin 4.
-
Mount the Ethernet shield on top of the Arduino board. Connect the SD card module to the shield if using.
-
Use jumper wires to complete all the connections between components. Double check everything looks correct.
Uploading the Code
Before powering up the Arduino, we need to upload the motion sensor alarm code to it:
-
Open the Arduino IDE on your computer and connect the Arduino via USB.
-
Paste the Arduino sketch code into a new sketch file.
-
Go to Tools > Board and select "Arduino Uno". Also select the correct serial port it is connected to.
-
Click the Upload button to compile the code and upload it to the Arduino.
-
When done uploading, the green LED on the Arduino should turn on, indicating it is powered up and running the code.
Positioning the Motion Sensor
The last step is positioning the PIR motion sensor in the optimal location:
-
Mount the sensor on the wall or ceiling overlooking the area you want to detect motion in.
-
The PIR sensor should have a clear line of sight to where an intruder would walk.
-
Mounting it in a corner maximizes the sensor's wide field of view.
-
Adjust the orientation of the PIR sensor to aim it at the area to monitor.
-
The detection range can be tested by walking in front of it and checking if the alarm activates.
Usage and Customization
Now that your DIY Arduino motion sensor alarm is assembled and installed, let's go over how to use it and customize it for your specific needs.
Calibrating the Sensor
The PIR sensor may need some calibration to function optimally in your environment. Here are a few tips:
-
Adjust the sensitivity and detection range potentiometers on the PIR sensor itself.
-
Change the delay after a motion detection (before sending another email) in the Arduino code.
-
Set the detectionCount variable to the number of positive readings required to trigger the alarm.
-
Experiment with the sensor position to improve coverage area and reduce false alarms.
Adjusting the Sensitivity
You can make the motion sensor alarm more or less sensitive by modifying the Arduino sketch:
-
Lower the detectionCount variable so that fewer motion detections will trigger the alarm.
-
Increase the delay between sending alert emails to prevent constant notifications.
-
Change the if statement logic to only notify during certain times of day.
-
Have the alarm require multiple sensors to detect motion before activating.
Modifying the Code
There are many ways to customize the behavior by modifying the Arduino code:
-
Add an LCD display to show text alerts and status messages.
-
Use a relay to activate external lights, cameras, or other devices when motion is detected.
-
Integrate a keypad to arm/disarm the system with a code.
-
Have the Arduino text an alert to your phone instead of sending email.
-
Detect tampering by triggering if the Arduino loses power suddenly.
Expanding the Project
Some ideas for taking this project to the next level:
-
Use a PIR camera module to capture and email photos when motion is detected.
-
Connect a GSM module to allow text alerts without WiFi/Ethernet.
-
Build a web interface to control the alarm and view alerts over the Internet.
-
Add multiple sensors in different zones with different alert actions.
-
Use a passive RFID tag to arm and disarm the system.
Conclusion
Constructing your own Arduino motion sensor alarm is an enjoyable, educational project that results in a functional security system. This guide covered sourcing the components, assembling the circuit on a breadboard, installing the code, adjusting the sensitivity, and enhancing the alarm system in many ways.
With the knowledge you've gained here, you can now build an Arduino motion sensor alarm system tailored exactly for monitoring your unique environment. You may even get ideas for more advanced alarm system projects to take on next using the Arduino platform.