Arduino驱动VL53L0X V2激光测距(串口输出)

Arduino驱动VL53L0X V2激光测距(串口输出)

  • 一、简介
  • 二、使用前准备
  • 三、测试方法
  • 四、实验现象
  • 总结
  • 一、简介

    激光测距传感器模块功耗小,体积小,安装方便。它是根据红外LED发光,照射到被测物体后,返回光经过MCU接收,MCU计算时间差得到距离,直接输出距离值。
    VL53LOX是新一代完全集成的传感器,配有嵌入式红外、人眼安全激光,先进的滤波器和超高速光子探测阵列,测量距离更长,速度和精度更高。
    激光测距传感器的感测能力可以支持各种功能,包括各种创新用户界面的手势感应或接近检测,扫地机器人、服务性机器人的障碍物探测与防撞系统,家电感应面板、笔记本电脑的用户存在检测或电源开关监控器,以及无人机和物联网产品等。

    原理框图

    VL53LOX进行IIC通讯地址说明

    VL53LOX读写说明



    引脚说明

    名称 描述
    VIN 电源3~5V
    GND 接地
    SCL IIIC串行时钟线
    SDA IIC串行数据线
    GPIO1 中断
    XSHUT 复位

    二、使用前准备


    点击图片购买

    VL53L0X V2激光测距模块 激光测距传感器 ToF飞行时间测距


    点击图片购买

    原装正版Arduino uno r3开发板


    点击图片购买

    USB2.0打印机数据线高速方口连接转接线 A公对B公

    点击图片购买

    杜邦线

    VL53L0X V2激光测距模块 激光测距传感器 ToF飞行时间测距 1个
    原装正版Arduino uno r3开发板 1个
    USB2.0打印机数据线高速方口连接转接线 A公对B公 1条
    杜邦线 若干

    三、测试方法

    用USB2.0打印机数据线高速方口连接转接线与Arduino uno r3开发板连接在一起。Arduino uno r3开发板和VL53L0X V2激光测距模块连接,如下图所示

    接线
    5V —— VCC
    GND —— GND
    SCL —— SCL
    SDA —— SDA
    安装Arduino IDE,打开ArduinoIDE,先安装【IRremote】库,点击【项目】,再点击【新建】,输入代码,如下图所示

    最后点击上传,如下图所示

    代码如下:

    /* This example shows how to get single-shot range
     measurements from the VL53L0X. The sensor can optionally be
     configured with different ranging profiles, as described in
     the VL53L0X API user manual, to get better performance for
     a certain application. This code is based on the four
     "SingleRanging" examples in the VL53L0X API.
    
     The range readings are in units of mm. */
    
    #include <Wire.h>
    #include <VL53L0X.h>
    
    VL53L0X sensor;
    
    
    // Uncomment this line to use long range mode. This
    // increases the sensitivity of the sensor and extends its
    // potential range, but increases the likelihood of getting
    // an inaccurate reading because of reflections from objects
    // other than the intended target. It works best in dark
    // conditions.
    
    //#define LONG_RANGE
    
    
    // Uncomment ONE of these two lines to get
    // - higher speed at the cost of lower accuracy OR
    // - higher accuracy at the cost of lower speed
    
    //#define HIGH_SPEED
    //#define HIGH_ACCURACY
    
    
    void setup()
    {
      Serial.begin(9600);
      Wire.begin();
    
      sensor.init();
      sensor.setTimeout(500);
    
    #if defined LONG_RANGE
      // lower the return signal rate limit (default is 0.25 MCPS)
      sensor.setSignalRateLimit(0.1);
      // increase laser pulse periods (defaults are 14 and 10 PCLKs)
      sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
      sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
    #endif
    
    #if defined HIGH_SPEED
      // reduce timing budget to 20 ms (default is about 33 ms)
      sensor.setMeasurementTimingBudget(20000);
    #elif defined HIGH_ACCURACY
      // increase timing budget to 200 ms
      sensor.setMeasurementTimingBudget(200000);
    #endif
    }
    
    void loop()
    {
      Serial.print(sensor.readRangeSingleMillimeters());
      if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
    
      Serial.println();
    }
    

    四、实验现象


    程序下载进去之后,显示测量的距离78mm。

    总结

    注意事项
    (1)波特率要选择正确。
    (2)要先安装【VL53L0X】库。

    物联沃分享整理
    物联沃-IOTWORD物联网 » Arduino驱动VL53L0X V2激光测距(串口输出)

    发表评论