Introduction: MOTION SENSOR USING ARDUINO

how to wire and program your new motion sensor with your arduino? Well look no further. This tutorial will give you a simple example of how to set up a motion sensor to your arduino and turn an led on or off if motion is detected.This principle is used in many field like automatic open door,smart homes ....etc. Keep following for the Arduino ,HTML and CSS tutorials.

Step 1: ELECTRONICS REQUIRED :-

The parts required for this basic complex instructables are

  • Arduino uno
  • Jumper wire
  • Motion sensor
  • Breadboard
  • LED

So let's get started with this instructables.

Step 2: BUILDING THE ELECTRONICS:-

  • place your controller if possible on a breadboard! I am using Arduino micro so it's very convenient to place on a breadboard if you're not using a micro you will need to use some jumper wires to connect your Arduino to a breadboard so you can plug your sensors and output devices in more easily.
  • After you're all situated you're gonna go ahead and place a wire from the Arduino ground to the ground on that motion sensor this pin you should be labeled.
  • You're also going to pick a pin on your Arduino and you're going to connect the out pin from the motion sensor which is labeled "out" to an empty pin on your Arduino I used the pin number five.
  • Then you're going to connect the VCC output from the motion sensors to the VCC output of the Arduino this is the positive five volts that's coming out of the Arduino.
  • Next go ahead and place your LED on the breadboard, the longer lead of the LED is the positive side or if both of your leads are the same you can look for a small notch on one of the sides of the LED this is going to be the negative side place it on your breadboard plug the negative side into the ground of the Arduino, you can use a jumper wire to go from the ground on the LED pen to the ground on the motion sensor then pick a pin that's empty on the Arduino and run a wire from it to the positive side of the LED.
  • I used pin number 7 for this. We are all done wiring now let's go ahead and go to the next step, programming the controller.

Step 3: CODING :-

int motion = 5;

int motionLed = 7;

void setup() {//ok i need to state what each pin will be doing. the led pin will//be an output and the motion pin will be an input.

pinMode(motion, INPUT);

pinMode(motionLed, OUTPUT);}

void loop(){ //what will happen in the sketch //if motion is detected we want to turn the led light on //if no motion is detected turn the led off //you also need to declare a variable to hold the sensor data long sensor = digitalRead(motion); //then the if statement to control the led

if(sensor == HIGH){

digitalWrite (motionLed, HIGH); }

else {

digitalWrite (motionLed, LOW); }

}

Comments

author
DAEHWANL made it! (author)2017-01-08

I made it! Thank you~~

1483945685919-1570699924.jpg
author
WannaDuino made it! (author)2016-11-16

and i tried it, But with problems of using the PICTURES here.

if you follow the pictures of this IBLE it will not work.

because the 2 pins of the LED ( pin 7 is GROUND on LED and led+ (ANODE) is 5VOLT.

and on the pictures its other way around.

And the code is working only 1 time?

so the led stays ON CONTINUE after detecting.

so please upgrade or update this IBLE, to tel that or people lose time in finding out what's wrong. i found out that its almost difficult to find a good IBLE,with no mistakes or good explaination, (and i am also guilty of that)

author
WannaDuino made it! (author)2016-11-16

WoW

sombody else responded to that guy that needed help,

and not the IBLE maker.

i realy can not cope with that, sorry

if placed an ible !!! HELP

you know you get mails from people.

or dont come here.

author
thomcomstock made it! (author)2016-02-26

error: 'sensor' was not declared in this scope
sensor = digitalRead(motion);
^
exit status 1
'sensor' was not declared in this scope

____________________________________

Could you rewrite the code for this so that it is written in correct syntax?

author
akshay.d21 made it! (author)akshay.d212016-03-24

replace if ( sensor == high ) by if ( motion == high ) ... it should work. :)

author
ChrisCr made it! (author)2015-08-10

Nice, this could be built into a bigger project, where did you source the motion sensor ?

author
feralmonkey4 made it! (author)feralmonkey42016-01-05

there is a similar motion sensor here

https://www.sparkfun.com/products/13285