激光测距模块

简介

这是一款高性价比的红外激光测距传感器,拥有高精度、远距离测距、可视红外激光、小视场角等特性。室内测量距离0.05-80m,室外测量距离0.05-50m,串口输出,兼容Arduino等多种控制板。可用于无人机降落、电子尺以及大型粮仓料位机等应用场景中。

注意: 对不同的测量目标和测量环境,由于环境光强度过大、环境温度过高或者过低、目标反光过弱或过强,或者目标表面粗糙不平,都可能引起测程缩短或者对测量结果产生较大误差。

技术规格

引脚示意图

引脚示意图 引脚示意图

使用教程

准备

接线图

接线图

示例代码

激光测距传感器通讯协议.pdf

/*!
 * @File  DFRobot_IraserSensor.ino
 * @brief  In this example, the infrared laser ranging sensor is used to measure the distance, and the sensor data is processed to obtain the measured distance
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @licence  The MIT License (MIT)
 * @author  [liunian](nian.liu@dfrobot.com)
 * @version  V1.0
 * @date  2020-08-13
 */
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3);//定义软串口,3号端口为TX,2号端口为RX
char buff[4]={0x80,0x06,0x03,0x77};
unsigned char data[11]={0};
void setup()
{
 Serial.begin(115200);
 mySerial.begin(9600);
}

void loop()
{
  mySerial.print(buff);
  while(1)
  {
    if(mySerial.available()>0)//判断串口是否有数据可读
    {
      delay(50);
      for(int i=0;i<11;i++)
      {
        data[i]=mySerial.read();
      }
      unsigned char Check=0;
      for(int i=0;i<10;i++)
      {
        Check=Check+data[i];
      }
      Check=~Check+1;
      if(data[10]==Check)
      {
        if(data[3]=='E'&&data[4]=='R'&&data[5]=='R')
        {
          Serial.println("Out of range");
        }
        else
        {
          float distance=0;
          distance=(data[3]-0x30)*100+(data[4]-0x30)*10+(data[5]-0x30)*1+(data[7]-0x30)*0.1+(data[8]-0x30)*0.01+(data[9]-0x30)*0.001;
          Serial.print("Distance = ");
          Serial.print(distance,3);
          Serial.println(" M");
        }
      }
      else
      {
        Serial.println("Invalid Data!");
      }
    }
    delay(20);
  }
}

常见问题

还没有客户对此产品有任何问题,欢迎通过 qq 或者论坛联系我们! 更多问题及有趣的应用,可以访问论坛进行查阅或发帖

更多

DFRobot 商城购买链接