Motion Detector With LED for Beginners




Introduction: Motion Detector With LED for Beginners

This is a simple project I made to test some motion sensors I bought. It will detect motion and light an LED when it does. This should only take 20-30 minutes start to finish and is a perfect project for beginners. Enjoy!

Step 1: Gather Supplies

First, gather your supplies

Step 2: Wiring and Adjustments

You will need to connect the LED and PIR sensor to the Arduino board. The PIR sensor I used has the center pin as the signal, the left for the 5V supply, and right for Ground. Wire the center line to digital pin 10 and the power and ground lines of the PIR to the 5 V pin and to the GND pin on the Pro Mini.

The LED should be connected to digital pin 3 (and don't forget the necessary resistor for the LED you're using). In my case I used a blue LED with a 22 ohm resistor.

The sensor reads more sensitively when motion is horizontal across the sensor rather than vertical according to the data sheet but I haven't had any problems with vertical motion detection.

The sensor has two different trigger methods, single trigger or repeating trigger which can be changed by adjusting the jumper in the top right. As shown it is set to single trigger which means when it senses motion it will set the signal line to high (3.3 V) for 2.5 seconds and then automatically go back to low until it detects motion again. In repeating trigger method the sensor will trigger high when motion is detected and stay high for a set amount time which can be adjusted by the timing screw. If motion is detected during that time, the timing resets to 0. In this way the signal can be kept continuously high while there is motion in front of the detector.

The default delay setting for the repeating trigger is 2.5 seconds. This can be adjusted up to roughly 5 minutes by turning the timing screw clockwise or down to as low as 0.3 seconds by turning it counterclockwise. Likewise, the sensitivity may be adjusted up by turning the sensitivity screw clockwise up to roughly 7 meters and decreased by turning the sensitivity screw counterclockwise down to about 3 meters.

Step 3: Code!

The code for this project is pretty simple. According to the data sheet for the PIR sensor it takes roughly 1 minute to initialize so the setup function has 60 seconds of delays during which time the LED will blink off and on in 3 second intervals. Once the sensor is initialized it will trigger high whenever it senses motion which will turn the LED on for 5 seconds. After the 5 seconds it will try to read again and the LED will stay lit if more motion has been detected or go low if there is no motion. The code can be found on my GitHub page and I have copied it below.

int LED = 3;
int PIR = 10;

