Skip to content

Measure distance using VL53L0X ToF LASER Range sensor + Arduino + OLED (mm/cm/in)



 

Hi, this tutorial is about distance measuring using the GY-VL53L0X ToF sensor, with an Arduino Uno board, we’ll go through a test then a little project using an OLED screen and a pushbutton to measure in different units (Metrics, Imperial).

So the sensor uses the ToF (Time of Flight) technique, it sends a LASER beam to the target and as long as it’s in the range, the LASER reflects back and get detected by the sensor, the time duration between emitting and receiving is measured, the velocity which is already known (approx = c, speed of light, and if there’s a mistake, a calibration is always possible),  we can then calculate the distance, Distance = Velocity * Time.

time-of-flight-principle.png
Source https://www.terabee.com/time-of-flight-principle/

One of the advantages of the ToF method, is that it can reach higher ranges, of course depending on the module used, here as usual we’re using 2-3$ ones, but it’s a very precise module thanks to the fine LASER used, not like the Ultrasound modules, or IR ones, that spreads a wide wave, and can mislead the readings, but they have their own useful applications though.

Range and accuracy

The module’s range depends on the surface color and the mode, there are two modes: default one (we’re using) and the long range one, in the default mode it can handle up to 1200mm (1,2m ; 40 in).

table.png
Source https://www.adafruit.com/product/3317

Hardware and parts

So for this project, alongside some jump wires we’ll be using:

The module is actually very small, around (1.5cm by 1cm) very useful for small applications like ToF10120




Wirings

Wiring 1: Direct wiring of the module

Wiring 1
Wiring for direct test, we use the i²c interface so SDA/SCL with A4/A5

Wiring 2: Adding OLED i2c display and a push button

Wiring 2
Adding OLED screen and a push button

Libraries

Codes

Check the codes below, or download them here. The results can be found below too.

Code 1: Library example – VL53L0x



Code 2: Using OLED and push button

The second code that uses the OLED and button you can download it here.

Tests

First test with the Serial monitor

Test_1
Distance measured and shown in mm

If the target is out of range

Test_2
If the target is out of range

Second test using OLED + push button

The strange part here, is that I couldn’t write some sentences in the OLED screen, like as Out of range, I just wrote OoR, I wanted to add “distance” while measuring but couldn’t too, the whole OLED goes black, also there are some strange spots on the bottom right, if someone can explain please welcome. Otherwise here are the results:

Out of range case

test_4.jpg
Out of Range case displayed on OLED

Showing result in mm

Test_5
Displaying in mm



Switching to cm

Test_6
Press the button to switch to cm

changing to inches

Test_7
Press again to switch to inches, and again to go back to mm

You can of course add or remove units as you want, it’s simple. Check the video tutorial if you need help, or want to see the demo.

Yassine View All

Automation and Electrical Engineer, Electronics amateur trying to share my little projects.

One thought on “Measure distance using VL53L0X ToF LASER Range sensor + Arduino + OLED (mm/cm/in) Leave a comment

Leave a Reply

Discover more from SURTR TECHNOLOGY

Subscribe now to keep reading and get access to the full archive.

Continue reading