Other Arduino Codes and Videos by Robojax

Using one VL6180X 20cm Time-of-Flight proximity sensor with Arduino

Using one VL6180X 20cm Time-of-Flight proximity sensor with Arduino

This is the Arduino code for VL6180X proximity sensor with 20cm range. Sensor explaiend in this video, wiring shown for 1 sensor and for 2 or more sensor. Adafruit Library is used. Code updated to be used easity with for real application for 1 sensor or 2 or more sensors.

Using 2 or more VL6080X Distance Proximity Sensor

Purchase VL6080Xsensor

-Amazon Canada
-Amazon USA
-Amazon Europe (All)

Chapters of this video

VL6080X Proximity Sensor

VL6080X Sensor
Click on image to enlarge

VL6080X Proximity Sensor

VL6080X Sensor
Click on image to enlarge

VL6080X Proximity Sensor

VL6080X Sensor
Click on image to enlarge

VL6080X Proximity Sensor

VL6080X Sensor
Click on image to enlarge

 /*
 *  Arduino code 
Using single VL6180X 20cm Time-of-Flight proximity sensor with Arduino

View code for using single VL6180X sensors: https://robojax.com/learn/arduino/?vid=robojax_VL6180X_laser2

 * Original code and library by https://github.com/adafruit/Adafruit_VL6180X
 * 
 * Written/updated by Ahmad Shamshiri for Robojax Robojax.com
 * on Mar 10, 2021  in Ajax, Ontario, Canada
 Watch the video instruction for this sketch: https://youtu.be/_H9D0czQpSI
 


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 donation using PayPal http://robojax.com/L/?id=64

* 
 * Code is available at http://robojax.com/learn/arduino

 * 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 download 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);
}
   

If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal