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.
GY-530 VL53LOX Rangefinder Module
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
Software Apps
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.
Comments (14)
Hello, I was just wondering if this sensor would be able to work with ice or with water. Thank you very much.
Hi.
Yes, the VL53L0X sensor can accurately work with different solid and liquid surfaces.
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
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.
I have a question….What does failed to boot the module mean here?
Hi dear
could you please share exact error accured with me?
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?
Hi dear
yes you can use for 8 sensors with same ID for your project.
only thing that you need for this is PCA9548A. actually it is a I2C Multiplexer.
please follow below for more details
https://electropeak.com/learn/connect-multiple-i2c-devices-to-arduino-using-i2c-multiplexer-tca9548a/
How would the code be in case of using 2 sensors?
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.
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?
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).
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?
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.