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

delay(3000);

digitalWrite(LED, HIGH);

delay(3000);

}

}

void loop() {

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

//if low, check again

if(digitalRead(PIR) == HIGH) {

digitalWrite(LED, HIGH);

delay(5000);

} 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

Comments

author
SHOE0007 (author)2016-07-28

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

buzzer sensor light.jpg
author
SHOE0007 (author)2016-07-27

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 shoemaker.daniel0004@gmail.ca.

Here a picture and diagram.

Diagram for shot in the dark 2.jpgShot in the dark 2.jpg
author
SHOE0007 (author)2016-07-19

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
author
SHOE0007 (author)2016-07-18

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
author
Muhammad faizanF (author)2016-02-19

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?

author
SachinA24 (author)2016-02-19

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 sackan18@gmail.com thanks

author
MomSTEAM (author)2016-02-02

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?

author
tcodd86 (author)MomSTEAM2016-02-02

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.

author
AmineM7 (author)2015-10-06

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

author
instructablesEHB (author)2015-08-31

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

author
tcodd86 (author)instructablesEHB2015-08-31

Thanks! I'm glad to hear that you liked it and think it will be useful.

author
DIY Hacks and How Tos (author)2015-08-30

Nice tutorial

author

Thanks!

author
Liamthe1st (author)2015-08-31

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

author
link2_thepast (author)Liamthe1st2015-08-31

Are you a Pro user? I believe only Pro users have the option to download as a PDF.