Infrared Laser Rangefinder Arduino Wiki - DFRobot

Introduction

This is a cost-effective IR laser distance sensor that features high accuracy, long-distance detection, visible IR laser, and small FOV. It offers the measuring ranges 0.05-80m for indoor use and 0.05-50m outdoor. With serial port output, it is compatible with all kinds of controller boards like Arduino. The sensor can be used in applications like UAV automatic landing, electronic scale, barn material level monitoring, etc.

warning_yellow.png NOTE: for different objects and operating environments, the measurement range of the sensor may be shortened or its performance may be affected due to factors like excessive intensity of ambient light, too high or low operating temperature, rough surface of target, and too weak or strong light reflection of target object.

Specification

Board Overview

Board Overview Pin diagram

Tutorial

Requirements

Connection Diagram

Connection Diagram

Sample Code

SEN0366 Communication Protocol.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);//Define software serial, 3 is TX, 2 is 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)//Determine whether there is data to read on the serial 
    {
      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);
  }
}

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents

DFshopping_car1.png Get Infrared Laser Distance Sensor(50m/80m) from DFRobot Store or DFRobot Distributor.

Turn to the Top