VL53L0X Laser Distance Meter
ESP32 DevKit (WROOM-32)·Arduino C++·Updated Jul 27, 2026·by FluxBench TeamIncludes Lab + Schematic
A contactless tape measure: a VL53L0X time-of-flight laser sensor is read with the standard VL53L0X library (init + continuous ranging), and the distance is shown in big digits on a 128x64 OLED in centimetres with a live proximity bar. Click the VL53L0X on the bench and drag its distance slider while the sketch runs - the display follows, the zone word changes CLEAR / NEAR / TOO CLOSE, and the red LED on GPIO 4 lights when a target comes within 10 cm.
sketch.ino
// VL53L0X Laser Distance Meter - a contactless tape measure + parking alarm.
// Click the VL53L0X on the bench and drag its distance slider while the sketch
// runs - the OLED shows the range in cm with a proximity bar, and the red LED
// lights with TOO CLOSE when something comes within 10 cm.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <VL53L0X.h>
#define ALERT_PIN 4
#define NEAR_MM 300 // under 30 cm = NEAR
#define CLOSE_MM 100 // under 10 cm = TOO CLOSE
Adafruit_SSD1306 display(128, 64, &Wire, -1);
VL53L0X sensor;
void setup() {
Serial.begin(115200);
pinMode(ALERT_PIN, OUTPUT);
Wire.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.display();
sensor.setTimeout(500);
sensor.init();
sensor.startContinuous();
Serial.println("Distance meter ready - drag the VL53L0X slider");
}
void loop() {
uint16_t mm = sensor.readRangeContinuousMillimeters();
float cm = mm / 10.0;
bool close = mm < CLOSE_MM;
bool near = mm < NEAR_MM;
digitalWrite(ALERT_PIN, close ? HIGH : LOW);
const char* zone = close ? "TOO CLOSE" : near ? "NEAR" : "CLEAR";
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
display.print("LASER DISTANCE");
display.setTextSize(3);
display.setCursor(0, 16);
display.print((int)(cm + 0.5));
display.setTextSize(2);
display.print(" cm");
display.setTextSize(1);
display.setCursor(0, 44);
display.print(zone);
// proximity bar: full at 0 mm, empty at 2000 mm
long barW = 128 - (mm * 128L / 2000);
if (barW < 0) barW = 0;
if (barW > 128) barW = 128;
display.fillRect(0, 56, (int)barW, 8, SSD1306_WHITE);
display.display();
Serial.print("Range: ");
Serial.print(mm);
Serial.print(" mm (");
Serial.print(cm, 1);
Serial.print(" cm) ");
Serial.println(zone);
delay(200);
}Built with FluxBench.AI — the AI workbench for embedded projects.