Arduino Project
Tof Distance
Course Introduction
This Arduino project uses a VL53L0X Time of Flight distance sensor and an OLED display to measure and visualize distance. The sensor continuously measures the distance in millimeters, and the measured value is shown on the OLED screen and printed to the serial monitor. This setup demonstrates how to use a micro LiDAR sensor for precise short-range distance measurement.
Note
If this is your first time working with an Arduino project, we recommend downloading and reviewing the basic materials first.
1.1 Install Arduino IDE(Important)
1.2 Introduction of Arduino IDE
Wiring

Common Connections:
Digital Servo Motor
Connect to breadboard’s positive power bus.
Connect to breadboard’s negative power bus.
Connect to 7 on the Arduino.
Laser Ranging Module
SDA: Connect to A4 on the Arduino.
SCL: Connect to A5 on the Arduino.
GND: Connect to breadboard’s negative power bus.
VCC: Connect to breadboard’s red power bus.
Writing the Code
Note
Build the circuit.
Install the library, use the Arduino Library Manager and search for Adafruit_VL53L0X install it.
Upload the code to the Arduino board using Arduino IDE.
/*
This code initializes and runs an Arduino Uno setup that interfaces with a VL53L0X Time of Flight
Micro-LIDAR Distance Sensor and an OLED display. It measures the distance in millimeters and displays
the distance on the OLED screen. The measurement values are also output on the serial monitor.
Note: The VL53L0X can handle about 50 - 1200 mm of range distance.
Board: Arduino Uno R4 (or R3)
Component: Time of Flight Micro-LIDAR Distance Sensor (VL53L0X) and OLED Display Module
Library: https://github.com/adafruit/Adafruit_VL53L0X (Adafruit_VL53L0X by Adafruit)
https://github.com/adafruit/Adafruit_SSD1306 (Adafruit SSD1306 by Adafruit)
https://github.com/adafruit/Adafruit-GFX-Library (Adafruit GFX Library by Adafruit)
*/
#include
#include "Adafruit_VL53L0X.h"
#include
#include
#include
// Initialize the OLED display module with a resolution of 128x64
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire, -1);
// Initialize the VL53L0X distance sensor
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
void setup() {
Serial.begin(9600);
// Start the OLED display with I2C address 0x3C
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
delay(1000);
// Begin I2C communication
Wire.begin();
// Start the VL53L0X distance sensor, halt if initialization fails
if (!lox.begin()) {
Serial.println(F("Failed to boot VL53L0X"));
while (1)
;
}
// Set OLED display text size and color
display.setTextSize(3);
display.setTextColor(WHITE);
}
void loop() {
VL53L0X_RangingMeasurementData_t measure;
lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout
// If there are no phase failures, display the measured distance
if (measure.RangeStatus != 4) {
display.clearDisplay();
display.setCursor(12, 22);
display.print(measure.RangeMilliMeter);
display.print("mm");
display.display();
Serial.println();
delay(50);
} else {
display.display();
display.clearDisplay();
return;
}
}
