Arduino Controlled Motion Sensor




In this Instructable, I'll be explaining how to build a motion activated alarm! It uses an Arduino microcontroller, a PIR (passive infrared) sensor, and a type of alarm. You can use an LED indicator, a buzzer, or a piezo. That's the easy part. I will also be showing how to display to a character LCD screen, and over serial communication with a pair of XBee chips to relay the information to your computer! We will start with the basic LED lighting up though. That is also the best way to test the functionality of your PIR sensor to ensure it is working.

You should have a little bit of experience with Arduino to do this project. There is enough detail in this instructable to build it without but it would help to understand if you wanted to expand on it. Enough small talk, lets begin!

After uploading, open the serial terminal as well. The output can be read from there.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Basic LED/Buzzer

Materials needed:
1. Any Arduino or a deviation of it should work perfectly fine for this. $30 for the standard Uno. As long as it can be programmed by the Arduino IDE you will be fine.
2. A PIR sensor. I am using the Parallax PIR sensor. You can get it for about $10. The one from Adafruit should work fine if you set it on H (retrigger) which I will explain later. The one from SparkFun has the signal pin that goes LOW (off) on detection so there will be some code changing. I do not know exactly how that one outputs signals.
3. A prototyping breadboard will make this much easier. Otherwise you will be soldering pins. This should be anywhere from $5 to $15 depending on what kind you get.

The Parallax PIR sensor I use requires a 10-60 second warm up time in order to calibrate itself. It is best to have no movement while it is calibrating. I give it 30 seconds, which I incorporate into the code.

Here is how I have my PIR set up. It is built on a shield that fits over the Arduino but the pins are the same.

My PIR module has the jumper on the back set on H - retrigger. The pin will stay HIGH the motion is continuous. The signal pin is hooked up to Arduino pin 4. The LED is hooked up to Arduino pin 5. The other two white pins do not matter in the picture, those are soldered to my shield from another project.

During the warmup period, the red LED blinks two times per second. After 30 seconds, the LED will stop blinking rapidly. Generally the PIR will not blink that rapidly in normal use so you will know when the warmup period ends. Check the images for the wiring. Arduino PDE file is attached.

To use a buzzer, simply wire that up in place of the LED and remove the resistor. You should use a transistor if the buzzer is not a piezo and is in a white boxy form that generates the buzz by vibrating against a plastic piece.

Step 2: Wireless Transmission!

This part isn't all that hard. You just need two XBee modules and a power supply for the receiver unit. It takes the very common 5.5mm center positive barrel jack. Input anywhere from 7v to 12v is fine. It also works fine at 6v from four AA batteries. It will not be enough to add an LCD since the voltage is actually slightly lower than 5v due to the voltage drop through the voltage regulator.

The easiest method would be an XBee shield plugged into the board and a receiver XBee on the other side. The receiver can be a simple XBee attached to an FTDI USB Serial converter.

You can use a simple XBee breakout board as well. If being used with a 5v Arduino, it MUST have a 5v to 3.3v logic circuit. 5v will toast an XBee. The SparkFun XBee Explorer and XBee Adapter Kit from Adafruit both have this circuit. Connect the Arduino TX pin to DIN on the XBee board and RX to DOUT.

The USB side will be the same. If using an XBee USB Adapter, it doesn't need any kind of wiring. Program the XBees with the standard command set and 9600bps and you are set.

Step 3: Going Advanced!

The Arduino is very modular. The rest of these pictures will show me building on an Arduino Mega but the code will work with any Duemilanove compatible Arduino. For example, my design has the LCD. My Arduino also has the code for sending data via XBee. You can see the TX led light up each time the PIR is triggered.

In the video, the warmup time is sped up because it has already been running for a few minutes. I simply reset as it makes for an easier video demonstration. The pinouts are inside the .pde and this is only for you to try if you know what you are doing! Ask any questions in the comments.

There is so much more that can be done with this, the rest is up to your imagination and abilities!

Microcontroller Contest

Participated in the
Microcontroller Contest

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    11 Discussions


    4 years ago on Introduction

    It is pretty easy to make an wireless version of this. Have a look here:


    5 years ago on Introduction

    Sir can i have the Research Method & Techniques for that arduino sensor alarm? Thanks for any info.


    7 years ago on Introduction

    Can I use the pir element as the board is expensive in my country and I have two pir elements and I don't have the BISS001 IC to drive it?


    7 years ago on Step 3

    this is something similar to what i have to do in my final year engineering project. my project is monitorin of oil well parameters using zigbee technology. in this we have 4 sensors(temp,press,pir, optocoupler). these sensors sense n pass data to microcontroller (still not able to decide which one to use). this data is transmitted by microcontroller using zigbee to a remote desktop. after reading this instructable of yours it seems very similar to what i have been looking for except that i have to use 3 sensors.. can u please help me out if u already have any such projects made or know about any links?


    8 years ago on Introduction

    Here's a really simple version of this, if you like to experiment with Arduino...

    Regards, Terry King


    8 years ago on Introduction

    What kind of protoboard is pictured in Step 1? I looks like Sparkfun something, but I can't identify it. TIA!

    1 reply

    Reply 8 years ago on Introduction

    That is actually one I made myself. I used the Sparkfun Wombat PTH blank board and the Arduino headers (2 6pins, 1 8pin, and 1 bent 8pin). Then I stuck a half size breadboard in the middle, removed one of the power rails so it could fit. The switch on the side allows me to easily switch off servos plugged in.


    8 years ago on Introduction

    The PIR sensor for adafruits has a trim pot on the back to adjust the length when it's triggered. You can literally have it be triggered and only output a HIGH for a few seconds, or you can have it triggered for up to 25 seconds i think (not exact).

    With that said the sensor would be bad to use as an active lighting device. You would have to be constantly moving for it to always be on.

    What i did in my code a while back was setup some settings that determined how long the lights would stay on even though the sensor may have went back to a LOW state.

    You could also use it as a switch, located near a door, situated to only be triggered when someone walks through the door.

    My Project includes:
    -2 PIRs at two different locations in the room
    -1 at the door, so any one of the PIR will always be on while i'm in the room.

    when i sit at my computer, the PIR underneath the desk triggers some lights around my computer.

    when i sit at my tv, the back lights around my tv turn on.

    The one at the door serves as a turn off protection.

    So with a couple of these paired along with a program that keeps track of when certain lights should be on makes for a very nice lighting in my work area.

    Also, i have 12v leds that use PWM with mosfets.

    Good work, though.

    1 reply

    Reply 8 years ago on Introduction

    Yes you could do that. For example if anyone else would like to know, the coding would work something like this. When the pin goes from HIGH to LOW, it sets a value as the millis() when the pin went low. Then there will be a loop that will keep the light on until a certain time has passed. The code would be something like:

    if(millis() - lastMillis >900000) // 900000ms is 15 minutes
    digitalWrite(light, LOW);

    There would also be another if statement where every new motion would reset the timer to the current millis. This code operates on the difference between the stored and current millis. It works in the method of checking how long it has been since the last motion. If it exceeds 15 minutes or whatever time you decide, you can have it shut the light off.