Skip to main content

vl53l0x

Precise time-of-flight laser distance measurement from 30-1200mm using the VL53L0X sensor via I2C.

Overview

The vl53l0x node measures distance using the STMicroelectronics VL53L0X time-of-flight laser ranging sensor via I2C. Unlike ultrasonic sensors, it uses a VCSEL laser for fast, accurate measurements unaffected by target color or reflectivity. Ideal for liquid level sensing, object detection, and robotics.

30-1200
Range (mm)
±3%
Accuracy
I2C
Interface
940nm
Laser (eye-safe)

Wiring (I2C)

Connection

VCC → 3.3V

GND → GND

SDA → GPIO 2 (Pin 3)

SCL → GPIO 3 (Pin 5)

XSHUT → GPIO (optional, for multi-sensor)

Default address: 0x29 (configurable via XSHUT pin)

Measurement Modes

Default: Balanced speed and accuracy

High Speed: 20ms, reduced range

High Accuracy: 200ms, best precision

Long Range: Extended to 2000mm

Properties

Property Type Default Description
bus number 1 I2C bus number
address number 0x29 I2C address (default 0x29)
mode string "default" "default", "high_speed", "high_accuracy", "long_range"
timing number 33000 Timing budget in microseconds
interval number 250 Reading interval in milliseconds

Output

{
  "payload": 342,
  "distance": 342,
  "unit": "mm",
  "status": "valid",
  "timestamp": 1640000000000
}

Example: Liquid Level Sensing in Tank

Mount the sensor above a tank to measure liquid level and calculate volume remaining.

vl53l0x function gauge
// Function node: Calculate tank level
var distance = msg.distance; // mm from sensor to liquid
var tankHeight = 500;        // Total tank depth in mm
var tankDiameter = 300;      // Tank diameter in mm

// Distance to liquid surface → liquid height
var liquidHeight = tankHeight - distance;
liquidHeight = Math.max(0, Math.min(tankHeight, liquidHeight));

// Calculate volume (cylindrical tank)
var radius = tankDiameter / 2;
var volume = Math.PI * Math.pow(radius, 2) * liquidHeight;
var volumeLiters = volume / 1000000; // mm³ to liters
var percent = (liquidHeight / tankHeight) * 100;

var status = "ok";
if (percent < 10) status = "critical";
else if (percent < 25) status = "low";

msg.payload = {
    distance: distance,
    level: liquidHeight.toFixed(0),
    percent: percent.toFixed(1),
    liters: volumeLiters.toFixed(2),
    status: status
};

return msg;

Example: Conveyor Belt Object Counter

Count objects passing on a conveyor belt by detecting distance changes.

// Function node: Object detection and counting
var distance = msg.distance;
var threshold = 200;  // Object closer than 200mm
var prevState = flow.get('objectPresent') || false;
var count = flow.get('objectCount') || 0;

var objectPresent = distance < threshold;

// Count on rising edge (object enters beam)
if (objectPresent && !prevState) {
    count++;
    flow.set('objectCount', count);
}

flow.set('objectPresent', objectPresent);

msg.payload = {
    distance: distance,
    objectPresent: objectPresent,
    count: count
};

return msg;

Use Cases

Liquid Level Sensing

Non-contact measurement of water, fuel, or chemical levels

Robotics Navigation

Obstacle detection and avoidance for mobile robots

People Counting

Detect people passing through doorways or corridors

Gesture Recognition

Detect hand proximity for touchless interfaces

Related Nodes