Source: https://mokxi.com/libraries/vl53l0x
Updated: 2026-11-02

Libraries / Sensors
Arduino library · Sensors

# VL53L0X (Pololu): laser distance in millimeters

The VL53L0X is a time-of-flight sensor from ST: it fires an invisible 940 nm laser pulse and counts how long the light takes to come back, which gives distance in millimeters up to about 2 m in good conditions. Pololu’s VL53L0X library is the compact way to drive it, a few hundred lines in place of ST’s full API.

Open the example in the editor See the calls

Built in on Mokxi: #include <VL53L0X.h> and it builds, with nothing to install. Free, and no account needed.

## What VL53L0X does

After init(), you either ask for one measurement at a time with readRangeSingleMillimeters() or put the sensor in continuous mode with startContinuous() and read the latest result as often as you like. Set a timeout first, or a sensor that stops answering will hang the sketch inside a read.

Every VL53L0X powers up at I2C address 0x29. Two of them on one bus need their XSHUT pins: hold all but one in reset, give the live one a new address with setAddress(), and wake the next.

Library Manager name | VL53L0X

Author | Pololu

Include | #include <VL53L0X.h>

Boards | every board Mokxi compiles for but ATtiny85

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | VL53L0X time-of-flight sensor

## Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <VL53L0X.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "VL53L0X" by Pololu from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add VL53L0X to lib_deps in PlatformIO. Mokxi follows the calls of release 1.3.1, so a sketch written here builds there too.

What to know in the simulator: ST’s reference SPAD and calibration steps are left out of init(); the part does not need them.

ESP32-C3 · Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · ESP32-C6 · Raspberry Pi Pico · Raspberry Pi Pico W · Seeed XIAO SAMD21 · STM32 · STM32 Nucleo-F411RE · STM32 Blue Pill · micro:bit V2 · Arduino Uno R4 · ESP32 DevKit · ESP32-S3-DevKitC-1 · ESP8266 NodeMCU · Arduino Pro Mini 3.3 V · Seeed XIAO ESP32-C3 · ESP32-C3 SuperMini · Seeed XIAO ESP32-C6 · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · Seeed XIAO ESP32-S3 · Arduino Nano ESP32 · Arduino Nano RP2040 Connect · Seeed XIAO RP2040 · Waveshare RP2040-Zero · Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### VL53L0X sensor

Creates the sensor object on the Wire bus at 0x29.

### sensor.setTimeout(500)

How many milliseconds a read may wait before giving up. 0 means wait for ever, which is the default and rarely what you want.

### sensor.init()

Checks the model ID and sets the sensor up. Returns false when no VL53L0X answers.

### sensor.readRangeSingleMillimeters()

Starts one measurement, waits for it and returns the distance in millimeters.

### sensor.startContinuous()

Keeps the sensor ranging back to back. Read the newest result with readRangeContinuousMillimeters().

### sensor.timeoutOccurred()

True when the last read ran out of time. Check it after each read and print TIMEOUT rather than a bogus number.

### sensor.setMeasurementTimingBudget(200000)

Spends more time on each measurement (here 200 ms, given in microseconds) for steadier readings.

### sensor.setAddress(0x30)

Moves this sensor to a new I2C address until it is powered off, so a second one can sit on the same bus.

## Example: Laser ruler

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

Open it in the editor, wired and ready to run · Laser ruler: the project page

## Common errors and how to fix them

### Failed to detect and initialize sensor!

init() returned false. Check the wiring to SDA and SCL, that Wire.begin() ran first, and that XSHUT is not held low. Run an I2C scanner: the sensor should show at 0x29.

### The reading is 8190 or 8191 all the time

That is the sensor saying nothing was in range. Point it at a surface within about 1.2 m, avoid shiny or very dark targets, and remove the protective film from the window if it is still on.

### The sketch freezes on the first read

No timeout is set, so the read waits for ever for a sensor that is not answering. Call setTimeout(500) before init() and test timeoutOccurred() after every read.

## Projects that use VL53L0X

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

Mars rover A rover that drives three waypoints by dead reckoning, steers around hazards it sees with a sonar mast, samples soil and light, and logs the mission to an OLED.

## Keep going

### Learn

- Arduino VL53L0X Distance Sensor: Wiring and Code
- I2C Scanner for Arduino and ESP32, and Fixes

### Parts

- VL53L0X time-of-flight sensor

### More sensors libraries

- DHT sensor library
- DHT20
- Adafruit_VL53L0X
- HX711 Arduino Library
- MPU6050
- Adafruit MPU6050
- BME280
- Adafruit BMP280 Library

Every built-in library · Open the editor

## Try VL53L0X without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
