how to use VL53L1X time-of-flight laser sensor with range of 4 meter. this
modulus offered in this shape and color on Aliexpress and eBay and also it is
these modules are sold on Aliexpress I purchased one for $9.39 cents with few
dollars of shipping and the other module was also sold around $9.28 cents what
four or five dollars shipping I received them about in a month. It is from ST
semiconductor they use I squared C (I2C) communication with to wires in both cases here
we have GPIO, this is the interrupt pin and this is X shut this is to shut it down and in
some cases you want to shut this down and only it turn it on when you need it
to measure but for our application continuously we will use it so we would
use VN 3.3 or up to 5 volts ground and then SDA and SCL these two are for I
square C communication we will leave these two off. I'm going to go through
this and the datasheet explained what they do but without this it can be used
and here in this module they put those two pins on the other side and we have
VCC here and ground here if the SDA and SCL and xshot an interrupt port on this side so
you know that you're not making mistake. we have a voltage regulator here that
when you inject 5 volts you will get 3.3 volts for the module so you can connect
it 3.3 or to 5 volts. the frequency is 50 Hertz which means you
can measure up to 50 times a second which is very fast so the distance the
range can be set up to 4 meter but this has three modes medium long and short
depending on which one we want to use in terms of accuracy you can select
different range and we're going to just test it in this video I'm just going to
display the value on the serial monitor in the VL53L0X (link below this video)
the video showing how to change the I2C dress with some methods but
in this one they've created a function with the library so you can easily
change the I2C address because if you want this one to have
separate address in terms of connecting with multiple I2C devices this is the
VL53L1X laser sensor, here is the actual module
the size is 4.9 by 2.5 by 1.6 mm this is
it is invisible laser of 490 nanometer wavelength of class 1
Datasheet Viewed
let's have a look at the data sheet for VL53L1X as they call it a long distance
time-of-flight sensor and here's a block diagram or the pins ground, SDA, SCL and
AVDD. these are the pins that we are using. We are not using the GPIO and Xshut
these two extra pins. on the module we have only this ground Xshut and GPIO
it uses SPAD single photon Avalanche diode receiving array and the range is 400
centimeter and the frequency is 50 Hertz it means 50 times a second it can
measure and the distance that it measures varies depending on the setting
that you have it has a mode distance mode we can set it a short medium and
long and short it measures up 236 centimeter and in the dark, 290 for the
medium and 360 centimeter in the long range (setting) and the maximum distance and the strong
ambient light other lights that are disturbing it the range will be reduced
significantly and in terms of timing budget or timing that it allows it can
go between 20 millisecond to 1000 millisecond or one second per
measurement thus determines the frequency and as you can see if you go with 20
millisecond in a minimum timing budget that we for short this and mode 33
will be for all the distance mode and 14 millisecond budget allows maximum
distance of 4 meters so if you want to measure 4 meter we have to fit it at this value
depending on your application sometimes when the measurement is not
needed you can shut this down using the Xshut pin here and it has been defined
here when you connect it to low it will be like this the power goes on it goes
on a standby mode until the Xshut is HIGH so that is when you connect it to
LOW but if you connect at HIGH or if you do not
this is how it behaves when the power is off the Xshut is also off when you turn
it on it xshot automatically goes HIGH without even connecting it so the device
will boot immediately the module comes with a user manual that was a datasheet
this is the user manual (the link is below this video) and it will explain how to use it
I will provide you the link for this if you want to have a look at it. when the
package arrives they put a piece of plastic make sure to remove it otherwise
it will affect the measurement length of the module is twenty three point nine
millimeters 23.9mm or zero point nine four inch 0.94
the width is 10.4 mm or 0.41 inch depth of the
module or thickness is four millimeters or 0.15 inch. Width of this is 12 millimeters
length is 16 millimeters depth is 3 millimeters. If your concern with weight
with the pins it's 1.1 gram 0.9 grams for the small one
Soldering pin headers
when you receives the module it is shipped like that with a pin headers that you
have to solder it or if you purchase this module the same way you have to
break this and connect four pieces here and if you need a interrupt connect the
two in here otherwise you can use just this side I'm inserting the pins from
the bottom because I want the face to be free without wires on this side I'm just
holding it with one hand with one finger and then feeding the solder only on 1 pin
once this holds it then go to the next side now your finger is free
you
and continue the rest
Wiring explained
let me now explain the wiring the code explanation and the wiring diagram for
this is available as part of my Arduino course at udemy.com the link to my course at
udemy is below this video. vn is connected here via this black
wires to 5 volts ground is connected using this brown wire to the ground and
here we have SCL the red is connected to A5, SDA is connected to A4. These pins
for I2C communication pin and also you can connect it to SDA and SCL
here as well at this spot
Code explained
I'll provide you the link this is the Sparkfun library . click and
download it and save it in my downloads folder somewhere you Sparkfun and then
click on a Sketch->include library->add . zip library from here pointed to
where you have downloaded I have downloaded into my downloads folder and
here Sparkfun VL53 L1x click on open then close arduino all
instances and reopen it on file->examples and at the bottom you see Sparkfun
VL53L1X click and open "read distance" so other components is supposed
to be included with this library this include Wire. is for I2C
communication and this is for that device if you're connecting it to these
two pens then 2 or 3 X shut or an interrupt this is the GPIO 1 and
distance sensor we are initializing creating an instance of this class and
we call it distance sensor inside the setup() wire.being() initializes I2C
communication this is initializing the serial monitor this is
just a text. And here we can set the distance if you want to measure long
distance, use distanceSensor.setDistanceModeLong
this will be for long distance measurement otherwise commenters and
then use this one setdistancemodeshort so this way you can set the mood
inside the setup() there's no library to set this at the
medium and then inside the loop this is starting the range sensing then to
measure we say distancesensor.getDistance() as an integer we are getting it
here and then after that we are stopping. This is holding now the distance
and in millimeter and here Serial.print will print this text because
this is inside that double quotation and that distance has a variable we print it
immediately after that. and then here we are getting the distance multiplying
it by this factor to convert it to inch and then this distance an inch divided
by twelve to make it feet and in case if you need those values and printLN will
create this line and immediately after
that this value and with a little tab this backslash T \t mean tab character extra
space and then this this is a new line and the loop will continuously read this
code and measure the distance
Demonstration
and by the way I've set this too short and distance measurement now let me
demonstrate it I have set this to display the distance in millimeter and
also distance an inch with two decimal places there is the module I've attached
it to this box and just putting a weight here and a harddrive
to hold it for me this is exactly and at the zero
and let's put this at twenty centimeter now this is a 20 centimeter
and as you can see we are reading exactly 20 centimeter or 200 or 201 it's
just one millimeter off and it is fluctuating let's see how close this can
measure on going 10 centimeters
as you can see as we got closer we are getting four or five centimeter off let
me go further at 30 centimeter
now it's 90 or 80 290 so 10 millimeter that's one centimeter off diviation when you
measure the distance of 30 centimeters each side so you can see it nothing for
the 9 inch you see 8.8 6 in terms of inch let's see at 6 inch
at 6 inch it is very accurate and by the way I've set this too short and
distance measurement now I'm exactly at 12 inch and we are reading 11.5
half-inch difference this portion I have prepared this from library
now if I upload that
it will also tell you the SPAD value so this measurement is with this amount
number of rays that it has and it measures and now I'm pointing this to a
for away distance in the hallway 3.7m or three point eight that's 370
centimeter let me pint it farther what happens now this is being pointed I've
uploaded the code the same and now it's the red module I'm pointing it to the
computer screen 400 millimeter pointing it to the wall further away so we are
reading
so we are reading forehand so we are reading three meters and let me point it
to farther away on the wall
Demonstration in complete dark space
let me turn the light off and see how it affects the measurement it's around 290
about 3mm to 5mm difference in complete dark room
the distance changes when mount of the ambient changed you keep
all this in mind when you're using it and some critical application I will
have separate video explaining and testing it under different conditions
with playing with different codes and the result will be presented as video for my
Patrons at patreon.com the link to my patreon account is below this video as
well there is some variation in measurement have compensated with
20-millimeter and it was responding properly in certain distance again when
I change the distance they didn't show the exact value and the measurement
varied by about 15 to 20 millimeters so that's if you are doing some precise
measurement that will affect your measurement so keep that in mind or some
offset based on the environment ambient light the environment that is affecting
it especially infrared or sunlight will have a lot of infrared or sun light will
module if you liked this video and learned something please thumb up 👍 as
see we are reading very exact value because there is some variation here
between the distance and space of this module that thickness of the board the