in this video we are going to use this vl53r0x laser distance meter to display the distance
on the lcd 1602 with I square c module
with just four wires also we'll see how we can use it with this larger screen
this is the wiring diagram for vl53 l0x because we needed two uh I square c connection and also
five volts for this module for the lcd and five volts for the laser sensor I’ve used pin 13 for
extra vcc for this in Arduino we have I square c pins scl and sda here and a4 and e5 also can
be used as I’ve explained before so without any breadboard we can use it like this vcc have been
connected using green wires to pin 13. in the code we have defined this pin as extra vcc pin
second and ground have been connected using blue wire to ground and here scl or clock
is connected using a brown wire with that to the last pin this is scl labeled inside it
and sda have been connected using a gray wire to the sda for the lcd from the top we see ground
have been connected using black wire to the ground and then vcc have been connected using white wire
to 5 volts and an sda using a grey wire to a4 scl or clock have been connected
using a purple wire to a5 if you're using a blue module the laser sensor with this color
or with this color all the locations are the same and also with the black pay attention to this
diode the red diode it should be on this side because the label is on the other
side and here is the wiring for this vl53l0x
on actual Arduino it has been labeled from here vcc is connected using green to pin 13
and the second pin ground is connected using blue wire to the ground of Arduino and then
we have a purple wire it's connected to scl as it has been connected also to SCL of Arduino
and the last one is sda have been connected using gray wire to the sda of Arduino if you're using
this type of Arduino module the sda and a fail have been labeled here not on the pin header
and for the lcd 1602 but I with the I2C module scl have been connected using this pink wire
to a5 sda has been connected using gray wire to a4 and vcc have been connected using white wire
to 5 volts and the ground have been connected using black wire to ground of Arduino
now this is a square c scanner let's run it and see the square c address for this
laser sensor and for the display
and as you can see it shows 0 to 0x29 that 29 is the address for the vl53l0x and 3fs for my module
and here if I if I connect my other module
it shows 26 so this is 26. let me now explain the code this is exactly the same as the previous
lecture which I’ve explained it the only new thing is this one vcc2 we have defined
13 as vcc for this for this module this liquid crystal underscore is i2c is a library that
we have studied in previous lesson you have to download and include it when you download it it
will be a zip file and then include it this then we create an instance of this class we call it lcd
pass the I square c address for the lcd 16 character and two line we have to pass this
and this is a constant integer type we call it type and one if you want to display in millimeter
and two if you want to display centimeter inside the setup we initialize the serial monitor
we set the vcc as an output using the pin mode command now this pin a spin 13 is an output and
then using digital right we set the same pin high so this gives us five volts for the for the module
we say lcd dot begin initializing their cd and also resetting the backlight and the setup is done
inside the loop sensor dot read range continuous millimeter this is long function name this at this
point it will read the distance in millimeter and we store it in a variable called distance
and then we print the text on the screen
clear the lcd because this is a loop and lcd will has to be clear from previous value we print this
text on the screen this is the text that you are reading and then we set the cursor 0 line 1
so it goes cursor 0 line 1 that was line 0. now we are here and we print the ist with the dot
with this column
and after that after seven characters we we set the cursor the seven zero one two three four five
six seven it starts from here and we check if the type is two then we convert the distance how we do
it to centimeter we get a distance divided by 10 and then we make it float because when you convert
from millimeter to centimeter the portion that is shown as millimeter should be as a decimal point
so we converted the integer to float and the result of this will be stored here we call it
distance cm centimeter of type float and then we print the same value that is there
we print the distance after that we print centimeter or millimeter
beside it this is for the serial monitor that prints the value for us
continuously the same value that you read here is displayed and here as well
else means if the type is not two then we needed a millimeter we print the distance we print this
mm at the end pay attention here we did not set the cursor without the cursor as soon as
you have space it will just work fine after that we print this on the screen with millimeter
instead of centimeter and this is part of the debugging system if the timeout happens
it will print this leave it it will help you to understand and then this will print a new line
and 500 millisecond is the blank that you see every half a second it reads the data
and here is a demonstration as you can see it shows some distance here
because in front of this ruler we have nothing and let me put it
directly at zero and let me put this this box here at 14 140 millimeter
and it shows around four millimeter deviation let me go to 10.
this shows 96 millimeters
and now I’m at 60
30
it shows very exact whoa and and I’m now pointing it to the wall
110 centimeter about a meter and if I go further
and if I point it to the ceiling which is far away slowly you can see that it
shows eight one nine zero when you see this it shows that it is out of range
it cannot measure more than 1.2 meter in continuous measurement
and now I’m inserting the other module just pay attention for the vcc
when I insert it you will see that you read minus 1 mm for that reason just reset this
press the reset on your Arduino and you will see that it will get fixed
because when you connect it you have to give it a little time now in 90 millimeters
it shows 94 one thing that I noticed that this reflective surface if I point it to
this you will get incorrect very incorrect value for example I’m putting it now at 10.
this is 100 millimeter as you can see it shows 88 or 80 it's huge difference
as I put the other edge you will see that it shows very accurate
and let me just point it towards the ruler
that's 11 centimeter
and the same way this black module works without any change in
wiring the only thing you need is to reset I just reset this
so it's 100 millimeter
and the same code also will work with this larger screen 2004
thank you for watching this was how to use this vl53l0x module to display the distance on lcd 1602
display