Using Ultrasonic Distance Sensor HC-SR04 with LCD Display and Arduino

preview_player
Показать описание
Display the results from the HC-SR04 Ultrasonic Sensor on an LCD

Required Hardware:
Arduino Board :
Ultrasonic Sensor:
LCD Display:
10K Ohm Potentiometer :
Breadboard:

Recommended Items:

Connections:
The HC-SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo. The Ground and the VCC pins of the module needs to be connected to the Ground and the 5 volts pins on the Arduino Board respectively and the trig and echo pins to any Digital I/O pin on the Arduino Board.

The HC-SR04 sensor attach to the Breadboard
The Sensor VCC connect to the Arduino Board +5V
The Sensor GND connect to the Arduino Board GND
The Sensor Trig connect to the Arduino Board Digital I/O 9
The Sensor Echo connect to the Arduino Board Digital I/O 10

Watch the basic tutorial about the HC-SR04:

LCD Display Connection:
Before wiring the LCD screen to your Arduino or Genuino board we suggest to solder a pin header strip to the 14 (or 16) pin count connector of the LCD screen.
To wire your LCD screen to your board, connect the following pins:

LCD VSS pin to Arduino GND
LCD VDD pin to Arduino 5V
LCD VO pin to 10k Potentiometer center pin
LCD RS pin to digital pin 1
LCD RW pin to Arduino GND
LCD Enable pin to digital pin 2
LCD D4 pin to digital pin 4
LCD D5 pin to digital pin 5
LCD D6 pin to digital pin 6
LCD D7 pin to digital pin 7
The 10k Potentiometer's other legs connect to +5V and GND
For the backlight of the display, pin 15 (A+) and 16 (K-) of the LCD connect to +5V and GND

If you want, can be use a 220 ohm resistor to power the backlight of the display.

About Source Code
The LiquidCrystal library allows you to control LCD displays that are compatible.

First you have to define the Trig and Echo pins. In this case they are the pins number 9 and 10 on the Arduino Board and they are named trigPin and echoPin. Then you need a Long variable, named “duration” for the travel time that you will get from the sensor and an integer variable for the distance.

In the setup you have to define the trigPin as an output and the echoPin as an Input and also start the serial communication for showing the results on the serial monitor. If the object is 10 cm away from the sensor, and the speed of the sound is 340 m/s or 0.034 cm/µs the sound wave will need to travel about 294 u seconds. But what you will get from the Echo pin will be double that number because the sound wave needs to travel forward and bounce backward. So in order to get the distance in cm we need to multiply the received travel time value from the echo pin by 0.034 and divide it by 2.

Social Media:
Рекомендации по теме
Комментарии
Автор


Recommended Items:

makerio
Автор

my guy you and your funky cowboy music is saving the entire 2022 year one computer science students

yabbero
Автор

Omg someone who actually writes where the wires go 👍👍👍 subscribing now!

sabrinaflipse
Автор

Sketch uses 3348 bytes (10%) of program storage space. Maximum is 32256 bytes.
Global variables use 71 bytes (3%) of dynamic memory, leaving 1977 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x10

avrdude: stk500_recv(): programmer is not responding

nektarioskoumantakis
Автор

4 saattir uğraşıyorum sizin videoyu gördüm ve 10dk de yaptım teşekkürler

alibayrak
Автор

Did it just like your tutorial. Works perfectly first time !! Thank you for all the work you did...

mikex
Автор

*For those who also can't get the code through the link-*
First, you need to be on a computer because this involves inspect element.


What you need to do is hover over the endcards, pull up the inspect element menu, and just start deleting the files that make up the cards. Just hover over the code if you get lost and it should highlight what you are messing with. Just delete all four and then just play and pause. All code will be visible.

hi-nwqy
Автор

so helpful listeding the resister omps and potentiometer

daltonhatinger
Автор

first Tutorial that worked for me. Very nice!

Luqn_code
Автор

proximity2:1: error: #include expects "FILENAME" or <FILENAME>

#include 'LiquidCrystal.h' //Please replace the single quote characters ('') with the parenthesis character (<>)

^

exit status 1
#include expects "FILENAME" or <FILENAME>

PLEASE HELP

colorboxartacademy
Автор

Your codes are awesome
Works well!!
Overall excellent

vaibhav.m
Автор

For some reason, all I get is a blank LCD screen and squares when I checked the serial monitor...

sciencesid
Автор

very very detailed.
I am not an electronic Guy. I want to make it. Is it possible with 400 / 170 point holes Breadboard?. If yes can you pls share the wiring?

baala
Автор

Video was great until the end. Could not see the code because video links popped up in front. Add a bit of black screen or something less important at the end so the important stuff doesn't get covered up.

kellyspoolhall
Автор

Could you do this same code but using a VL53L1X lidar time of flight sensor on your next video, whilst using the same items except for the ultrasonic sensor?

chrislambert
Автор

Simple fix for the source code problem. Download it instead of just viewing it. Use cloudshare to change the rar to a zip than download it. View as a txt for the code. On the first line change 'liquidcrystal' to <liquidcrystal>. Then verify and run.

LNU
Автор

great video!! can you please upload another one without potentiometr

taqitahmidtanzil
Автор

i have a problem: doenst work HELP !!!
The sketch uses 3302 bytes (10%) of the program memory space. The maximum is 32256 bytes.
Global variables use 71 bytes (3%) of dynamic memory, leaving 1977 bytes for local variables. The maximum is 2048 bytes.

mohamedsultan
Автор

In serial monitor the distance is showing 0. Irrespective of object towards the ultrasonic sensor. What to do.

creativenathani
Автор

Can u give me the code becoz i cant open the code, an error occurs while i try to open the code

sonuKhan-shoe
welcome to shbcf.ru