–>

Cool Arduino Ultrasonic Transducer HC-SR04 Distance Measurement With Tinkercad

Tinkercad Arduino Ultrasonic Distance Measurement

This post is about how to use the ultrasonic sensor HC-SR04 with Arduino Uno to make an ultrasonic distance sensor just like the ultrasonic sensor used in cars for parking assistance or Robotics.

My Books on Amazon

Components

Arduino UNO

, Banggood

16×2 LCD

, Amazon DE , Banggood

HC-SR04 Ultrasonic Transducer

, Amazon DE , Banggood

Circuit Connection

We start with Arduino Uno connected to 16 by two LCD.

Four pins of data and enable pin and register select pins connected to Arduino.

The VCC and ground connected to 5 volts and ground in Arduino Uno. Read Write and contrast pins connected to ground the backlight led positive pin connected to VCC.

The negative pin of the backlight led connected to negative through one kilo ohm resistor. Here is the HC-SR04 ultrasonic sensor it has two elements one element called trigger that’s the ultrasonic transmitter and hat’s the receive element called echo.

VCC connected to five volts and ground connected to the ground and here is the trigger or transmit pin connected to Arduino to pin number nine.

And the echo connected to pin number ten.

Ultrasonic Sensor 👇👇👇👇
https://www.banggood.in/custlink/G3D5je5Fj7

surveyeah icon JOIN SURVEYEAH!

My books on Amazon

Arduino Tinkercad Autonomous Guided Vehicle Book on Amazon

Arduino Code

#include <LiquidCrystal.h> // includes the LiquidCrystal Library
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)
const int trigPin = 9;
const int echoPin = 10;
long duration;
int distanceCm, distanceInch;
void setup() {
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;
distanceInch = duration*0.0133/2;
lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("Distance: "); // Prints string "Distance" on the LCD
lcd.print(distanceCm); // Prints the distance value from the sensor
lcd.print(" cm");
delay(10);
lcd.setCursor(0,1);
lcd.print("Distance: ");
lcd.print(distanceInch);
lcd.print(" inch");
delay(10);
}

Tinkercad Arduino Simulation

Here is the distance in centimeters and in inches as calculated by our ultrasonic distance device here we click on the ultrasonic sensor we find that the target is simulated on Tinkercad as a small object we can move it and we can see here the distance of that object from the ultrasonic sensor we can change that distance and we see the result on the LCD.

Here is the distance is about 175 centimeters it’s nearly as the same on the LCD. And we can change the distance and as we know the ultrasonic beam has a cone shape. Then we get that target out of this shape it’s no longer detected because of the way the ultrasonic waves move into the air.

When we get it back inside the detection area we find that it’s responding to the ultrasonic waves going from the transmitter and bouncing on the target and then coming back to the receiver. That’s the same way the ultrasonic sensor on the car parking assistance or in robotics.

surveyeah icon JOIN SURVEYEAH!

Videos

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top