Back to Step by Step Course by Robojax

Lesson 76: Using VL6180 62cm Laser Distance sensors with Arduino

Please select other codes for this lecture from the links below.

  • VL6180 Datasheet (pdf)
  • Part 8: Obstacle Avoidance with Arduino

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

    wiring diagram for VL6180
    • 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
    * Lesson 76-1: Using One single VL6180 Laser  Distance Sensor with Arduino 
     * Adafruit code modified for this tutorial
     * by Ahmad Shamshiri at 22:22 on 
     * Mar 10-11, 2021 in Ajax, ON, Canada
     Please watch video instruciton of this code :
    View code for using two or more VL6180X sensors:
      This video is part of Arduino Step by Step Course which starts here:
    If you found this tutorial helpful, please support me so I can continue creating 
    content like this. You can support me on Patreon
    or make donation using PayPal
     * 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
        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
        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 <>. 
    #include <Wire.h>
    #include "Adafruit_VL6180X.h"
    Adafruit_VL6180X vl = Adafruit_VL6180X();
    void setup() {
      // wait for serial port to open on native usb devices
      while (!Serial) {
      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);
    //  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");

    The least I expect from you is to give the video a thumbs up and subscribe to my channel. I appreciate it. I have spent hundreds of hours making these lectures and writing code. You don't lose anything by subscribing to my channel. Your subscription is a stamp of approval for my videos, helping more people find them and, in turn, helping me. Thank you!

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

    **** AFFILIATE PROGRAM **** We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to and affiliated sites.

    Right Side