Introduction

This is a low-cost single-point TOF (Time of Flight) IR distance sensor for short-to-medium range distance measurement within 0.2m~12m. It adopts 850nm LED light source and unique designs of optical system, structure, and circuit. The integrated filtering algorithm could greatly reduce the measurement noise. The ranging module supports both I2C and UART communication, easy to be integrated into end products. Besides, it offers single passive measurement and continuous active measurement for meeting various requirements in actual use.

Specification

Note: besides all kinds of mainboards, the module can also be directly used on the Host. The related software and tutorials are attached at the end of this page.

Board Overview

Board Overview

Num Label Description
1 SCL I2C Communication Clock Line
2 SDA I2C Communication Data Line
3 GND_LED Light Source Power Supply -
4 VCC_LED Light Source Power Supply +
5 TX UART Data transmitting line
6 RX UART Data receiving line
7 GND Module Power Supply -
8 VCC Module Power Supply +

Tutorial

Requirements

I2C Connection Diagram

I2C connection

Sample Code

/**
 * @file measureDistance.ino
 * @brief This example demonstrated the basic distance measuring function of LIDAR07, the range is 0.2m-12m (Operating voltage: 5 V)
 * @n Connection rules: PIN1-PIN8 are in the front of the sensor from right to left. 
 * @n          PIN1----------------------SCL--------------------Maincontroller SCL(IIC mode)
 * @n          PIN2----------------------SDA--------------------Maincontroller SDA(IIC mode)
 * @n          PIN3----------------------Light source power supply ground--------------Maincontroller GND
 * @n          PIN4----------------------Light source power supply(5V)--------Maincontroller VCC
 * @n          PIN5----------------------TX---------------------Maincontroller RX pin, which is set to be used for serial communication with the sensor (UART mode)
 * @n          PIN6----------------------RX---------------------Maincontroller TX pin, which is set to be used for serial communication with the sensor (UART mode)
 * @n          PIN7----------------------Module main power supply ground------------Maincontroller GND
 * @n          PIN8----------------------Module main power supply(5V)------Maincontroller VCC
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @licence     The MIT License (MIT)
 * @author [yangfeng]<feng.yang@dfrobot.com>
 * @version  V1.0
 * @date  2021-04-16
 * @get from https://www.dfrobot.com
 * @url  https://github.com/DFRobot/DFRobot_LIDAR07
 */
#include"DFRobot_LIDAR07.h"

//If using IIC mode, please enable macro USE_IIC
//#define USE_IIC
#ifdef USE_IIC  
DFROBOT_LIDAR07_IIC  LIDAR07;
#endif

//If using UART mode, please enable macro USE_UART. The USE_UART is enabled by default. The two modes USE_IIC and USE_UART can’t be used at the same time.
#define USE_UART
#ifdef USE_UART

#if defined(ESP8266)||defined(ARDUINO_AVR_UNO)
#include <SoftwareSerial.h>
SoftwareSerial  mySerial(4,12);//GPIO4 is corresponding to RX on main control board, GPIO12 is corresponding to TX on main control board
/**!
 * The TX of esp32 Serial1 is GPIO10, and the RX is GPIO9 
 * The TX of mega2560 Serial1 is GPIO18, and the RX is GPIO19
 * The TX of M0 Serial1 is GPIO1, and the RX is GPIO0
 * The TX of leonardo Serial1 is GPIO1, and the RX is GPIO0
 */
#endif
DFROBOT_LIDAR07_UART  LIDAR07;  
#endif

void setup() {
  uint32_t version;
  Serial.begin(115200);
#ifdef USE_IIC
  while(!LIDAR07.begin()){
    Serial.println("The sensor returned data validation error");
    delay(1000);
  }
#endif

#ifdef USE_UART
#if defined(ESP8266)||defined(ARDUINO_AVR_UNO)
  mySerial.begin(115200);
  while(!LIDAR07.begin(mySerial)){
    Serial.println("The sensor returned data validation error");
    delay(1000);
  }
#else
  Serial1.begin(115200);
  while(!LIDAR07.begin(Serial1)){
    Serial.println("The sensor returned data validation error");
    delay(1000);
  }
#endif
#endif

  version = LIDAR07.getVersion();
  Serial.print("VERSION: ");
  Serial.print((version>>24)&0xFF,HEX);
  Serial.print(".");Serial.print((version>>16)&0xFF,HEX);
  Serial.print(".");Serial.print((version>>8)&0xFF,HEX);
  Serial.print(".");Serial.println((version)&0xFF,HEX);

  LIDAR07.startFilter();  //After enabling the filter, it can be stopped by calling LIDAR07.stopFilter()
}

void loop() {
  int errinfo;
  while(!LIDAR07.startMeasure()){
    Serial.println("Incorrect data was returned");
    delay(1000);
  }
  Serial.print("Distance:");Serial.print(LIDAR07.getDistanceMM());Serial.println(" mm");
  Serial.print("Amplitude:");Serial.println(LIDAR07.getSignalAmplitude());
  delay(1000);
}

Expected Results

Expected Result

Compatibility

MCU Work Well Work Wrong Untested Remarks
Arduino UNO
FireBeetle ESP32
FireBeetle ESP8266
FireBeetle M0
Leonardo
Micro:bit Voltage unsupported, large data error
Arduino Mega2560
MCU Work Well Work Wrong Untested Remarks
Arduino UNO Unstable when software serial port baud rate is 115200
FireBeetle ESP32
FireBeetle ESP8266
FireBeetle M0
Leonardo
Micro:bit Not support
Arduino Mega2560

FAQ

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

More Documents

DFshopping_car1.png Get TOF IR Distance Sensor (0.2~12m) from DFRobot Store or DFRobot Distributor.

Turn to the Top