How To: Use an Arduino with an Ultrasonic Sensor (HC-SR04)

nonscio
nonscio
63 هزار بار بازدید - 7 سال پیش - This video is about using
This video is about using the popular HC-SR04 Ultrasonic Sensor with an Arduino Uno to make distance measurements. You can use these measurements in many applications from robot object avoidance to parking sensors.

For more information see this post: https://www.nonscio.com/blog/q9gjkd7z...

See how this can be used to help a robot navigate autonomously! How To: Build ScioBot 2.0 Vision Ultr...

#define echoPin 7
#define trigPin 8

long duration;
long distance;

void setup() {
 // put your setup code here, to run once:
 Serial.begin(9600);
 pinMode(echoPin,INPUT);
 pinMode(trigPin,OUTPUT);
}

void loop() {
 // put your main code here, to run repeatedly:
 digitalWrite(trigPin,LOW);
 delayMicroseconds(2);
 digitalWrite(trigPin,HIGH);
 delayMicroseconds(10);
 digitalWrite(trigPin,LOW);
 duration = pulseIn(echoPin,HIGH);
 distance = duration/58.2;
 Serial.print(distance);
 delay(50);
}
7 سال پیش در تاریخ 1396/07/08 منتشر شده است.
63,046 بـار بازدید شده
... بیشتر