Introduction: 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. 

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: