Arduino security system with motion sensors

Photo of author

By Jackson Taylor

Home » Arduino » Arduino security system with motion sensors

As an Amazon Associate we earn from qualifying purchases.

In today’s world, ensuring the safety of your home or business is more important than ever. One of the most effective ways to secure your property is by using a motion sensor-based security system. The Arduino platform offers a versatile and affordable solution to build such systems, combining motion sensors with easy-to-program microcontrollers. In this article, we’ll dive into how you can create your own Arduino-based security system with motion sensors and why it’s an excellent option for home or office security.

Why Choose Arduino for Security Systems?

Arduino’s open-source nature, combined with its ease of use, makes it a popular choice for DIY enthusiasts looking to create their own security solutions. With Arduino, you can design a system that fits your specific needs, whether it’s for monitoring movement in certain areas or triggering alarms. Moreover, Arduino’s cost-effectiveness and flexibility allow for integrating various components such such as cameras, sirens, and remote notifications.

How Arduino Motion Sensors Work

At the core of any Arduino security system is the motion sensor. These sensors detect movement by identifying changes in the surrounding environment, such as heat signatures or light variations. The most commonly used motion sensors in Arduino-based security systems are Passive Infrared (PIR) sensors. PIR sensors work by detecting infrared radiation emitted by objects in motion.

Hardware Hack

Stop Buying New Batteries for Your Tech

Electronics are expensive, but their power sources don't have to be. Discover the simple engineering trick to recondition dead batteries and bring your gadgets back to 100% capacity.

Watch the Free Video

When the sensor detects movement, it sends a signal to the Arduino board, which then processes the information and triggers an action, like activating an alarm or sending a notification.

Choosing the Right Motion Sensor for Your System

Selecting the right motion sensor for your security system is crucial. Here are a few options to consider:

1. PIR Sensors

PIR sensors are the most common type used in motion detection systems. They are simple to use and relatively inexpensive. PIR sensors detect changes in infrared radiation, making them ideal for detecting human movement.

See also
Arduino security system with remote control

2. Ultrasonic Sensors

For longer-range detection, ultrasonic sensors emit sound waves and measure the time it takes for the waves to bounce back. These sensors can detect motion at greater distances than PIR sensors, but they may be more complex to set up.

3. Microwave Sensors

Microwave sensors are capable of detecting movement through walls and other obstacles. These are more advanced and expensive but offer higher detection accuracy and longer range.

Building an Arduino Motion Sensor Security System

Materials Needed:

Step-by-Step Guide:

Step 1: Connect the PIR Sensor to the Arduino

First, connect the PIR sensor to the Arduino board. The sensor has three pins: VCC (power), GND (ground), and OUT (signal). Connect the VCC pin to 5V on the Arduino, the GND pin to the ground, and the OUT pin to a digital input pin (e.g., pin 7).

Step 2: Wire the Buzzer or Siren

Next, connect a buzzer or siren to the Arduino to sound an alert when motion is detected. One pin of the buzzer should go to a digital output pin on the Arduino (e.g., pin 8), while the other goes to ground.

Step 3: Write the Code

Now, write the code to program the Arduino. The code should check for motion detection from the PIR sensor and trigger the buzzer when movement is detected. You can also add an LED to indicate when the system is active. Here’s a basic code snippet:

int sensorPin = 7;  // Pin connected to PIR sensor
int buzzerPin = 8;  // Pin connected to Buzzer
int sensorState = 0; // Variable to store sensor status

void setup() {
 pinMode(sensorPin, INPUT); // Set PIR sensor pin as input
 pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output
 Serial.begin(9600);
}

void loop() {
 sensorState = digitalRead(sensorPin); // Read the PIR sensor
 if (sensorState == HIGH) {       // If motion is detected
  digitalWrite(buzzerPin, HIGH);    // Activate buzzer
  Serial.println("Motion detected!");
 } else {
  digitalWrite(buzzerPin, LOW);    // Deactivate buzzer
 }
}

