Introduction: Arduino Motion Sensor
I will be teaching you how to make a motion/ distance sensor with and arduino.
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.