Skip to content
Get started

VL53L4CX Time Of Flight Distance Sensor

The vl53l4cx sensor platform allows you to use VL53L4CX optical time of flight (datasheet, ST) sensors with ESPHome to measure distances up to about 6m. The sensor works optically by emitting short infrared pulses and measuring the time it takes the light to be reflected back.

Unlike the VL53L1X, the VL53L4CX sees up to four targets in one measurement, for example a box under part of its field of view and the floor behind it. The target option picks the one the sensor reports. The measurements are processed by ST’s own driver on the ESP, so each sensor uses about 9.5 KB of RAM.

The I²C Bus is required to be set up in your configuration for this sensor to work. Set its frequency to 400kHz if the other devices on the bus allow it: each measurement moves about 150 bytes, which blocks the main loop for about 4ms at 400kHz but about 38ms at 50kHz, the default on most platforms. ESPHome logs a warning at compile time when the bus is slower.

# Example configuration entry
sensor:
- platform: vl53l4cx
name: "VL53L4CX Distance"

The sensor reports the distance in meters, or NaN when no target passes the checks. The first five measurements after the sensor starts (at boot or after a reset) are not reported, since ST’s driver needs them to settle.

When a measurement fails or times out, the sensor keeps its last state and the component shows a warning. After five failed measurements in a row, the state becomes NaN, so a sensor that stopped answering does not keep reporting its last distance. The sensor is then reset (through enable_pin when set, otherwise by a software reset) and set up again every 5 seconds until it answers.

  • VIN connects to 3.3V
  • GND connects to ground
  • SCL connects to I²C SCL (clock)
  • SDA connects to I²C SDA (data)
  • GPIO1 (labelled GPIO on some boards) is the interrupt output, low while a measurement is ready. Connect it to a free input pin and set it as interrupt_pin to save an I²C read on every loop.
  • XSHUT connects to a free GPIO pin and is used as enable_pin. It is optional for a single sensor at the default 0x29 address, and required for every sensor when more than one VL53L4CX shares an I²C bus.
  • distance_mode (Optional, string): The distance mode, medium or long. Defaults to long. ST’s driver has no short mode for the VL53L4CX.

  • timing_budget (Optional, Time): The time allowed for a single distance measurement, from 10ms to 200ms. A longer budget gives more accurate readings at a lower measurement rate. Defaults to 33ms.

  • target (Optional, string): Which of the valid targets in a measurement the sensor reports: nearest, farthest or strongest (the highest return signal). Defaults to nearest.

  • min_distance (Optional, distance): Targets closer than this are ignored, for example dust or insects on the cover glass. Defaults to 0mm.

  • offset (Optional, int): Calibration offset in millimeters added to every target, from -1000 to 1000. It applies before min_distance is checked. Defaults to 0.

  • address (Optional, int): The I²C address of the sensor. Defaults to 0x29. If another address is set, the sensor is re-addressed at startup, which requires enable_pin. When more than one VL53L4CX shares an I²C bus, every sensor must be set to an address other than 0x29.

  • enable_pin (Optional, Pin Schema): The pin connected to XSHUT on the VL53L4CX. Required when address is not 0x29, and for every sensor when more than one VL53L4CX shares an I²C bus.

  • interrupt_pin (Optional, Pin Schema): The pin connected to GPIO1 on the VL53L4CX. Without it, ESPHome asks the sensor over I²C whether a measurement is ready. Each sensor needs its own pin, and GPIO16 on the ESP8266 cannot be used because it has no interrupts.

  • update_interval (Optional, Time): How often to start a measurement. Defaults to 1s. Set it to never to measure continuously: each measurement starts as soon as the last one is read, so the sensor reports one every timing_budget. An interval no longer than timing_budget skips updates, and ESPHome warns about it.

  • All other options from Sensor.

With several objects in view, the sensor reports up to four targets with their distance and signal strength.

  • nearest reports the closest valid target, the way a single-target sensor behaves.
  • farthest looks past partial obstructions. A garage sensor pointed at the floor keeps reporting the floor while the open door or a car roof is at the edge of its view; combine it with min_distance so anything on the cover glass is ignored.
  • strongest reports the target that reflects the most light.
# Garage floor sensor that ignores partial obstructions
sensor:
- platform: vl53l4cx
name: "Garage Distance"
target: farthest
min_distance: 100mm
interrupt_pin: GPIOXX
update_interval: never
filters:
- median:
window_size: 15
send_every: 15

Measuring continuously reports a distance every timing_budget, about 30 times a second at the default. The median filter above sends one value for every 15 measurements; use a filter like it, or throttle, so Home Assistant is not flooded with updates.

Multiple VL53L4CX sensors can share one I²C bus. All sensors start at the same default address (0x29), so each one is held in reset with its XSHUT pin while the others are given new addresses:

  1. Connect the XSHUT pin of each sensor to a different GPIO and set it as enable_pin
  2. Give each sensor its own address other than 0x29

ESPHome rejects a configuration where a sensor on a shared bus has no enable_pin, stays at 0x29, or uses the same address as another VL53L4CX on that bus. A VL53L4CX also cannot share an I²C bus with a VL53L0X, VL53L1X or VL6180X, since those boot at 0x29 too and are re-addressed separately; put them on another bus.

# Two VL53L4CX sensors on the same I²C bus
sensor:
- platform: vl53l4cx
name: "Distance Front"
address: 0x30
enable_pin: GPIOXX
- platform: vl53l4cx
name: "Distance Rear"
address: 0x31
enable_pin: GPIOXX