VL53L0X Time-of-Flight Distance Sensor

View on Amazon
Overview
About VL53L0X Time-of-Flight Distance Sensor
The VL53L0X, developed by STMicroelectronics, is a high-precision Time-of-Flight (ToF) sensor that uses laser-based technology to measure distances up to 2 meters with exceptional accuracy. With low power consumption and fast response time, it is ideal for robotics, gesture recognition, and obstacle detection.
ā” Key Features
- Extended Measurement Range ā Accurately detects distances up to 2 meters.
- Laser-Based Time-of-Flight Technology ā Ensures fast and precise measurements.
- I²C Communication ā Seamlessly integrates with ESP32, Arduino, and other microcontrollers.
- Low Power & Compact Design ā Ideal for portable and battery-powered applications.
With its advanced sensing capabilities and efficient performance, the VL53L0X is an excellent choice for embedded systems requiring accurate distance measurement. š
Check Other sensors modules based on VL53L0X Time of Flight Sensor:
Get Your VL53L0X
š” Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
VL53L0X Specifications
Complete technical specification details for VL53L0X Time-of-Flight Distance Sensor
š Technical Parameters
VL53L0X Pinout
The VL53L0X pinout includes I2C communication pins (SDA, SCL), power supply (VIN, GND), shutdown pin (XSHUT), and interrupt pin (GPIO1) for advanced configurations.
Visual Pinout Diagram

Pin Types
Quick Tips
(ToF) laser ranging sensor,Measurement range: 30 mm to 2000 mm (2 meters),Resolution: 1 mm
of View: ~25°,Operating voltage: 2.8V to 5.5V,I2C address: 0x29 (default, changeable via XSHUT)
wavelength: 940 nm (Class 1),Fast response time: <30ms typical,Low power consumption: ~20-40 mA during ranging
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 VIN | Power | Power supply input (2.8V to 5.5V) | Typically 3.3V or 5V |
2 GND | Ground | Ground connection | Common ground |
3 SCL | I2C Clock | I2C Serial Clock line | Clock signal (requires pull-up) |
4 SDA | I2C Data | I2C Serial Data line | Bidirectional data (requires pull-up) |
5 XSHUT | Control | Shutdown pin (active low) | Used to reset sensor or change I2C address |
6 GPIO1 | Interrupt | Interrupt output pin | Optional for event-driven measurements |
Wiring VL53L0X to ESP32
Connect the VL53L0X to your ESP32 via I2C (SDA and SCL pins). The sensor operates at 2.8V to 5.5V and uses laser-based Time-of-Flight technology for accurate distance measurement. Pull-up resistors (typically 4.7kΩ) are usually included on modules.
Visual Wiring Diagram

