Introduction: Motion Activated LEDs

Picture of 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

Picture of 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

Picture of 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.

TL; DR
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

Picture of 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

Picture of 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: http://arduino.cc/en/Reference/HomePage

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
[email] mark.graziano.13@gmail.com
[instructables profile] https://www.instructables.com/member/GraziCNU/
*/

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()  {
 
  Serial.begin(9600);
  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

Picture of 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

Picture of Wiring

Explanation:

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: 

Comments

Joey_senpai (author)2017-03-27

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.

RobertoCarlos (author)2016-09-03

Thanks.

Very good.

NileshG (author)2015-02-06

Thanks Very Simple & Lucid. Easy to Implement.

AnnaThomasMoney (author)2015-01-23

Hi! Love this project. Can I do this with a 12v LED strip?

alexmac131 (author)2014-01-29

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

GraziCNU (author)alexmac1312014-09-25

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!

eddieBeg (author)2014-04-24

hye, can I use power supply 9DC 2000mA for this project?

GraziCNU (author)eddieBeg2014-09-25

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.

sriramsrikp (author)2014-04-28

Hai, how to connect two PIR sensor in this circuit???

GraziCNU (author)sriramsrikp2014-09-25

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.

Hello sorry to bother you but Im trying to make this but I'm using this PIR https://www.sparkfun.com/datasheets/Sensors/Proxim...

Does this affect the project at all?

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

Is there a way to make the motion sensors wireless?

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!).

AgentArod (author)2014-02-27

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?

GraziCNU (author)AgentArod2014-04-05

*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 :)

About This Instructable

26,230views

125favorites

License:

More by GraziCNU:Motion Activated LEDsSound Reactive LED StripTurning your Raspberry Pi into a personal web server
Add instructable to: