Distsance finder by using ultrasonic sensor with Arduino
1x Arduino board
1x DC supply
4x Male to female jumper connecting wire
Apparatus required:
1x Ultrasonic sensor
1x DC supply
4x Male to female jumper connecting wire
Construction:
Step 1: Upload the program given below in to Arduino board
Step 2: Connect the Arduino and Ultrasonic sensor in to the pins trigPin-9, echoPin-10
Step 3: Now click serial monitor in the Arduino software
Step 4: Move your sensor and find distance approx,
Step 5: Follow us and subscribe our YouTube channel
Program:
#define trigPin 9
#define echoPin 10
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
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 >= 400 || distance <= 2){
Serial.println("Out of range");
}
else {
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
}
For more details follow us and ask in Contact Form. You will receive response in 24 hours
0 comments:
Post a Comment