Home Code Arduino and VL53L0X Time-of-Flight example

Arduino and VL53L0X Time-of-Flight example

by shedboy71
[lebox id="1"]

The VL53L0X is a new generation Time-of-Flight (ToF) laser-ranging module housed in the smallest package on the market today, providing accurate distance measurement whatever the target reflectances unlike conventional technologies. It can measure absolute distances up to 2m, setting a new benchmark in ranging performance levels, opening the door to various new applications.

The VL53L0X integrates a leading-edge SPAD array (Single Photon Avalanche Diodes) and embeds ST’s second generation FlightSenseTM patented technology.

Here is a typical module

The VL53L0X’s 940 nm VCSEL emitter (Vertical Cavity Surface-Emitting Laser), is totally invisible to the human eye, coupled with internal physical infrared filters, it enables longer ranging distances, higher immunity to ambient light, and better robustness to cover glass optical crosstalk.

 

Schematics/Layout

 

arduino and VL53L0X

arduino and VL53L0X

 

Code

 

You will need to install the adafruit library – https://github.com/adafruit/Adafruit_VL53L0X

[codesyntax lang=”cpp”]

#include "Adafruit_VL53L0X.h"

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

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

  // wait until serial port opens for native USB devices
  while (! Serial) {
    delay(1);
  }
  
  Serial.println("Adafruit VL53L0X test");
  if (!lox.begin()) {
    Serial.println(F("Failed to boot VL53L0X"));
    while(1);
  }
  // power 
  Serial.println(F("VL53L0X API Simple Ranging example\n\n")); 
}


void loop() {
  VL53L0X_RangingMeasurementData_t measure;
    
  Serial.print("Reading a measurement... ");
  lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!

  if (measure.RangeStatus != 4) {  // phase failures have incorrect data
    Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
  } else {
    Serial.println(" out of range ");
  }
    
  delay(100);
}

[/codesyntax]

 

Output

Open the serial monitor, move the sensor nearer and farther away from objects for example your hand

VL53L0X API Simple Ranging example

Reading a measurement… Distance (mm): 70
Reading a measurement… Distance (mm): 70
Reading a measurement… Distance (mm): 71
Reading a measurement… Distance (mm): 72
Reading a measurement… Distance (mm): 71
Reading a measurement… Distance (mm): 71
Reading a measurement… Distance (mm): 70
Reading a measurement… Distance (mm): 71
Reading a measurement… Distance (mm): 67
Reading a measurement… Distance (mm): 114

 

Links

https://www.st.com/resource/en/datasheet/vl53l0x.pdf

1pcs GY- 530 VL53L0X World smallest Time-o f-Flight (ToF) laser ranging sensor 10 orders

Share
[lebox id="2"]

You may also like

Leave a Comment