The VL53L0X is an amazing laser time of flight range sensor that connects via I2C. It can be used in similar ways to the HC-SR04 module, but doesn't suffer from many of the HC-SR04's problems.

It'll measure distances up to 2m, accurate to around 5%, and needs between 2.5 and 3.6 volts.


The easiest solution is to use a 'VL53L0X satellite' board from the X-NUCLEO-53L0A1:

You need to wire up as follows:

Pin Name Espruino
2 SCL I2C SCL (B10)
3 XSDN Any GPIO (B4)
4 SDA I2C SDA (B3)
5 VDD 3.3v
7 N/C
8 N/C
9 N/C
10 N/C

The square pin on the PCB is pin 1

XSDN is for shitting down/waking up the device. You can just connect it straight to VDD if needed.


You can use the VL53L0X (About Modules) module with the VL53L0X as follows:

digitalWrite(B4,1); // set XSDN -> turn the sensor on
var laser;
setTimeout(function() {
  laser = require("VL53L0X").connect(I2C2);
  // make one reading
  console.log(laser.performSingleMeasurement().distance+" mm");
  // or repeatedly measure
  setInterval(function() {
    // sets LED brightness depending on distance
    var dist = laser.performSingleMeasurement().distance;
    analogWrite(LED1, (300-dist)/300, { soft:true, freq:200 });
  }, 50);

XSDN isn't needed and can be connected to 3.3v. It is used for powering the device on and off (and you must leave a 2ms delay between powering the VL53L0X on and using it).

Currently there is no calibration performed so the results aren't as accurate as they could be. ST don't appear to have documented the sensor's interface properly, so to calibrate you would need to reverse engineer their libraries.


VL53L0X.prototype.r = function (addr, n) { ... }

VL53L0X.prototype.w = function (addr, d) { ... }

/* Perform one measurement and return the result.

Returns an object of the form:

   distance , // distance in mm
   signalRate, // target reflectance
   ambientRate, // ambient light.
   effectiveSpadRtnCount //  effective SPAD count for the return signal
VL53L0X.prototype.performSingleMeasurement = function () { ... }

exports.connect = function (i2c, options) { ... }


The cheapest way to get a VL53L0X at the moment seems to be from eBay

However you can also use ST's X-NUCLEO-53L0A1 kit (shown above):

Or can also buy boards from:

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.