void setup() {

// initialize digital pin 3 as an output for LED

pinMode(LED, OUTPUT);

//initialize digital pin 10 as input for PIR

pinMode(PIR, INPUT);

//initialization time for PIR sensor to warm up

//blink LED to show that something is happening

for(int i = 0; i < 10; i++) {

digitalWrite(LED, LOW);


digitalWrite(LED, HIGH);




void loop() {

//read PIR sensor, if High light LED for 5 seconds

//if low, check again

if(digitalRead(PIR) == HIGH) {

digitalWrite(LED, HIGH);


} else {

digitalWrite(LED, LOW);



Step 4: Program Your Arduino

It's not quite as easy to upload a sketch to an Arduino Pro Mini as it is to one of the other varieties of microcontroller that have USB ports directly on them. However it is still relatively straightforward and just a few tweaks to the Arduino IDE are needed to get it right.

First, make sure you have a USB mini cable, not micro! If you have the FTDI chip and Arduino Pro Mini board I linked to in the supply list it's as simple as hooking the FTDI right onto the programmer pins on the end of the mini and then connect the USB to the FTDI and to your computer as shown in the image.

In the Arduino IDE paste the code in and select the Arduino Pro Mini board in Tools -> Boards. In Tools -> Processor Select ATMega328, 5 V. Now you can compile and upload your sketch as usual.

Step 5: Use Your Motion Sensor!

Congratulations, you've made a motion detector! Now you can plug in your motion sensor and watch it work. In the future I will be making several of these which will communicate via RF receivers with a board that will be able to display if there is motion detected at other sensors. I hope this Instructable helped you get started with your motion sensors and Arduino



    • Metalworking Contest

      Metalworking Contest
    • Fix It! Contest

      Fix It! Contest
    • Tiny Home Contest

      Tiny Home Contest

    18 Discussions


    Question 5 months ago

    This is probably a stupid question, but since the sensor has all necessary adjustability, and 3.3V output, why can't you just power the LED directly from the sensor output? And for higher amperage applications, just use the PIR outlet to trigger a relay and use the PIR power source to power the target device? Like I said, this question may be stupid, especially since so many 'ibles/applications seem to use arduinos even though functionality of the circuits appear relatively simple (to me, a rank amateur).

    2 more answers

    Hi, you're absolutely correct. I used the arduino here not because it is necessary but as a learning tool for people getting started with the platform. It's basically a slightly more complicated Blinky program.

    That makes sense. Certainly many of the instructables are not the simplest solutions, generally focusing on learning and fun. But since I'd seen so many simple systems using arduinos and such I thought that as a noob I was just missing something critical. Thanks for reply.

    Here is the device that turns off sound when the beam is disrupted.

    buzzer sensor light.jpg

    Although it is not the same this can act like a motion detector when a beam of light is shinning on the CDs cell and is disrupted sets off an alarm. Does anyone know if you can setup a DC powersupply near 6 volts? E-mail

    Here a picture and diagram.

    Diagram for shot in the dark 2.jpgShot in the dark 2.jpg

    Here from the 130 in 1 electronic kit is a project that uses three transistors and NAND gate with a cd's cell to turn three leds on and off. When low light is applied and the beam to the cds cell is interrupted the leds change direction.

    a second motion detector.jpg

    I built a different type with a 200 in 1 electronic kit with a flash light and the circuit. Here is a digaram of it!

    Optical counter.jpg

    I have an ESP-01 module connected to the arduino and powered by an external power source. I tried sending AT commands using the serial monitor in Arduino IDE, blue led blinks each time I send a command, but I get no response back.

    ESP --- Power
    Vcc --- 3.3v
    GND --- GND

    ESP --- Arduino UNO
    GND --- GND
    CH_PD --- 3.3v (tied 10kOhm)
    RX --- RX (connected 10kOhm to GND and RX Arduino)
    TX --- TX

    I tried swapping the TX and RX pins, directly connecting the pins without resistors, or even connecting the other pins to either 3.3v or GND like other tutorials schematics. I also tried uploading the BareMinimum code or SoftSerial samples provided by other tutorials. In the end, nothing works.

    Also when I try to upload code to the ESP-01 through the IDE I get "warning: espcomm_sync failed error: espcomm_open failed" errors.

    Is my module fried or am I doing something wrong?

    Hi tcodd86 . I am from india. And I want help from you. Wanted to make a motion sensor switch project. But what exactly I want to make it I can't explain you here. So can I send a email to you. Want to send a attachment . Please email me on thanks

    This is amazing, thank you for sharing!
    My 11yr old son just discovered this Audrino thing "world" (don't have one yet)
    Can you tell me after coding, can you then connect to a battery for portability?

    1 reply

    Hi, I'm glad you found it helpful. Yes, you definitely can connect it to a battery. For a first arduino I would probably recommend the Uno model (or clone) as it's a little easier to program since it just requires a USB cable instead of a FTDI programmer. The code is the exact same. I bought some kits similar to this or this when I was getting started. They have a lot in them and are a great way to have supplies for a lot of projects pretty cheap. Feel free to comment or message me if you have any questions.

    one time the calibration is finished it make the led on motion detcted at 46 seconds

    This is a very complete and accurate tutorial. Thank You so very much for sharing your time and skills. Many people will gain from your effort.

    Best Regards

    1 reply

    I want to be able to Download it to PDF but it is not showing the option

    1 reply