Distance Finder

by AbidChettuthara in Circuits > Arduino

238 Views, 0 Favorites, 0 Comments

Distance Finder

Distance Finder.jpg

Hello Friends,

In this tutorial, I am going to show you how to interface ultra sonic sensor with Arduino to measure distance and print in serial monitor. So we need to complete 3 section. First to complete the circuit. Then we need to write the code for the project. And final section is to test the project. So let's move.

Required Items

IMG_20200903_211017.jpg

1. Arduino Uno

2. Ultra Sonic Sensor HC-SR04

3. Breadboard

4. Arduino Uno Cable

5. Male to Male Jumpers

So these are the items required for the projects.

Connection

2020-09-03 (1).png
IMG_20200904_152131.jpg
IMG_20200904_152157.jpg

Now we need to connect the ultra sonic sensor to Arduino. So first attach the sensor to the breadboard. Then follow the connections :

  • VCC to 5V
  • GND to GND
  • Trig to D7
  • Echo to D8

After completing circuit let's move to the coding section.

Coding

2020-09-03.png

So guys let's start coding. This is the code for the project.

#define trigPin 7
#define echoPin 8

float duration;
float distance;

void setup() {
  Serial.begin(9600);
  pinMode(trigPin,OUTPUT);
  pinMode(echoPin,INPUT);
}

void loop() {
  digitalWrite(trigPin,HIGH);
  delay(10);
  digitalWrite(trigPin,LOW);
  duration = pulseIn(echoPin,HIGH);
  distance = (duration/2)* 0.034;
  Serial.print("Distance ");
  Serial.print(distance);
  Serial.println(" cm");
  delay(250);
}

If you want to download the code click on the download button.

After coding let's upload it to the Arduino board.

Test the Project

IMG_20200903_211932.jpg
2020-09-04.png
IMG_20200904_150834.jpg

Now all the work is done. The last step is to test the project and make sure whether it works or not.So guy's if you like this project please support and follow me. Thanks for reading this tutorial. And if you have any doubts please leave a comment and feel free to contact me.