Arduino driver for the STMicroelectronics VL53L1X time-of-flight (ToF) distance sensor.
The VL53L1X provides accurate distance measurement using laser time-of-flight technology, supporting long-range detection, configurable timing budgets, and multiple range modes for flexible applications.
-
High-accuracy distance measurement
- Up to 4 meters range
- mm-level resolution
-
Multiple range modes
- SHORT (high ambient immunity)
- MEDIUM (balanced)
- LONG (maximum distance)
-
Configurable timing budget
- 15 ms to 500 ms
- Trade-off between speed and accuracy
-
Blocking and non-blocking read APIs
-
Ambient light measurement
-
I²C address change support
-
Status monitoring with detailed error decoding
The VL53L1X uses I²C communication.
| VL53L1X Pin | MCU Pin | Notes |
|---|---|---|
| VIN | 3.3V / 5V* | Check module specs |
| GND | GND | Common ground |
| SDA | SDA | I²C data |
| SCL | SCL | I²C clock |
| XSHUT | GPIO (optional) | Hardware shutdown control |
| GPIO1 | GPIO (optional) | Interrupt output |
- Default I²C address: 0x29
- Supported bus speeds:
- 100 kHz
- 400 kHz (recommended)
- Open Arduino IDE
- Go to Library Manager
- Search for 7Semi VL53L1X
- Click Install
- Download repository as ZIP
- Arduino IDE → Sketch → Include Library → Add .ZIP Library
if (!sensor.begin())
{
Serial.println("Sensor init failed");
while (1);
}uint16_t distance = sensor.readDistance();- Returns distance in millimeters
uint16_t ambient = sensor.getAmbient();sensor.setMeasurementRange(LONG);- SHORT → best for close range, high ambient immunity
- MEDIUM → balanced performance
- LONG → maximum distance
sensor.setMeasurementTime(100);- Range: 15 ms – 500 ms
- Higher value → better accuracy, slower updates
sensor.readBlocking();- Waits until measurement is ready
- Uses timeout internally
Status status = sensor.readOnce();- Returns immediately
- Check status before using data
uint8_t status = sensor.getStatus();- RANGE_VALID → valid measurement
- RANGE_VALID_WEAK → usable but degraded
- Other values → error conditions
sensor.setOffset(-10);- Adjusts measurement error (in mm)
sensor.changeI2CAddress(0x30);sensor.setInterruptPolarity(true); // active HIGH- Robotics (obstacle detection)
- Drones (altitude sensing)
- Smart devices (presence detection)
- Industrial distance measurement
- Gesture sensing
- MIT License