Arduino VL53L0X distance sensor

Help me by sharing this post


←PREVIOUS TUTORIAL       NEXT TUTORIAL→

See also this more info post. This sensor is a carrier/breakout board for ST’s VL53L0X laser-ranging sensor, which measures the range to a target object up to 2 m away. The VL53L0X uses time-of-flight measurements of infrared pulses for ranging, allowing it to give accurate results independent of the target’s color and surface. Distance measurements can be read through a digital I²C interface. The board has a 2.8 V linear regulator and integrated level-shifters that allow it to work over an input voltage range of 2.6 V to 5.5 V, and the 0.1″ pin spacing makes it easy to use with standard solderless breadboards and 0.1″ perfboards.

Arduino VL53L0X Time-of-Flight Distance Sensor tutorial



PART 1 - Schematic

The connections are pretty easy, see the image below with the breadboard circuit schematic. The sensor the data uisng i2c communication. For that connect A4 from the Arduino to the SDA pin and A5 to the SCL pin. Do the same for the LCD inc ase you want to print the values to the LCD screen instead of serial monitor.


We need:
1 x Arduino NANO/UNO: LINK eBay
1 x VL53L0X module: LINK eBay
1 x i2c LCD: LINK eBay
1 x Jump wires: LINK eBay
1 x Breadboard: LINK eBay

VL53L0X arduino tutorial schematic distance




PART 2 - CODE

Download the code from below. You will also need the Adafruit_VL53L0X library. Below are 2 codes, one with serial print and another with i2c LCD print. Select the one you want. Compile, upload, make the connections and open serial monitor at 9600 bauds and see the results.


Download code (serial print):
Download Adafruit_VL53L0X library:
Download i2c LCD library:


// SVL53L0X Distance Test
// http://www.electronoobs.com/eng_arduino_tut73.php

#include "Adafruit_VL53L0X.h"
Adafruit_VL53L0X lox = Adafruit_VL53L0X();

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

  // 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);  
}






Download code (i2c LCD print):

// SVL53L0X Distance Test
http://www.electronoobs.com/eng_arduino_tut73.php

#include "Adafruit_VL53L0X.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 or 0x3f for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

void setup() {
  lcd.init();
  lcd.backlight();
  Serial.begin(9600);

  // 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);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(" DISTANCE in mm ");
    lcd.setCursor(0,1);
    lcd.print(measure.RangeMilliMeter);
  } else {
    Serial.println(" out of range ");
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(" DISTANCE in mm ");
    lcd.setCursor(0,1);
    lcd.print("  OUT OF RANGE  ");
  }

  
  delay(100);  
}



VL53L0X arduino tutorial schematic distance





←PREVIOUS TUTORIAL       NEXT TUTORIAL→

Help me by sharing this post








yt_link
insta_link
fb_link
twitter_link

VL53L1X laser distance sensor
page 1/1



ADVERTISERS

WellPCB PCB Manufacturing
urPCB PCB Manufacturing
PCBGOGO PCB service

Gearbest Alfawise U30 2.8 inch Touch Screen DIY Desktop 3D Printer - U30 EU Plug Black
Alfawise U30 2.8 inch Touch Screen DIY Desktop 3D Printer - U30 EU Plug Black only $$162.89

AFFILATE

Gearbest Creality3D CR - 10S 3D Printer - EU Plug Upgrade Version Coffee and Black
Creality3D CR - 10S 3D Printer - EU Plug Upgrade Version Coffee and Black only $$352.94

Gearbest Creality 3D Ender-3 V-slot Prusa I3 DIY 3D Printer Kit 220 x 220 x 250mm Printing Size - EU Plug Black
Creality 3D Ender-3 V-slot Prusa I3 DIY 3D Printer Kit 220 x 220 x 250mm Printing Size - EU Plug Black only $$153.84

Gearbest Alfawise U20 Large Scale 2.8 inch Touch Screen DIY 3D Printer - EU - U20 EU Plug Black
Alfawise U20 Large Scale 2.8 inch Touch Screen DIY 3D Printer - EU - U20 EU Plug Black only $$253.39