Arduino Motion Sensor

2,734

28

5

Introduction: Arduino Motion Sensor

I will be teaching you how to make a motion/ distance sensor with and arduino.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Materials

1 computer

1 arduno

1 arduino plug

1 breadboard

1 ultra sonic distance sensor

8 jumper wires

2 led lights

Step 2: Setting Up the Arduino

1. Plug in your arduino to your computer and open arduino on your computer.

Step 3: Connecting the Sensor

1. connect 5v to the breadboard

2. connect pin 12 right next to 5v

3. connect pin 13 right next to pin 12

4. connect ground right next to pin 12

5. line up the sensor with corresponding wires

Step 4: Connect LED S to Arduino

1. put a wire in ground and connect it to the back row with a + sign on the breadboard

2. put a wire into the row with the ground and connect it to a place on the breadboard

3. put a wire into pin 8 and put it right next to the ground

4. put a wire into the row with the ground and connect it a couple spaces away from the first ground

5. put a wire into pin 7 and put it right next to the ground

6. put each LED into one ground and one pin

Step 5: Create the Code

//if it has // its not part of the code its just a comment

void setup() {

Serial.begin(9600);

pinMode(11,OUTPUT);

pinMode(12,INPUT);

pinMode(10,OUTPUT);

//pinMode activates the pin so the arduino can use it

}

void loop() {

long duration, inches;

digitalWrite(11,LOW);

//digitalWrite gives the arduino a command. LOW means off, and HIGH means on

delayMicroseconds(2);

//delay makes the arduino wait before doing the next command

digitalWrite(11,HIGH);

delayMicroseconds(5);

digitalWrite(11,LOW);

duration = pulseIn(12,HIGH);

//this part is telling pin 11 to read the sensor

inches = duration / 74/ 2;

Serial.println(inches);

delay(10);

if(inches < 5){

digitalWrite(10,HIGH);

}

if(inches > 5){

digitalWrite(10,LOW);

}

}

Step 6: Test It

1. move your hand back and forth and see if the lights change

Step 7: Adjustments

1. if you change the numbers in the if statements it will change the distance that it will be triggered.

Arduino Contest 2017

Participated in the
Arduino Contest 2017

LED Contest 2017

Participated in the
LED Contest 2017

Be the First to Share

    Recommendations

    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Arduino Contest 2020

      Arduino Contest 2020

    5 Discussions

    0
    Andrewf64
    Andrewf64

    2 years ago

    Nice... would be even nicer to add a notification via WiFi!?

    0
    tliguori330
    tliguori330

    2 years ago

    really clear i learned alot

    0
    Swansong
    Swansong

    2 years ago

    That's a neat simple setup :)

    0
    darnoldgoldstein
    darnoldgoldstein

    Reply 2 years ago

    make sure to vote for me in the LED and arduino contests