Contents

Interfacing VL53L0X Laser Distance Sensor with Arduino

VL53L0X Distance Sensor Features

The VL53L0X sensor is a laser rangefinder. First, the sensor sends a laser pulse, and the distance from object to the sensor is estimated by measuring the travel time of the laser pulse. Due to the very high speed of light, this sensor is not used in applications less than a millimeter.

This module can measure a maximum distance of 2 meters. The operating voltage is 2.8 to 5 volts and it uses the I2C protocol to communicate with the microcontroller.

You can download the datasheet of this module here.  

VL53L0X Distance Sensor Module Pinout

This sensor has 4 pins:

  • VCC: Module power supply
  • GND: Ground
  • SDA: Data signal
  • SCL: Clock signal

You can see the pinout of this module in the image below.

Required Materials

Hardware Components

Arduino UNO R3 × 1
VL53L0X Distance Sensor × 1
Male to Male jumper wire × 1

Software Apps

Arduino IDE

Interfacing VL53L0X Distance Sensor with Arduino

Step 1: Circuit

The following circuit shows how you should connect Arduino to VL53l0X sensor. Connect wires accordingly.

Step 2: Installing Library

Go to the Library Manager and search for Adafruit_VL53L0X library and install it.

Tip

If you need more help with installing a library on Arduino, read this tutorial: How to Install an Arduino Library

Step 3: Code

Upload the following code to your Arduino.

/*
  VL53L0X Distance Sensor
  modified on 26 oct 2020
  by Amir Mohammad Shojaee @ Electropeak
  
Home
Based on Adafruit Example */ #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(" 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(1000); }

The sensor library must be defined first. Then, the sensor is detected. In the main part of the program, distance from object to the sensor is measured and its value is displayed on the Serial Monitor. If there is no data to measure, “out of range” appears on the output.

The output of the Serial Monitor is as follows. By moving the sensor, you will see the measured range increases in millimeters.

Liked What You See?​
Get Updates And Learn From The Best​

Comments (14)

  • Sophie Morin Reply

    Hello, I was just wondering if this sensor would be able to work with ice or with water. Thank you very much.

    January 14, 2022 at 6:12 pm
    • Mehran Maleki Reply

      Hi.
      Yes, the VL53L0X sensor can accurately work with different solid and liquid surfaces.

      January 15, 2022 at 7:32 am
  • Sophie Morin Reply

    Hello,
    I have a follow up question. What other systems do I need to combine this sensor with to be able to measure the distance between the sensor and the ice?
    Thank you

    January 21, 2022 at 3:18 pm
    • Mehran Maleki Reply

      Hello,
      An Arduino board and the sensor are enough for measuring the distance. And you should decide what other stuffs you need, since it all depends on your project.

      January 29, 2022 at 8:50 am
  • RedSKull Reply

    I have a question….What does failed to boot the module mean here?

    March 21, 2023 at 9:39 am
    • Ali Abdolmaleki Reply

      Hi dear
      could you please share exact error accured with me?

      April 1, 2023 at 8:07 am
  • Mokka Reply

    How many of these sensors can I connect to one Arduino board? I would like to use 3, 4, 6 or 8 sensors.
    If I cannot use so many sensors in one Arduino board what could be a feasible solution? Is there a hub solution?

    March 29, 2023 at 10:52 am
  • jhon Reply

    How would the code be in case of using 2 sensors?

    June 6, 2023 at 5:10 am
    • Mohammad Damirchi Reply

      Hi jhon,
      In order to use several sensors, u can use the x-shout pin in the sensor. This way, you can temporarily disable all the sensors except for one of them.

      June 6, 2023 at 10:52 am
  • Kerin Reply

    Hi. I have an arduino mega 2560 and I am trying to connect the distance sensor. When I enter the code, it shows me the following message “error starting VL53L0X”. I checked the connections, changed the sensor, but it still keeps coming up. what could be going on?

    August 11, 2023 at 8:08 pm
    • Mohammad Damirchi Reply

      Hi Kerin
      Run I2CScanner from Arduino examples to check the address of the sensor. The I2C pins of Arduino Mega are pins 20 and 21 (and not A4 and A5 pins).

      August 13, 2023 at 9:29 am
  • [email protected] Reply

    I have a quick question; I can find the maximum range in the data sheet, but no minimum. What is the expected minimum range it can reliably measure with indoor use?

    August 16, 2023 at 6:50 am
    • Mohammad Damirchi Reply

      Hi yuri,
      As of my last knowledge, the minimum range of the VL53L0X sensor is typically around 30 mm (3 cm) in default mode. This means that the sensor can accurately measure distances starting from around 30 mm and above.

      August 16, 2023 at 3:29 pm

Leave a Reply

Your email address will not be published. Required fields are marked *