Language: EN

arduino-sensor-distancia-vl53l0x

Measuring distance accurately with Arduino and VL53L0X and VL6180X laser sensors

What is a VL53L0X?

The VL53L0X is a next-generation infrared laser distance sensor that we can use with a processor like Arduino to measure distances from 50mm to 2000mm accurately. For closer ranges, the VL6180X variant has a range of 5mm to 200mm.

The VL53L0X is capable of operating even with high infrared ambient light, and incorporates a measurement compensation system that allows it to operate even behind a protective glass.

It is one of the best distance sensors available. It has superior precision to ultrasound and infrared sensors and is not affected by environmental conditions such as echoes or object reflectance.

On the other hand, the measurement angle is relatively narrow. This is an advantage in most circumstances, where we want to read the distance right in front of the sensor. Although it can also be a disadvantage, for example, when detecting obstacles.

Price

VL53L0X sensors are somewhat more expensive than other distance sensors, although in return they have superior features. We can find modules with VL53L0X for €3.90 from international sellers on eBay and AliExpress.

arduino-sensor-distancia-laser-vl53l0x-componente

How does a VL53L0X work?

The VL53L0X is a ToF (Time of flight) sensor. Its operation consists of sending a pulse of infrared light laser and measuring the time it takes for the beam to return to the sensor.

The integrated circuit incorporates a 940nm VCSEL (Vertical Cavity Surface-Emitting Laser) laser emitter, a SPAD (Single Photon Avalanche Diodes) detector, and internal electronics (called FlightSenseTM) that perform the necessary calculations.

arduino-sensor-distancia-laser-VL53L0X-funcionamiento

The measurement angle or FOV (Field of View) is 25º. This translates to a measurement area of 0.44m in diameter at a distance of 1m.

The measurement range depends on the environmental conditions (indoor or outdoor), the characteristics of the target, and the operating mode. In general, we have two modes. The standard mode is from 50 to 1200mm, and an extended mode up to 2000mm. For closer ranges, the VL6180X variant has a range of 5mm to 200mm.

Target ReflectanceConditionsIndoorOutdoor
White targetTypical200cm80cm
Minimum120cm60cm
Gray targetTypical80cm50cm
Minimum70cm40cm

Regarding precision, again it depends on the environment, target, and operating mode. The following table shows typical range and precision values according to the different operating modes of the VL53L0X.

ModeTimingRangePrecision
Default30ms1.2mSee next table
High precision200ms1.2m+/- 3%
Long range33ms2mSee next table
High speed20ms1.2m+/- 5%

This translates to the following reference precisions for standard and long-range operating modes.

IndoorOutdoor
Target ReflectanceDistance33ms
White targetat 120cm4%
Gray targetat 70cm7%

Which is summarized in the following graph, for the standard operating mode.

arduino-sensor-distancia-laser-VL53L0X-precision

For more detailed information, consult the manufacturer’s Datasheet, which includes detailed information about operating modes, measurement range and precision, among many other interesting data.

Assembly diagram

The connection of the modules that integrate the VL53L0X is simple, as communication is done through I2C. Therefore, we simply power the module from Arduino using GND and 5V and connect the SDA and SCL pins of Arduino with the corresponding pins of the sensor.

arduino-sensor-distancia-laser-vl53l0x-esquema

The diagram, seen from Arduino, would be as follows.

arduino-sensor-distancia-laser-VL53L0X-conexion

Code examples

To read the VL53L0X sensor, we will use the library developed by Adafruit, available at this link.

The library includes several usage examples. The following code takes distance readings and displays the results on the serial port.

#include "Adafruit_VL53L0X.h"

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

void setup() {
  Serial.begin(9600);

  // Initialize sensor
  Serial.println("VL53L0X test");
  if (!lox.begin()) {
    Serial.println(F("Error initializing VL53L0X"));
    while(1);
  }
}

void loop() {
  VL53L0X_RangingMeasurementData_t measure;
    
  Serial.print("Reading sensor... ");
  lox.rangingTest(&measure, false); // if true is passed as a parameter, it shows debug data on the serial port

  if (measure.RangeStatus != 4)
  {
    Serial.print("Distance (mm): ");
    Serial.println(measure.RangeMilliMeter);
  } 
  else
  {
    Serial.println("  Out of range ");
  }
    
  delay(100);
}

Download the code

All the code in this post is available for download on Github. github-full