In this project, we will build a compact and accurate laser distance meter using an Arduino Uno, a VL53L0X Time-of-Flight (ToF) laser ranging sensor, and a 0.96″ OLED SSD1306 display. The device will measure and display real-time distance readings in both millimeters and centimeters, accompanied by a smooth progress bar animation on the OLED screen. This beginner-friendly tutorial is perfect for anyone interested in laser-based distance measurement, I2C communication, and display interfacing with Arduino.
Project Overview
The VL53L0X sensor from STMicroelectronics is a Time-of-Flight (ToF) sensor that measures distance by calculating the time it takes for a laser pulse to travel to a target and back. Unlike ultrasonic sensors, it provides precise and fast readings even in compact environments and under various lighting conditions. This makes it ideal for robotics, automation, and smart sensing projects.
The OLED display visualizes the distance in real time, making the project not only functional but also visually appealing. Both the OLED and VL53L0X communicate with the Arduino via the I2C bus, keeping the wiring simple.
Watch the video demonstration here:
PCBWay offers high-quality PCB prototyping and assembly at an affordable price, starting at just $5 for 5 PCBs. With fast turnaround, great customer support, and easy online ordering, it’s a top choice for hobbyists and professionals alike.
Components Required
| Component | Quantity | Description |
|---|---|---|
| Arduino UNO | 1 | Main microcontroller board |
| VL53L0X ToF Sensor | 1 | Laser-based distance sensor (up to 2 meters) |
| OLED Display (SSD1306, 128×64) | 1 | 0.96″ I2C OLED display |
| Breadboard | 1 | For quick prototyping |
| Jumper Wires | — | Male-to-female connections |
Circuit Diagram and Wiring
| VL53L0X Pin | Arduino UNO | OLED SSD1306 |
|---|---|---|
| VIN | 5V | VCC |
| GND | GND | GND |
| SDA | A4 | SDA |
| SCL | A5 | SCL |
Both the VL53L0X sensor and the OLED display share the same I2C lines (SDA and SCL), making the wiring neat and straightforward.
Library Installation
Before uploading the Arduino sketch, install these libraries through the Library Manager:
- Adafruit SSD1306 – for controlling the OLED display
- Adafruit GFX Library – provides graphics functions
- VL53L0X by Pololu – handles communication with the ToF sensor
In the Arduino IDE, navigate to:
Sketch → Include Library → Manage Libraries → Search for each name → Install.
Arduino Code
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <VL53L0X.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
VL53L0X sensor;
void setup() {
Serial.begin(9600);
Wire.begin();
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("Display failed"));
while(1);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(10, 20);
display.print(F("Distance Meter"));
display.display();
delay(1500);
sensor.setTimeout(500);
if (!sensor.init()) {
display.clearDisplay();
display.setCursor(10, 20);
display.print(F("Sensor Error!"));
display.display();
while(1);
}
sensor.startContinuous();
display.clearDisplay();
display.setTextSize(2);
display.setCursor(30, 25);
display.print(F("READY"));
display.display();
delay(1000);
}
void loop() {
int dist = sensor.readRangeContinuousMillimeters();
display.clearDisplay();
display.setTextSize(1);
display.setCursor(30, 5);
display.print(F("DISTANCE"));
display.drawLine(0, 15, 128, 15, SSD1306_WHITE);
if (!sensor.timeoutOccurred()) {
display.setTextSize(2);
display.setCursor(15, 25);
if (dist < 1000) {
display.print(dist);
display.setTextSize(1);
display.setCursor(85, 31);
display.print(F("mm"));
} else if (dist < 8000) {
float cm = dist / 10.0;
display.print(cm, 1);
display.setTextSize(1);
display.setCursor(85, 31);
display.print(F("cm"));
} else {
display.setTextSize(1);
display.setCursor(20, 30);
display.print(F("OUT OF RANGE"));
}
display.drawRect(4, 50, 120, 10, SSD1306_WHITE);
int bar = map(constrain(dist, 30, 2000), 30, 2000, 0, 116);
if (bar > 0) {
display.fillRect(6, 52, bar, 6, SSD1306_WHITE);
}
Serial.print(F("Distance: "));
Serial.print(dist);
Serial.println(F(" mm"));
} else {
display.setTextSize(1);
display.setCursor(35, 30);
display.print(F("TIMEOUT"));
}
display.display();
delay(100);
}
How It Works
The VL53L0X sensor measures distance using the Time-of-Flight principle. It emits an invisible laser pulse and calculates the distance based on the time it takes for the light to reflect off an object and return to the sensor. This method provides high accuracy, stability, and immunity to ambient light interference.
The measured distance is then sent to the Arduino, which processes and displays it on the OLED. The OLED shows the numerical value in millimeters or centimeters and a visual progress bar that changes length based on distance. The Serial Monitor also logs each reading in real time for debugging or data analysis.
Serial Monitor Output
When you open the Serial Monitor, you’ll see real-time readings similar to:
Distance: 145 mm
Distance: 156 mm
Distance: 162 mm
Applications
- Contactless object detection
- DIY laser tape measure
- Robotics obstacle sensing
- Smart home automation
- Gesture-controlled interfaces
- Precision distance-based triggers
Summary
| Feature | Description |
|---|---|
| Sensor Type | VL53L0X Time-of-Flight Laser |
| Range | 30 mm – 2000 mm |
| Interface | I2C |
| Display | 0.96″ OLED (SSD1306) |
| Power Supply | 5V or 3.3V |
| Microcontroller | Arduino UNO or compatible |
Final Thoughts
This project shows how simple it is to integrate a laser-based Time-of-Flight sensor with an Arduino for precise distance measurement. With just a few components and minimal wiring, you can build a functional, accurate, and visually interactive distance meter. It’s an excellent addition to any beginner’s Arduino toolkit and a great stepping stone into the world of sensor-based electronics and robotics.