HDTutorial
EN

Playback starts YouTube’s embedded player (privacy-enhanced mode).

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

68,893 views November 8, 2017 3:06

Watch on YouTube
Channelnonscio

Description from the creator

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: nonscio.com/blog/q9gjkd7zg5llfkp0ghnfwecqy2oxas

See how this can be used to help a robot navigate autonomously! youtu.be/IvulErD05rA

#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);
}

About this tutorial

nonscio published this 3:06 video tutorial on November 8, 2017. It has been watched 68,893 times on YouTube.

Channel
nonscio
Duration
3:06
Published
November 8, 2017
Views
68,893
Likes
415

Tags

Share

This tutorial in other languages