Motion Activated LEDs




In this tutorial, I will show you how to create motion activated LEDs which will be triggered by a Parallax PIR sensor and controlled by an Arduino Uno. This project can have practical applications such as night lighting for stairs, walkways, etc. 

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: Materials

For this project you will need:

1. Arduino Uno $30

2. Parallax PIR Motion Sensor $11

3. Mini Breadboard $6

4. USB A to B cable $4

5. 4x LEDs $4

6. 4x 220ohm resistors $6

7. Solid Core Wire $2.50

8. Wall Adapter Power Supply - 9VDC 650mA $6

Total cost should be around $70, but as I have said in previous instructables, YOU WILL USE ALL THESE PARTS AGAIN! As long as you plan to continue tinkering, don't sweat the price too much.

Step 2: Breadboard Basics

Breadboards are incredibly helpful when building circuits. They help you keep all of your components organized and laid out in a logical fashion. They also make it easy to confirm that the right wires are making the connections to the proper component leads. If you have never worked with a breadboard before, I'll explain the internal connection layout with the diagram above:

The on either side of the breadboard there are two columns, denoted by the blue and red highlights. These columns allow the user to have a common power and ground for components no matter where they are placed on the board. Whether your component is placed at A1 or J30, a common power and ground connection will only be a short distance away. All of the holes are connected vertically, so if you connected your ground (or power if you felt so inclined) to the left  or right most blue column, your common ground would extend from that column from position 1 all the way down to 30. However, the left and right sides are not connected, so If you wanted both blue columns grounded you would need to make two separate connections on either side.

Rows A-E and F-J are where your components will be placed. This part of the board is also split between the left and right side about the center of the board. If a wire is placed in A1, that charge will carry through E1 and stop at the center divide. If a wire is placed in F1 that charge will carry through J1. You do not have to start out at position 1 every time either. If you place a connection at C1 for example, A1, B1, D1 and E1 would all have the same charge.

The first two and last two blue and red columns share a connection vertically.
A-E share a connection horizontally
F-J share a connection horizontally
A-E connections and F-J connections are not bridged across the center.

Step 3: Parallax PIR Motion Sensor

The PIR Sensor detects motion by measuring changes in the infrared (heat) levels emitted by surrounding objects. When motion is detected the PIR sensor outputs a high signal on its output pin. 

Key Features:

Detection range up to 15 ft. away on short setting, up to 30 ft. away on long setting 
Onboard LEDs light up the lens for fast visual feedback when movement is detected 
Mounting holes for 2-56 sized screws provide easy integration in permanent applications 
3-pin SIP package perfect for breadboard-friendly projects 
Easy communication with any microcontroller 
Small size makes it easy to conceal

*from the Parallax website, product description.

I've included photos of the front and back so If you have not yet purchased the product, you can get an idea of what you will be working with in terms of connecting leads.

If you would like to learn more about PIR technology, check out THIS Instructable which goes into the inner workings of the module.

Step 4: Arduino IDE

"The Arduino language is merely a set of C/C++ functions that can be called from your code. Your sketch undergoes minor changes (e.g. automatic generation of function prototypes) and then is passed directly to a C/C++ compiler (avr-g++). All standard C and C++ constructs supported by avr-g++ should work in Arduino." - Arduino support page

It is fairly straight forward and Arduino has a nice set of references and tutorials listed on their webpage:

To begin programming your Arduino, you will need to download the Arduino IDE software: Click here

Once you have downloaded the IDE open up a blank document

Step 5: Arduino Code

Copy and paste the following code into your new project window:

January 28, 2014
[author] Mark Graziano
[instructables profile]

int LEDArray[] = {5, 6, 9, 10};           // LED array for PWM 5,6,9 and 10
int numOfLEDs = 4;                       // LEDs of index 0-3
int pirState = LOW;
int pirVal = 0;
int pirPin = 12;