Step 4: Test the System

Upload the code to your Arduino board and test the system. When you walk in front of the PIR sensor, the buzzer should sound, indicating that motion has been detected. You can modify the code to include other actions, such as sending a text message or triggering a camera to capture images.

See also
Arduino line follower robot using color sensors

Enhancing Your Arduino Security System

While the basic setup is functional, you can enhance the system further by integrating additional features. Here are a few ideas:

Sustainable Tech

Keep Toxic E-Waste Out of Landfills

Don't throw away your failing laptop, phone, or car batteries. Learn how to recondition them at home in just a few hours. It's better for the planet—and your wallet.

Learn How It Works

1. Adding Wireless Connectivity

By integrating a Wi‑Fi or GSM module, you can receive real‑time alerts on your smartphone whenever the system detects motion. This feature is useful for remote monitoring.

Wi‑Fi Module (ESP8266):

You can use the ESP8266 module to connect your Arduino to the internet, allowing it to send notifications via email, text, or even to a web server.

GSM Module:

Alternatively, a GSM module can send SMS alerts directly to your phone. This is a great option if you don’t have access to Wi‑Fi but still want to stay updated.

2. Integration with Surveillance Cameras

To enhance security further, consider adding a camera to your system. When motion is detected, the Arduino can trigger the camera to take a snapshot or record a video, which can be stored locally or uploaded to a cloud service.

3. Customizing Alerts

You can program the Arduino to create custom alerts based on the type of movement detected. For instance, the system could distinguish between a pet and a human and send different types of notifications for each.

Safety and Security Tips

  • Positioning Sensors Correctly: Ensure your PIR sensors are placed in areas that offer a clear line of sight and avoid false readings due to pets or environmental factors.
  • Power Supply: Always use a stable power supply. If you’re using a battery, make sure it’s rechargeable or has a long lifespan to prevent sudden failures.
  • Enclosure: Consider housing your Arduino and components in a protective enclosure to shield them from environmental damage.

Using a Motion Sensor to Trigger a Camera

Many people who build this project want more than an alarm. They want a camera that records when something moves. An Arduino Uno can read a PIR sensor easily, but it can’t capture or process images on its own, so you need a second piece of hardware for the camera. There are two common ways to set this up:

  • Use a board with a built-in camera. Boards such as the ESP32-CAM can read the PIR output on one of their input pins and take a photo when it goes high. The photo can be saved to a microSD card or sent over Wi-Fi, so you may not need the Uno at all.
  • Keep the Arduino as the trigger. The Arduino reads the PIR sensor and sends a signal, through a spare pin or over serial, to a separate camera device, such as a Raspberry Pi with a camera module. That device takes the picture.
See also
RGB LED control with Arduino

Add a short cooldown in your code after each trigger. A PIR sensor can stay high while someone moves in front of it, and without a delay your camera may save dozens of nearly identical photos. Camera boards also tend to draw more current than a simple sensor and buzzer circuit, so give them a stable power supply. A weak supply is a common cause of random resets.

It also helps to know the limits of a PIR sensor when you think about motion tracking. It only tells you that something warm moved within its field of view. It can’t tell you where the person is. To get a rough form of tracking, you can place several PIR sensors facing different zones and use servos to point the camera toward the zone that triggered. To follow a person within the frame, you need image-based detection running on a more capable board, which is a bigger project than the basic build above.

Conclusion

An Arduino‑based motion sensor security system is an affordable, customizable, and effective way to enhance the safety of your home or business. By following the steps outlined above, you can easily create a motion‑detecting alarm system and add advanced features like remote alerts and camera integration. Whether you’re a beginner or an experienced maker, Arduino provides endless possibilities to tailor your security system to meet your needs. With the right components, programming, and a little creativity, you can have a professional‑grade security system in no time.

Revive Your Dead Electronics

Got a drawer full of dead gadgets or a failing car battery? Instead of paying a premium for replacements, use this simple trick to easily recondition them right from home.

See How It Works