Hi, welcome to an arduino tutorial from Robojax. my name is Ahmad Shamshiri. in
this tutorial we are going to learn how we can use the vr53 l1x 4 meter
laser distance sensor to display the distance
on a lcd monitor with four wires. that's the lcd with r squared c module
or on 2004 display with 20 characters and four line cls
connected to a5 and then for the module if. you
you can get the code for this by clicking at the link below the video in
the description which will take you to www.robojax.com/learn/arduino
let's get started with this.
i wanted to display that distance as measured with
vr53 l1x. this module is offered in different shapes tutorial that i'm going
to show you will work with this module that you buy from aliexpress or ebay.
maybe this module from aliexpress or ebay
or if you're using this adafruit version or if you're using sparkfun
or any other module that you have we will be using only four wires.
power supply and ground so 3.3 volts and then we have SDA
and SCL. which is offered in this shape or this shape or blue
doesn't matter whatever shape you have. the
functionality and code that i'm just showing you with work with all of them.
this is lcd 1604 which has only four wires this is I2C
module and if you have problem with this module
with the address also i have separate video full
explanation of this (link below this video). in this video we're just going to use it
and i'm not going to explain those for that you have to watch
the video introduction to lcd and you have to
watch the introduction to the vr53 l1x because this is out of the
focus of this tutorial. 1602 which means it has 16 characters
and two line one two or if you use this 2004
also the same code will work to display the distance.
on the screen so you have extra lines they are available.
Wiring Explained
let me now explain the wiring regardless of which module you have
they all have the same pins. so we have two pins for power
as you can see VIN, GND this can be connected to 3.3 volts
or 5 volts and then we have sda and scl here as well we have sda and scl and at
the end we have xshut and GPIO here they call it
interrupt (INT) and XSHUT. I've explained them
separately so i'm using only four wires here.
VIN and five volts this is connected to 3.3 volts
at this point ground is connected to the ground
and then we have scl here this scl is connected to this point
a5 sda is connected to a4 i could also
connect it there and then for the lcd doesn't matter. if
you have large or small they both are the same and we have
this i squared c (I2C) module here we have four wires.
this GND is connected to the ground of arduino.
the vcc is connected to 5 volts to this point.
and then we have sda this orange it has been connected to the SDA of
arduino board here and then we have scl
SCL s also connected to the scl here. you can connect it also here doesn't
matter to a4 and a5. a4 is SDA
a5 is SCL. or you can connect it to breadboard and from breadboard connected
to the sensor and to the module doesn't matter.
because on the same line you can connect up to
128 different devices. so you can correct them all in parallel
that's okay.
Wiring Diagram
and here is the wiring diagram for the lcd ground is connected
to the ground vcc is connected to 5 volts SDA is connected
to A4, SCL is connected to A5. and then for the module if you're
using this module the vcc is connected to 3.3 volts it
works. and then ground i've connected in here
but you can connect also to this ground. and here this is SCL
and this is SDA the gray
if you're using this red module this display is the same
the label is exactly the same so just pay attention for SDA this is SCL
and this is SDA. and if you're using the adafruit module
pay attention to these pins here pause this video and follow
the same way and if you're using sparkFun
clearly label the SDA and SCL like this. if you want to learn arduino i
have a bestseller course on udemy where you can learn arduino from ground
up with hundreds of projects all course material library
codes wiring diagram everything available in
one place the link for my arduino course is below this video in the description.
Code explained
now let me explain the code first you need to get
the library as i have mentioned it you have to download and install the
library this is a link. install it. and on this link if you click
directly it will open the library manager for you and here sparkfun
will be listed currently it is installed so install
is disabled but in your case just click and install it.
you need to also install this the LiquidCrystal_I2C i have separate video
explaining that because i'm not gonna go through that.
make sure to watch that the link is below the video.
the same way download and save it as a zip file
and then install it and here this is the i squared C
address (I2C) for the module to get that address
i'll give you this i square c scanner file
just upload it to your Arduino and once you open the serial monitor
Set the serial monitor at 9600 from the lower right corner of the screen
here you will be able to see the address but
pay attention that if you see we don't see anything
on the lower (Lower right side) section here select 9600 baud
and then it will read it. now i have two modules here
one is let me stop this is my lcd and this is my
laser sensor both of these will work with I2C
so i have to know which one is which.
for that purpose this is my laser sensor i'm just disconnecting the two wires for
this
and now this is scrolling and it will i'm just
checking it so just wait for it as you can see it shows 0x26. now the
second one disappeared so this is my address.
and then close that. and the address you will type it in here
this 16 is number of characters two is 2 lines. because
for this one it has 16 characters and two lines.
for the 2004 if you have larger one
if you're using this one then it has 20 characters and
four lines. so type here 20 and make this
four. if you're using long range use this one
if you're using for medium and short use this one meaning
uncomment this and comment this here. so this will
change this will change the mode .and inside the loop here
this is getting the distance and this is printing it.
if you don't have it it will not read the distance. if you don't have this it
will not print. to print in millimeter type m
to print an inch type "i" to print in centimeter
press type c it's all lowercase with single quote.
and if you need it in foot just type f
because meter is not common and i use already
m for millimeter for meter just type a it's "a" . a little odd but this was my only
option to use character.
if you need full explanation of the code it is available as part of my arduino
course at udemy.com where everything will be explained for other projects.
to use distance inside the code use this
Demonstration
and here is a demonstration right now i'm pointing it to the ceiling there's a
light in front of me so let me point it on
this side and the distance sense is shown
let me point it down
so we read 37 millimeter
so because my room is very small if it gets some kind of reflection it
might get this zero
No reflection for surface like carpet will result in 0mm reading.
here inside the loop print distance m this was showing millimeter for for
millimeter i used m now let's change it to inch
and upload the code
now it shows inch
and if you want to change it to centimeters just
type c the mode is medium now it shows in terms of centimeters
Long mode demonstration
and here i change the mode to long so i commented that and uncomment so it
was like that just uncommented
and uploaded the code
so that's the maximum that i can get three meter
but my hand is shaking i'm changing it to
i for inch m was 4 millimeter that's a long mode 58
so let me move it
so the the distance if you want to do it in centimeter
just type here c
to centimeter when the length is long the c and m will get out
for that purpose we need to change this distance instead of distance
just make it d so i will post separate code in case if you just want
to use d.
Demonstration of code with "D"
i've updated the code with version 2 and instead of distance it just shows d
so you have enough room for the values to be displayed
so that's almost 4 meters 380
centimeters and now let's put i inch for
d where it shows again the mood is long and here
as you can see it choose everything properly with
all digits and characters if you want to change it to foot
just type here f
this shows in terms of foot now this shows in terms of meter
so 3 meters 70 centimeter so this is almost 4 meter
the this is 400 millimeter 42 centimeter
and if i point it here 0.05 that's 50 millimeter
or 5 6 centimeters and 204 display with 20 characters
and four line
Demonstration of "sensor failed"
i have disconnected now the sensor and this is what you read
it says sensor failed it means the wiring is incorrect
or your sensor is dead and now if i connect it back
it will work.
I would like to thank my Patrons from Patreon.com
Subtitle is typed on Jun 21, 2020 by Ahmad Shamshiri
I did my part to help you learn. Now it is your turn.
Simply subscribe to my channel 🔔 and thumb up 👍 the video and say "thank you"
The link to my PayPal account is under the video if you want to send me cash donation. Thank you.
thank you for watching this was how to get the distance from the laser sensor
vr 53 l1x and display it on the lcd if you learned
something and found this useful please thumb up 👍
as this will help my video in the search algorithm of youtube. if you have comment
or question posted at the comment section below
i try to answer and reply. if you want to get updates of my upcoming videos
make sure to subscribe.
Extra clips
saying this you will see that
you