void setup()  {
  pinMode(pirPin, INPUT);
  int i;
  for(i = 0; i < numOfLEDs; i++) {
    pinMode(LEDArray[i], OUTPUT);

void loop()  {
  pirVal = digitalRead(pirPin);
  int i;
  //if motion is captured, light the LEDs in sequence
  if (pirVal == HIGH) {
  for (i= 0; i < numOfLEDs; i++) {
    analogWrite(LEDArray[i], 255);
    delay (1000);
  delay (1000);
   for (i= 0; i < numOfLEDs; i++) {
    analogWrite(LEDArray[i], 0);
    delay (1000);
  if (pirState == LOW) {
      pirState = HIGH;
  //else, set all LED values to zero
  else {
    analogWrite(LEDArray[0], 0);
    analogWrite(LEDArray[1], 0);
    analogWrite(LEDArray[2], 0);
    analogWrite(LEDArray[3], 0);
    if (pirState == HIGH) {
      pirState = LOW;

Step 6: Compile and Upload

The check button is for the compiler. Click it and you should receive a message at the bottom of your screen saying that the code is done compiling.

Once that has been verified, use the USB A to B cable to hook up your Arduino to your computer. Be sure you do not simultaneously powering the Arduino with the wall adapter power supply. You can end up frying the microcontroller if it is being powered by both sources simultaneously...I accidentally did this to an Arduino Mega before.

Once the Arduino is connected to your computer navigate to Tools > Board to make sure you have the right model board selected. You may also want to navigate to Tools > Serial Port to be sure you have the proper port selected to send your information.

Hit the upload icon (looks like a right facing arrow) and it should upload in about 10 seconds. You should see a "Done Uploading." pormpt at the bottom of the window when this is complete.

Unplug your Arduino from your computer, it will save the information you just uploaded even when it is in an "off" state.

*the first figure shows the compilation steps and the second figure shows the upload steps

Step 7: Wiring


The 4 LEDs are attached to Digital Output PWM pins 5,6,9 and 10. Each has a resistor before the LED to reduce the current stress. They all share a common ground at the very top of the breadboard (from perspective of the figure).

The Parallax PIR Motion Sensor, GND shares the same common ground as the LEDs, Vcc is connected to the Arduino's 5V output, and OUT is connected to digital pin 12 on the Arduino.

Power this project with your  9VDC 650mA  wall adapter power supply.

Step 8:

At this point you should be good to go with your compact set up. Now it's time to think of how you can apply it practically in your own home! Here is a video of one of my favorite applications of this type of project: 

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    17 Discussions


    Question 1 year ago

    Just built this circuit and the LED's light up in sequence perfectly however the motion sensor doesn't seem to be doing anything. The LED's are continuously flashing on and off regardless of any motion input in front of the sensor. How can I tell if the motion sensor is working? (The sensor I'm using is from the UNO R3 Project set that came with the board - HC-SR501 PIR Motion Sensor)


    2 years ago

    Hi, I am not able to upload the code. It says the below error:

    Arduino: 1.8.2 (Windows 7), Board: "Arduino/Genuino Uno"

    Sketch uses 2308 bytes (7%) of program storage space. Maximum is 32256 bytes.

    Global variables use 194 bytes (9%) of dynamic memory, leaving 1854 bytes for local variables. Maximum is 2048 bytes.

    avrdude: ser_open(): can't open device "\\.\COM1": The system cannot find the file specified.

    An error occurred while uploading the sketch

    This report would have more information with

    "Show verbose output during compilation"

    option enabled in File -> Preferences.


    5 years ago

    you could wire the LEDs to the signal of the PIR which only triggers when motion is detected.

    that said, I still like the idea of the arduino control for logging, other devices etc so this is a good core project for expansion

    1 reply

    Reply 5 years ago on Introduction

    Valid point. I wanted to use the Arduino to show an example of the behaviors you could program to control the LEDs. Thanks for the feedback!


    Reply 5 years ago on Introduction

    Absolutely, just be sure you check the current limits of the components you are using and add the proper resistors between the power supply and your components. You don't want to burn out any of your components because that 2000mA exceeded your components max values.


    Reply 5 years ago on Introduction

    Connect the proper Vcc and ground and then just connect the additional OUT lead to an empty GPIO pin on the arduino. Just remember to initialize that GPIO pin and define the desired behavior in your code.

    Sorry for the belated response! The one you have the link for works just fine. Still has all the same leads but they are just labeled differently. You still have the standard Vcc and ground to give the component power but in my project the signal line is labeled "OUT" while yours is labeled "ALARM" (or AL).

    P.S. Asking questions isn't a bother! It's why I posted these things in the first place :)

    I personally have not tried, but since it is only sending an on/off signal, I bet you could get away with a simple IR emitter and receiver diode set up. Other methods like bluetooth, wifi and RF may be a bit overkill (in set up and on your wallet!).


    5 years ago on Introduction

    Hi im having some troubles with this and i dont know if its just my sensor because when i upload it the leds flash and all but once theyre done and i do some finger movements in front of the sensor nothing happens. I already rewired everything but what is it, my sensor?

    1 reply

    Reply 5 years ago on Introduction

    *sorry for the late response*

    Is your PIR motion sensor made
    by Parallax like the one I used in this tutorial? If so, does the red
    LED on the sensor turn on if you wave your hand in front of it? If it does, try attaching a single LED to the Vcc and Out of the PIR sensor (so your circuit is only comprised of the most basic components). Let me know what happens if you give that a shot. If the sensor is working properly I'll see if I can troubleshoot any of the other steps for you :)