Connection Status
Protocol
Pin Connections
| VL53L0X Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 VIN Required | 3.3V or 5V | Power supply (2.8V to 5.5V) | |
2 GND Required | GND | Ground connection | |
3 SDA Required | GPIO21 | I2C data line (with 4.7kΩ pull-up) | |
4 SCL Required | GPIO22 | I2C clock line (with 4.7kΩ pull-up) | |
5 XSHUT Optional | GPIO (optional) | Shutdown/reset control | |
6 GPIO1 Optional | GPIO (optional) | Interrupt output for event detection |
address: 0x29 (default, can be changed using XSHUT pin)
resistors (4.7kΩ) usually included on module
bus speed: Standard (100 kHz) or Fast (400 kHz)
pin allows multiple sensors on same bus (change addresses)
XSHUT low to shutdown, high to enable sensor
interrupt pin can signal when measurement ready
is Class 1 (eye-safe under normal conditions)
affected by target surface (best on matte white)
shiny, transparent, or very dark surfaces
glass should be clean for best performance
Adafruit_VL53L0X or Pololu VL53L0X library
VL53L0X Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The VL53L0X sensor fails to initialize on the ESP32, resulting in errors such as: Failed to boot VL53L0X.
Possible causes include incorrect wiring, insufficient power supply, or improper I2C communication setup.
Solution: Verify that the sensor's SDA and SCL lines are correctly connected to the corresponding I2C pins on the ESP32 (default GPIO21 for SDA and GPIO22 for SCL). Ensure that the sensor is powered within its operating voltage range (2.8V to 5.5V). Use an I2C scanner to confirm the sensor's address (default 0x29) and check for any address conflicts on the bus.
Issue: The VL53L0X sensor provides fluctuating or inaccurate distance readings when interfaced with the ESP32.
Possible causes include electrical noise, improper sensor alignment, or interference from ambient light sources.
Solution: Ensure that the sensor is properly aligned perpendicular to the target surface to receive accurate reflections. Minimize exposure to strong ambient light, especially direct sunlight, which can interfere with the sensor's infrared measurements. Implement filtering algorithms, such as averaging multiple readings, to mitigate the effects of occasional erroneous data.
Issue: When using multiple VL53L0X sensors simultaneously with the ESP32, their signals interfere with each other, causing inaccurate readings.
Possible causes include identical I2C addresses for all sensors or overlapping measurement zones.
Solution: Since the VL53L0X sensor has a fixed I2C address (0x29), using multiple sensors on the same bus requires additional hardware, such as an I2C multiplexer, to manage communication. Alternatively, consider using the sensor's XSHUT pin to control and assign different I2C addresses programmatically. Physically space the sensors apart to prevent their measurement zones from overlapping, reducing the chance of cross-talk interference.
Issue: The VL53L0X sensor experiences timeout errors during distance measurements when connected to the ESP32.
Possible causes include I2C communication errors, long cable lengths, or interference from other devices on the I2C bus.
Solution: Ensure that the I2C bus operates at an appropriate speed (standard mode at 100kHz or fast mode at 400kHz) and that the cable lengths are minimized to reduce capacitance. Check for proper pull-up resistors on the SDA and SCL lines (typically 4.7kΩ) if they are not already included on the sensor module. Isolate the sensor from other devices on the I2C bus to identify potential sources of interference.
Debugging Tips
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
VL53L0X Programming Examples
Ready-to-use code examples for different platforms and frameworks
#include <Wire.h>
#include <Adafruit_VL53L0X.h>
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
void setup() {
Serial.begin(115200);
Wire.begin();
if (!lox.begin()) {
Serial.println("Failed to initialize VL53L0X! Check connections.");
while (1);
}
Serial.println("VL53L0X Initialized.");
}
void loop() {
VL53L0X_RangingMeasurementData_t measure;
lox.rangingTest(&measure, false);
if (measure.RangeStatus != 4) { // Status 4 means no object detected
Serial.print("Distance: ");
Serial.print(measure.RangeMilliMeter);
Serial.println(" mm");
} else {
Serial.println("Out of range.");
}
delay(500);
}lox.begin() method. In the loop(), the rangingTest() method measures the distance to an object in millimeters, which is printed to the Serial Monitor every 500 ms. If no object is detected or the object is out of range, a corresponding message is displayed. The I2C protocol facilitates communication with the sensor.#include <stdio.h>
#include "driver/i2c.h"
#include "esp_log.h"
#define I2C_MASTER_NUM I2C_NUM_0
#define I2C_MASTER_SDA_IO 21
#define I2C_MASTER_SCL_IO 22
#define I2C_MASTER_FREQ_HZ 100000
#define VL53L0X_ADDR 0x29
static const char *TAG = "VL53L0X";
void app_main() {
i2c_config_t i2c_config = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_MASTER_SDA_IO,
.scl_io_num = I2C_MASTER_SCL_IO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_MASTER_FREQ_HZ,
};
ESP_ERROR_CHECK(i2c_param_config(I2C_MASTER_NUM, &i2c_config));
ESP_ERROR_CHECK(i2c_driver_install(I2C_MASTER_NUM, I2C_MODE_MASTER, 0, 0, 0));
ESP_LOGI(TAG, "VL53L0X initialized.");
while (1) {
// Placeholder for distance measurement implementation
ESP_LOGI(TAG, "Reading distance...");
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}I2C_MASTER_NUM defines the I2C port, and GPIO21 and GPIO22 are used as the SDA and SCL lines. While the provided code sets up the I2C communication, additional functions for sending measurement commands and reading data from the VL53L0X would need to be implemented to perform distance measurements. The example demonstrates how to initialize the sensor and prepare for measurements.sensor:
- platform: vl53l0x
name: "VL53L0X Distance"
update_interval: 500msvl53l0x platform to interface with the sensor. The sensor's name, 'VL53L0X Distance,' makes it easily identifiable in home automation platforms like Home Assistant. The update_interval of 500 ms ensures frequent updates for applications requiring real-time distance measurements.platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/Adafruit VL53L0X @ ^1.2.0
monitor_speed = 115200main.cpp
#include <Wire.h>
#include <Adafruit_VL53L0X.h>
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
void setup() {
Serial.begin(115200);
Wire.begin();
if (!lox.begin()) {
Serial.println("Failed to initialize VL53L0X! Check connections.");
while (1);
}
Serial.println("VL53L0X Initialized.");
}
void loop() {
VL53L0X_RangingMeasurementData_t measure;
lox.rangingTest(&measure, false);
if (measure.RangeStatus != 4) { // Status 4 means no object detected
Serial.print("Distance: ");
Serial.print(measure.RangeMilliMeter);
Serial.println(" mm");
} else {
Serial.println("Out of range.");
}
delay(500);
}Wire.begin(), the sensor is configured using lox.begin(). The rangingTest() function retrieves distance measurements in millimeters, which are printed to the Serial Monitor every 500 ms. A status check ensures meaningful data is displayed, and the code gracefully handles 'out of range' cases.from machine import I2C, Pin
from vl53l0x import VL53L0X
# Initialize I2C (SDA=21, SCL=22)
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# Initialize VL53L0X sensor
sensor = VL53L0X(i2c)
print("VL53L0X Distance Sensor Example")
while True:
distance = sensor.read() # Distance in mm
print("Distance: {} mm".format(distance))
time.sleep(0.5)read() method is called in a loop to fetch distance measurements in millimeters. The measurements are displayed on the console every 500 ms. The library simplifies communication with the sensor, handling low-level I2C details internally.Wrapping Up VL53L0X
The ESP32 VL53L0X Time-of-Flight Distance Sensor is a powerful distance sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
Best Practices
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Safety First
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.
Ready to Start Building?
Now that you have all the information you need, it's time to integrate the VL53L0X into your ESP32 project and bring your ideas to life!
Explore Alternative Sensors
Looking for alternatives to the VL53L0X? Check out these similar sensors that might fit your project needs.

VL53L1X Time-of-Flight Sensor
The VL53L1X is a high-accuracy long-distance laser-ranging sensor from STMicroelectronics. It uses a 940nm VCSEL emitter and advanced SPAD...

GY-530 VL53L0X Time-of-Flight Sensor
The GY-530 is a breakout board for the VL53L0X Time-of-Flight (ToF) sensor from STMicroelectronics. It uses FlightSense technology to...

HC-SR04 Ultrasonic Distance Sensor
The HC-SR04 is a versatile ultrasonic distance sensor capable of measuring distances up to 4 meters with high precision. It is widely used...





