Ultrasonic Motion Sensor code -
https://goo.gl/PCL9Qo
/*Ultrasonic sensor Pins:
VCC: +5VDC
Trig : Trigger (INPUT) - Pin11
Echo: Echo (OUTPUT) - Pin 13
GND: GND
*/
WE'LL TRY THIS FIRST
#define trigPin 13
#define echoPin 12
#define led 7
void setup()
{ Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led, OUTPUT);
}
void loop()
{ long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 10)
{ digitalWrite(led,HIGH);
}
else {
digitalWrite(led,LOW);
}
Serial.print(distance);
Serial.println(" cm");
delay(500);
}
=================================
ALTERNATIVE
// Copy the following and paste into your Arduino software and delete the template provided (the void setup and void loop).
int trigPin = 11; //Trig - white Jumper
int echoPin = 13; //Echo - yellow Jumper
long duration, cm, inches;
void setup() {
//Serial Port begin
Serial.begin (9600);