Using the VL53L1X with Arduino involves wiring up the sensor to your Arduino-compatible microcontroller, installing the Adafruit VL53L1X library and running the provided example code.

Wiring

Wire as shown for a 5V board like an UNO. If you are using a 3V board, like an Adafruit Metro, wire the board's 3V pin to the VL53L1X Vin.

  • Board 5V to sensor Vin
  • Board GND to sensor GND
  • Board SCL to sensor SCL
  • Board SDA to sensor SDA
  • Board 2 to sensor GPIO
  • Board 3 to sensor XSHUT

Library Installation

You can install the VL53L1X library for Arduino using the Library Manager in the Arduino IDE.

Click the Manage Libraries ... menu item, search for VL53L1X , and select the Adafruit VL53L1X library:

If asked about dependencies, click "Install all".

Load Example

Open up File -> Examples -> Adafruit VL53L1X -> VL53L1X_simpletest and upload to your Arduino wired to the sensor.

#include "Adafruit_VL53L1X.h"

#define IRQ_PIN 2
#define XSHUT_PIN 3

Adafruit_VL53L1X vl53 = Adafruit_VL53L1X(XSHUT_PIN, IRQ_PIN);

void setup() {
  Serial.begin(115200);
  while (!Serial) delay(10);

  Serial.println(F("Adafruit VL53L1X sensor demo"));

  Wire.begin();
  if (! vl53.begin(0x29, &Wire)) {
    Serial.print(F("Error on init of VL sensor: "));
    Serial.println(vl53.vl_status);
    while (1)       delay(10);
  }
  Serial.println(F("VL53L1X sensor OK!"));

  Serial.print(F("Sensor ID: 0x"));
  Serial.println(vl53.sensorID(), HEX);

  if (! vl53.startRanging()) {
    Serial.print(F("Couldn't start ranging: "));
    Serial.println(vl53.vl_status);
    while (1)       delay(10);
  }
  Serial.println(F("Ranging started"));

  // Valid timing budgets: 15, 20, 33, 50, 100, 200 and 500ms!
  vl53.setTimingBudget(50);
  Serial.print(F("Timing budget (ms): "));
  Serial.println(vl53.getTimingBudget());

  /*
  vl.VL53L1X_SetDistanceThreshold(100, 300, 3, 1);
  vl.VL53L1X_SetInterruptPolarity(0);
  */
}

void loop() {
  int16_t distance;

  if (vl53.dataReady()) {
    // new measurement for the taking!
    distance = vl53.distance();
    if (distance == -1) {
      // something went wrong!
      Serial.print(F("Couldn't get distance: "));
      Serial.println(vl53.vl_status);
      return;
    }
    Serial.print(F("Distance: "));
    Serial.print(distance);
    Serial.println(" mm");

    // data is read out, time for another reading!
    vl53.clearInterrupt();
  }
}

Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. You should see the the values from the senor being printed out.

This guide was first published on Oct 27, 2021. It was last updated on Jun 23, 2024.

This page (Arduino) was last updated on Jun 23, 2024.

Text editor powered by tinymce.