Laser Range Sensor VL6180 - johnosbb/Automation GitHub Wiki

Laser Range Sensor VL6180

image

  • The sensor has I2C Comms Only.

With this very small TOF10120 Time-of-Flight sensor you can easily measure a distance using the reflection of light.

Specifications:

  • Voltage (power supply and signal): 3.3-5V DC
  • Detection distance: 100-1800mm
  • Wavelength: 940nm
  • 2 Mounting holes of 2mm
  • Dimensions: See images

Pinout:

image

  • 1 VIN: 3.3-5V DC
  • 2 GND: Ground
  • 3 SDA: I2C data signal
  • 4 SCL: I2C clock signal
  • 3 INT: TTL ouput
  • 4 SHUT: TTL input

Details

I2C address: 0x52

Sample Code

/* This example shows how to use continuous mode to take
range measurements with the VL6180X.
The range readings are in units of mm. */

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include "Adafruit_VL6180X.h"

Adafruit_VL6180X vl = Adafruit_VL6180X();





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

  delay(1000);
  
  Serial.println("Adafruit VL6180x test!");
  if (! vl.begin()) {
    Serial.println("Failed to find sensor");
    while (1);
  }
  Serial.println("Sensor found!");


}

void loop()
{
  float lux = vl.readLux(VL6180X_ALS_GAIN_5);

  Serial.print("Lux: "); Serial.println(lux);
  
  uint8_t range = vl.readRange();
  uint8_t status = vl.readRangeStatus();

  if (status == VL6180X_ERROR_NONE) {
    Serial.print("Range: "); Serial.println(range);

    Serial.println();
  } else {
    Serial.println("Error obtaining Range: "); 
    return;
  }

  // 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(1000);
}

References

⚠️ **GitHub.com Fallback** ⚠️