Using one VL6180X 20cm time-of-flight proximity sensor with Arduino
Using one VL6180X 20cm time-of-flight proximity sensor with Arduino
In this tutorial, we will learn how to use the VL6180X time-of-flight proximity sensor with an Arduino. The VL6180X is designed to detect objects within a range of up to 20 centimeters, making it ideal for various robotics applications. By the end of this guide, you will be able to set up the sensor, read distance measurements, and implement simple logic based on those measurements.

For clarity on the setup and code, be sure to watch the associated video (in video at 00:00).
Hardware Explained
The VL6180X is a compact proximity sensor that utilizes time-of-flight technology to measure distances accurately. It operates using I2C communication, allowing for easy integration with Arduino and other microcontrollers. The sensor has a maximum range of 62 cm, but for this project, we will focus on the 20 cm range, which is suitable for most close-range applications.
The sensor operates on a voltage range of 2.6 to 3.5 volts and has low power consumption, making it ideal for battery-operated devices. It includes two GPIO pins that can be used for interrupt handling and power management, allowing for flexibility in more complex applications.
Datasheet Details
| Manufacturer | STMicroelectronics |
|---|---|
| Part number | VL6180X |
| Logic/IO voltage | 2.6 - 3.5 V |
| Supply voltage | 2.6 - 3.5 V |
| Output current | 1.7 mA (typ.) |
| Peak current | < 10 mA |
| PWM frequency guidance | N/A |
| Input logic thresholds | 0.3 x VCC (high), 0.2 x VCC (low) |
| Voltage drop / RDS(on) / saturation | N/A |
| Thermal limits | -20 to 70 °C |
| Package | 4.8 x 2.8 x 1 mm |
| Notes / variants | Proximity and ambient light sensing |
- Ensure proper voltage supply between 2.6 to 3.5 V.
- GPIO pins can be configured for various purposes, including interrupts.
- Use I2C pull-up resistors if necessary.
- Keep the sensor clean and unobstructed for accurate readings.
- Check for proper wiring to avoid communication errors.
Wiring Instructions


To wire the VL6180X sensor to your Arduino, follow these steps:
- Connect the
VCCpin of the sensor to the5Vpin on the Arduino. - Connect the
GNDpin of the sensor to theGNDpin on the Arduino. - Connect the
SCLpin of the sensor to theA5pin on the Arduino (I2C clock). - Connect the
SDApin of the sensor to theA4pin on the Arduino (I2C data).
Make sure to double-check your connections to avoid any communication issues. If you plan to use multiple sensors, ensure that each sensor has a unique I2C address and adjust the wiring accordingly.
Code Examples & Walkthrough
Below is a brief excerpt from the setup code where we initialize the sensor and establish I2C communication:
void setup() {
Serial.begin(115200);
while (!Serial) { delay(1); }
if (! vl.begin()) {
Serial.println("Failed to find sensor");
while (1);
}
Serial.println("Sensor found!");
}
In this section, we initialize the serial communication and check if the sensor is found. If the sensor is not detected, the program will halt, indicating an issue with the connection.
Next, let's look at the main loop where we read the distance and handle errors:
void loop() {
uint8_t range = vl.readRange();
uint8_t status = vl.readRangeStatus();
if (status == VL6180X_ERROR_NONE) {
Serial.print("Range: "); Serial.print(range);
Serial.println("mm");
}
// Error handling omitted for brevity
delay(50);
}
Here, we read the distance measurement into the variable range and check the status. If there are no errors, the distance is printed to the serial monitor. This is crucial for understanding how far the object is from the sensor.
The full code will load below this article for your reference.
Demonstration / What to Expect
When you run the code with the sensor wired correctly, you should see distance readings in millimeters printed on the serial monitor. If an object is placed within 20 cm of the sensor, the distance will be displayed accurately. If the object is too far or there are any issues, appropriate error messages will be shown. This process is demonstrated in the video (in video at 10:00).
Video Timestamps
- 00:00 Start
- 00:56 Introduction
- 04:30 VL6080V Datasheet viewed
- 06:58 Wiring shown
- 07:32 Wiring for two or more sensors
- 09:22 Installing library
- 10:30 Arduino code explained (1 sensor)
- 12:57 Code for 2 or more sensors
- 19:35 Demonstration 1 sensor
- 22:05 Demonstration with 2 sensors
This code has not been parsed yet. Please return to the admin panel to parse it.
This code has not been parsed yet. Please return to the admin panel to parse it.
|||您可能需要的东西
-
易趣从eBay购买VL618X传感器ebay.us
-
全球速卖通从AliExpress购买VL618X传感器s.click.aliexpress.com
-
Banggood从Banggood购买VL618X传感器banggood.com
资源与参考
-
外部
-
外部
-
外部Purchase VL6180X from Amazon USAamzn.to
-
外部VL6080X datasheetst.com
文件📁
没有可用的文件。