Distance measurement with the VL6180X

FunduinoLast updated on

Präzise Nahbereichsmessung mit dem Time-of-Flight-Sensor

Der VL6180X misst Entfernungen mit einem Laserstrahl. Er sendet einen kurzen Lichtimpuls aus und misst, wie lange das Licht bis zum Objekt und zurück braucht – daher der Name „Time of Flight“.

Gegenüber Ultraschall- und Infrarotsensoren hat er zwei Vorteile: einen sehr schmalen Abtastbereich und eine Messung, die nicht von der Helligkeit des reflektierten Lichts abhängt. Dafür ist seine Reichweite auf den Nahbereich beschränkt.

Angeschlossen wird er über den I²C-Bus – vier Leitungen genügen. Die Auswertung übernimmt eine fertige Bibliothek von Adafruit.

The VL6180X laser distance sensor on its circuit board
The VL6180X

You need this

VL6180X Abstandssensor - Time of Flight Laser, bis 10 cm, I2C VL6180X Abstandssensor - Time of Flight Laser, bis 10 cm, I2C 5,02 € *Item no. F23108551About the product — VL6180X Abstandssensor - Time of Flight Laser, bis 10 cm, I2C
Funduino UNO R3 Mikrocontroller - ATmega328P, 16 MHz, für Arduino Funduino UNO R3 Mikrocontroller - ATmega328P, 16 MHz, für Arduino 13,90 € *Item no. F23107480About the product — Funduino UNO R3 Mikrocontroller - ATmega328P, 16 MHz, für Arduino
Breadboard 830 Kontakte - Steckbrett für Arduino, lötfrei Breadboard 830 Kontakte - Steckbrett für Arduino, lötfrei 2,90 € *Item no. FUN-1010553About the product — Breadboard 830 Kontakte - Steckbrett für Arduino, lötfrei
Breadboardkabel männlich-männlich - 40 Stück, 20 cm Breadboardkabel männlich-männlich - 40 Stück, 20 cm 1,74 € *Item no. FUN-1010558About the product — Breadboardkabel männlich-männlich - 40 Stück, 20 cm

All 4 parts together 23,56 € *Ready to ship immediately · Delivery time: 1-3 business days

* All prices include statutory VAT, plus shipping costs.

The VL6180X sensor

The VL6180X - often simply called the VL6180 - is a distance sensor with a tiny laser light source and a corresponding receiver. It measures how long the laser light takes to reach the object and return, then calculates the distance from that. That's why it's also called a “time-of-flight” sensor.

Because it uses a very narrow beam of light, it's particularly effective at short distances.

The VL6180X laser distance sensor on its circuit board
The VL6180X

Difference from other distance sensors

  • Compared with ultrasonic sensors: The detection range is significantly narrower.
  • Compared with infrared distance sensors: The VL6180X is more precise because it measures time of flight rather than the amount of reflected light.

According to the manual, the range is approximately 15 to 200 mm. Strong ambient light can reduce it. The sensor works with any microcontroller between 3 and 5 volts.

Connect the sensor

Communication takes place over the I²C bus, so only four wires are needed:

  • VIN to 5V or 3.3V on the microcontroller
  • GND to GND
  • SCL to the SCL pin
  • SDA to the SDA pin
Wiring the VL6180X to the microcontroller via I2C
Connect VIN, GND, SCL, and SDA

Install the library and output measured values

Install the library through the Library Manager: Adafruit_VL6180X. It includes example sketches that demonstrate the full range of functions. For this guide, the sketch has been reduced to distance measurement only.

The sketch outputs the readings in the Serial Monitor. Set it to 115200 baud – this is not the default value.

Adafruit_VL6180X library in the Library Manager
The Adafruit_VL6180X library
Distance values in millimeters in the Serial Monitor
Measured values at 115200 baud
1 / 2
Display distance in the Serial Monitor
#include <Wire.h>
#include "Adafruit_VL6180X.h"
Adafruit_VL6180X vl = Adafruit_VL6180X();
void setup()
{
  Serial.begin(115200);
  while (!Serial) // Wait until the serial connection is established
  {
  delay(1); // This pause is repeated as long as the serial connection is not established.
  }
  vl.begin();
}
void loop()
{
  uint8_t Entfernung = vl.readRange(); // The measured distance value is stored in "Entfernung".
  uint8_t status = vl.readRangeStatus(); // The sensor status is read.
  if (status == VL6180X_ERROR_NONE) { // If the sensor status contains no errors, the contents of the IF loop follow
    Serial.print("Distance in mm: "); Serial.println(Entfernung);  //Output the distance in the serial monitor
  }
  delay(100); // The delay keeps the values in the serial monitor easy to read. In applications for recording measurement data, such pauses should be avoided.
}
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.