搜索代码

Using one VL6180X 20cm time-of-flight proximity sensor with Arduino

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.

VL6080X Sensor top view

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

ManufacturerSTMicroelectronics
Part numberVL6180X
Logic/IO voltage2.6 - 3.5 V
Supply voltage2.6 - 3.5 V
Output current1.7 mA (typ.)
Peak current< 10 mA
PWM frequency guidanceN/A
Input logic thresholds0.3 x VCC (high), 0.2 x VCC (low)
Voltage drop / RDS(on) / saturationN/A
Thermal limits-20 to 70 °C
Package4.8 x 2.8 x 1 mm
Notes / variantsProximity 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

Wiring VL6180 Obstacle Avoidance with Arduino
Wiring VL6180 Obstacle Avoidance with Arduino
VL6180_dual_sensor_bb

To wire the VL6180X sensor to your Arduino, follow these steps:

  • Connect the VCC pin of the sensor to the 5V pin on the Arduino.
  • Connect the GND pin of the sensor to the GND pin on the Arduino.
  • Connect the SCL pin of the sensor to the A5 pin on the Arduino (I2C clock).
  • Connect the SDA pin of the sensor to the A4 pin 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

图像

VL6080X sensor
VL6080X Sensor
VL6080X Sensor back of PCB
VL6080X Sensor back of PCB
VL6080X Sensor top view
VL6080X Sensor top view
VL6080X Sensor verticle
VL6080X Sensor verticle
Wiring VL6180 Obstacle Avoidance with Arduino
Wiring VL6180 Obstacle Avoidance with Arduino
VL6180_wiring_new
VL6180_wiring_new
VL6180_dual_sensor_bb
VL6180_dual_sensor_bb
361-Arduino code for VL6180X 20cm Time-of-Flight proximity sensor
语言: C++
This code has not been parsed yet. Please return to the admin panel to parse it.
450-Lesson 76: Using 2 ore more VL6180X 62cm Laser Distance Sensors with Arduino
语言: C++
This code has not been parsed yet. Please return to the admin panel to parse it.

|||您可能需要的东西

文件📁

没有可用的文件。