搜索代码

Lesson 77: Using VL53L0X 200cm Laser Distance Sensors with Arduino

Lesson 77: Using VL53L0X 200cm Laser Distance Sensors with Arduino

In this lesson, we learn how to use one VL53L0X 200cm laser ToF (Time of Flight) distance sensor using Arduino. The module and wiring are explained. The code is fully explained and demonstrated. This code is for two sensors.

图像

更新 VL53L0X 上 I2C 地址的 Arduino 代码
更新 VL53L0X 上 I2C 地址的 Arduino 代码
448-Lesson 77: Using VL53L0X 200cm laser distance sensors with Arduino
语言: C++
/* 
 *  S08-08 VL53L0X
 * Lesson 77-1: Using One single VL53L0X Laser Distance Sensor with Arduino  
 *  This example shows how to use continuous mode to take
 range measurements with the VL53L0X. It is based on
 vl53l0x_ContinuousRanging_Example.c from the VL53L0X API.

The range readings are in units of mm. 
Please watch video instruction of this code: https://youtu.be/CUg8VheNyoU
 
View code for using two or more VL6180X sensors: https://robojax.com/course1/lecture76

  This video is part of 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. 

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/>. 
	
Original source: https://github.com/adafruit/Adafruit_VL53L0X
Modified by Ahmad Shamshiri for RoboJax.com
Date modified: May 31, 2018 at 19:25 at Ajax, Ontario, Canada


Pin connection

VL53L0X Pin  Arduino Pin
VCC         5V
GND         GND
SDA         A4 or SDA if available
SCL         A5 or SCL if available
GPIO1       leave it unconnected
XSHUT       D12 (digital 12 or pin 12)
*/


#include <Wire.h>
#include <VL53L0X.h>

VL53L0X sensor;


void setup()
{

  Serial.begin(9600);
  Wire.begin();
  sensor.init();
  sensor.setTimeout(500);

  // Start continuous back-to-back mode (take readings as
  // fast as possible).  To use continuous timed mode
  // instead, provide a desired inter-measurement period in
  // ms (e.g. sensor.startContinuous(100)).
  sensor.startContinuous();
}

void loop()
{
  int distance =sensor.readRangeContinuousMillimeters();
  //int distance =sensor.startContinuous(100);
  
 //distance = distance;
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.print("mm");
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.println();
  delay(100);
}

资源与参考

文件📁

没有可用的文件。