Episode #8 · VL53L0X

Give Your Robot Eyes

A laser time-of-flight rangefinder the size of a grain of rice, for about two dollars. Millimeter distances over I2C, dozens of times a second — and a rover that sees the wall before it hits it.

Episode video — paste your YouTube ID to embed

What it is

The VL53L0X (by ST) fires an invisible, eye-safe infrared laser pulse and times how long the light takes to bounce back — actual time of flight, reported as a clean number in millimeters. It was built by the hundreds of millions for phone autofocus; we get it on a $2 breakout. Honest range: ~3 cm to ~1 m indoors. For a palm-sized robot, plenty.

Wiring — four wires, two of them I2C

VIN ──▶ 3.3V          (native 3.3V — no level shifting)
GND ──▶ GND
SDA ──▶ GPIO 0
SCL ──▶ GPIO 1

I2C is a party line: every chip on the bus has an address, and only the one called answers — so these same two wires can serve a dozen sensors later. Two rites of passage first: solder the loose header pins (four joints, any iron), and peel the near-invisible protective film off the sensor window, or your readings will be a lottery machine.

The code — obstacle avoidance

Install the VL53L0X library by Pololu, then it's the EP6 rover's drive() plus three lines of brain. Full sketch in the sidebar.

int mm = sensor.readRangeContinuousMillimeters();
if (sensor.timeoutOccurred() || mm > 2000) mm = 2000;  // nothing seen = clear

if (mm < 150) { drive(-180,-180); delay(250);   // back up...
                drive( 180,-180); delay(300); } // ...turn away
else          { drive( 200, 200); }             // full ahead

That's a self-driving rover: an if-statement and a laser.

What I wish I knew

  • Peel the film. It ships on the window and you'll swear there isn't one.
  • "Sensor not found"? SDA and SCL are swapped, nine times out of ten.
  • Out of range = a giant number (8190 timeout), not zero. Treat huge readings as "path clear" deliberately.
  • Physics has opinions. Matte black shortens range, glass bounces weirdly, direct sunlight floods the detector.
  • Mount it clear. Front of the chassis, dead level, nothing in view — or it reports your robot's own nose forever. (Two eyes? Every VL53L0X wakes at the same I2C address — that's a future episode. One is enough.)

⏱ Your 60-second challenge

Stop one hand-width (~100 mm) from the wall.

Drive at a wall and tune until your robot stops clean. Post your stopping distance — and the speed it survived — in the YouTube comments. Bragging rights for the fastest clean stop.