搜索代码

Lesson 76-1: Using a Single VL6180 Laser Distance Sensor with Arduino

Lesson 76-1: Using a Single VL6180 Laser Distance Sensor with Arduino

In this lesson, we learn how to use the VL6180 62cm laser ToF (Time of Flight) distance sensor with Arduino. The module is explained, the wiring diagram is shown, and wiring is explained. The code is fully explained and demonstrated. This code is for a single sensor.

图像

Wiring VL6180 Obstacle Avoidance with Arduino
Wiring VL6180 Obstacle Avoidance with Arduino
449-Lesson 76: Using VL6180 62cm laser distance sensors with Arduino
语言: C++
/*
* Lesson 76-1: Using one VL6180 laser distance sensor with Arduino 
 * Adafruit code modified for this tutorial
 * by Ahmad Shamshiri at 22:22 on 
 * March 10-11, 2021 in Ajax, ON, Canada
 Please watch video instruction of this code: https://youtu.be/_H9D0czQpSI
 
View code for using two or more VL6180X sensors: https://robojax.com/course1/lecture76

  This video is part of the Arduino Step by Step Course, which starts here: https://youtu.be/-6qSrDUA5a8

 

If you found this tutorial helpful, please support me so I can continue creating 
content like this. You can support me on Patreon: http://robojax.com/L/?id=63

or make a donation using PayPal: http://robojax.com/L/?id=64
  
 * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact. * 
 * This code has been downloaded from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>. 
 */
#include <Wire.h>
#include "Adafruit_VL6180X.h"

Adafruit_VL6180X vl = Adafruit_VL6180X();

void setup() {
  Serial.begin(115200);

  // wait for serial port to open on native usb devices
  while (!Serial) {
    delay(1);
  }
  
  Serial.println("Adafruit VL6180x test!");
  if (! vl.begin()) {
    Serial.println("Failed to find sensor");
    while (1);
  }
  Serial.println("Sensor found!");
}

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");
  }
//  if(range <=76)
//  {
//    //do something
//  }

  // Some error occurred, print it out!
  
  if  ((status >= VL6180X_ERROR_SYSERR_1) && (status <= VL6180X_ERROR_SYSERR_5)) {
    Serial.println("System error");
  }
  else if (status == VL6180X_ERROR_ECEFAIL) {
    Serial.println("ECE failure");
  }
  else if (status == VL6180X_ERROR_NOCONVERGE) {
    Serial.println("No convergence");
  }
  else if (status == VL6180X_ERROR_RANGEIGNORE) {
    Serial.println("Ignoring range");
  }
  else if (status == VL6180X_ERROR_SNR) {
    Serial.println("Signal/Noise error");
  }
  else if (status == VL6180X_ERROR_RAWUFLOW) {
    Serial.println("Raw reading underflow");
  }
  else if (status == VL6180X_ERROR_RAWOFLOW) {
    Serial.println("Raw reading overflow");
  }
  else if (status == VL6180X_ERROR_RANGEUFLOW) {
    Serial.println("Range reading underflow");
  }
  else if (status == VL6180X_ERROR_RANGEOFLOW) {
    Serial.println("Range reading overflow");
  }
  delay(50);
}

资源与参考

尚无可用资源。

文件📁

没有可用的文件。