VL53L0X time-of-flight distance with ESP32
Supply 3.3-5 V
Bus I2C
I2C address
0x29
Measures distance
Pins and ESP32 wiring
| Pin | Role | ESP32 pin | Notes |
|---|---|---|---|
| VIN | Power | 3V3 | |
| GND | Ground | GND | |
| SCL | I2C clock (SCL) | D22 | |
| SDA | I2C data (SDA) | D21 | |
| XSHUT | Input (the ESP32 drives it) | D25 | Shutdown, active LOW. Optional; needed to use several sensors |
| GPIO1 | Interrupt | D35 | Interrupt output, optional |
Suggested wiring for the 30-pin ESP32 DevKit, avoiding flash, input-only and strapping pins. BoardPilot checks it for you as you wire.
Good to know
- Every sensor starts at address 0x29. To use two on one bus, hold one in reset with XSHUT and give the other a new address at start-up; the new address is lost at power-off. (ST VL53L0X datasheet, I²C interface: device address 0x52 (8-bit), change of address)
Check it is the real chip
Read register 0xC0: a genuine part answers 0xEE. BoardPilot does this automatically in “Debug a problem”.
Starter code (Arduino)
#include <Wire.h>
void setup() {
Serial.begin(115200);
Wire.begin(21, 22); // SDA = GPIO 21, SCL = GPIO 22
Wire.beginTransmission(0x29);
bool found = Wire.endTransmission() == 0;
Serial.println(found ? "VL53L0X time-of-flight distance found at 0x29" : "Not found: check power, GND and SDA/SCL");
}
void loop() {}
Sources
- ST VL53L0X datasheet, Default I2C address 0x29 (0x52 8-bit)
- ST VL53L0X API user manual, Reference register 0xC0 reads 0xEE
Try it in 3D in BoardPilot
VL53L0X time-of-flight distance on other boards: wiring and code
Arduino Mega 2560 R3 Arduino Nano Arduino Uno R3 WeAct Black Pill STM32F411CE ESP32-C3-DevKitM-1 ESP32-S3-DevKitC-1 Nordic nRF52840 DK NUCLEO-F401RE Raspberry Pi Pico 2 Raspberry Pi Pico W Raspberry Pi Pico Teensy 4.1
Learn the basics
Lesson: UART, I2C and SPI Lesson: GPIO: pins in and out Lesson: Timers and interrupts I2C I2C address SDA and SCL Pull-up resistor GPIO Interrupt
Related parts
ADS1015 12-bit ADCADS1115 16-bit ADCADXL375 high-g accelerometer (±200 g)AHT10 temperature + humidityAHT20 + BMP280 combo moduleAHT20 temperature + humidity
Part data: CC BY 4.0, free to reuse with credit to BoardPilot.