TF03 (ToF) Laser Range Sensor(100m/180m)

SEN0328 TF03 Laser Range Sensor(100m)

Introduction

As the third generation product of TF series, TF03 inherits the cost-effective and compact-integration advantages from the previous two generations. Meanwhile, TF03 upgrades more than ten key parameters and offers multiple expansion functions to meet the various demands in different application scenarios. We have two detection ranges for you to choose: 100m and 180m. With a small size of 44×42.9×31.8mm, it can be covered by just a palm of one hand. The product is applicable to the terrain following of drones, the collision avoidance of cars, intelligent transportation and industrial safety warning.

TF03 employs the pulsed time-of-flight principle. The unique design of the optical system and the signal processing circuit improved the detecting performance in a compact size. In addition to increasing the range to more than 100 meters, this sensor features 0.1m blind zone, ±10cm accuracy, up to 10KHz frequency and 100Klux ambient light immunity. TF03 also contains a compensation algorithm targeting outdoor highlight environment, so that it can still keep excellent performance in harsh environment.

TF03 sensor uses aluminum-made shell and infrared band-pass glass to improve the overall strength. With IP67 enclosure rate, the sensor can be applied in various extreme environments. It supports multiple interfaces for different applications, such as, UART, CAN, IO. Besides that, multiple parameters of TF03 can be configured by customers, including the measuring frequency, baud rate, trigger mode, over-range assignment, and so on. TF03 is also equipped with BootLoader function, enabling users to upgrade product firmware locally. Power the sensor with 5V. The average power consumption is 0.55W. It is compatible with controllers like Arduino, Raspberry Pi. With Arduino and Raspberry Pi libraries developed by DFRobot, users can conveniently integrate functions into system to develop their applications.

warning_yellow.png NOTE:

  • This product can only be maintained by qualified professionals and only the original spare parts can be used to ensure its performance and safety.
  • The product itself has no polarity and over-voltage protection. Please complete wiring and supply power correctly according to the contents of the Manual.
  • The working temperature of the product is -20℃~60℃, do not use it beyond this range so as to avoid risks.
  • The storage temperature of the product is -40°C~85°C; please do not store it beyond this temperature range, so as to avoid risks.
  • Do not open its enclosure for assembly or maintenance beyond this Manual; otherwise, it will affect the product performance.
  • When the product transmitter and receiver lens are covered by dirt, there will be a risk of failures. Please keep the lens clean.
  • The product will have a risk of failure when immersed completely in water. Do not use it underwater.
  • When detecting objects with high reflectivity, such as mirrors and smooth tiles, the product may have a risk of failures.

Specification

Board Overview

SEN0328 TF03 Laser Range Sensor Board Overview
Num Label Description
Red VCC Power Supply
White CAN_L CAN Bus
Green CAN_H CAN Bus
Blue GPIO IO Output
Brown TTL_RXD Serial Receive
Yellow TTL_TXD Serial Transmit
Black GND Ground

warning_yellow.png NOTE

  • The interface type of the product is MH1.25-7P, which cannot be directly used on Arduino Uno so we provide you with the 2.54-1P dupont wires and PH-P plastic shell socket. The wires on the sensor and the dupont wires should be connected in this way: black(sensor) to black(dupont), red to red, brown to blue, yellow to green.
  • The sensor supports two communication modes: TTL and CAN. The default mode is TTL, and can be changed via command by users. Please note that the two modes cannot be used as output at the same time.

Module Communication Protocol and Data Format

The standard version of TF03 supports two communication modes: TTL and CAN. Users can use command to change the default TTF mode. The two modes cannot be used as output at the same time.

Serial Port Mode

TF03 serial port mode adopts UART-LVTTL interface. The output level is LVTTL level (0~3.3V), and the details are shown below:

Item Content
Communication Protocols UART
Band Rate 115200
Data Byte 8
Stop Byte 1
Check Byte None

Standard Serial Data Format(UART)

The outputs of TF03 are shown as below: all the data are hexadecimal number; there are 9 bytes in data of each frame. The data includes real measured distance(DIST); the other bytes are reserved; the frame tail is checkbyte.

Data Byte Define Description
Byte0 Frame Head 0x59
Byte1 Frame Head 0x59
Byte2 DIST_L DIST low eight bits
Byte3 DIST_H DIST high eight bits
Byte4 Reserved /
Byte5 Reserved /
Byte6 Reserved /
Byte7 Reserved /
Byte8 Check Low eights bytes of Checksum, Checksum=Byte0 + Byte1 + ...+ Byte7

Serial Port Pixhawk Data Format

Pixhawl data format is output in the form of string, unit m. For example, if the measured distance is 1.21m, then output the string 1.21. There is a linefeed behind each distance value. In serial communication, the output mode can be changed to pixhawk output mode via command.

High/Low Level Output

Set a threshold (adjustable), when the measured distance is more /less than the threshold, output high/low.

For example:

CAN Bus Mode

The CAN communication protocol of TF03 can be customized. CAN band rate, ID, and Frame format are adjustable. As seen below:

Item Content
Communication Protocols CAN
Band Rate 1M
Receive ID 0x3003
Transmit ID 0x3
Check Byte Transmit Frame is regarded as standard frame by default, and receive frame supports standard frame and expension frame

The data format TF03 in CAN mode is shown below. All the data are hexadecimal number and there are 8 bytes in each data frame. The data includes real measured distance(DIST); the other bytes are reserved.

Data Byte Define Description
Byte0 DIST_L DIST low eight bits
Byte1 DIST_H DIST high eight bits
Byte2 Reserved /
Byte3 Reserved /
Byte4 Reserved /
Byte5 Reserved /

Customized Configuration

General Command Description

The product parameters can be changed to meet requirements of various application. Users can send the related command to revise the orignal parameters, such as output data format, frame rate and so on. After the setting completed, input wirte-in configuration command then the parameters will be saved in Flash and users don't need to reset after restarting the device.

Please change the parameters according to the instruction, and do not try sending irrelevant or unstated command in case of casuing unnecessary lost.

Byte byte0 byte1 byte2 byte3~byteN-2 byteN-1
Description Head Len ID Payload Check sum
Function Downstream Upstream Description Factory Configuration
Get firmware Version 5A 04 01 5F 5A 07 01 V1 V2 V3 SU Version: V3.V2.V1; SU: checksum /
System Reset 5A 04 02 60 Succeed: 5A 05 02 00 61; Fail: timeout 1s, no response / /
Set Output frame rate 5A 06 03 LL HH SU Succeed: same as downstream; Fail: timeout 1s, no response / 100fps
Enable Output Enable: 5A 05 07 01 67; Disable: 5A 05 07 00 66 Succeed: same as downstream; Fail: timeout 1s, no response / Enable
Single Trigger 5A 04 04 62 Data Frame / /
Set Output Format 5A 05 05 LL SU Succeed: same as downstream; Fail: timeout 1s, no response LL: output format, for instance: 00:ASCII output(reserved);01: binary output; 02: PIX output; 05: IO output Binary
Set serial band rate 5A 08 06 H1 H2 H3 H4 SU Succeed: same as downstream; Fail: timeout 1s, no response band rate=(H4 << 24)+(H3 << 16)+(H2 << 8)+H1 115200
Check and Enable Enable:5A 05 08 01 68; Disable: 5A 05 08 00 67 Succeed: same as downstream; Fail: timeout 1s, no response / Enable
Restore Factory Configuration 5A 04 10 6E Succeed: 5A 05 10 00 6F; Fail: 5A 05 10 ER SU Fails if ER is not equal to 0 /
Save Configuration 5A 04 11 6F Succeed:5A 05 11 00 70; Fail:5A 05 11 ER SU Fails if ER is not equal to 0 /
Configure Over Range Value 5A 06 4F LL HH SU Succeed: 5A 05 4F 00 AE; Fail: timeout 1s, no response Over Range Value=(HH << 8) + LL, unit: cm 18000
Configure CAN transmit ID 5A 08 50 H1 H2 H3 H4 SU Succeed:5A 05 50 00 AF; Fail: timeout 1s, no response ID=(H4 << 24)+(H3 << 16)+(H2 << 8)+H1 0x3
Configure CAN receive ID 5A 08 51 H1 H2 H3 H4 SU Succeed: 5A 05 51 00 B0; Fail: timeout 1s, no response ID=(H4 << 24)+(H3 << 16)+(H2 << 8)+H1 0x3003
Configure CAN band rate 5A 08 52 H1 H2 H3 H4 SU Succeed:5A 05 52 00 B1; Fail: timeout 1s, no response Baudrate=(H4 << 24)+(H3 << 16)+(H2 << 8)+H1 1000000
Configure CAN transmit frame type Standard frame:5A 05 5D 00 BC; Expanded Frame:5A 05 5D 01 BD Succeed:5A 05 5D 00 BC; Fail: timeout 1s, no response / Standard Frame
Configure transmit mode TTL: 5A 05 45 01 A5; CAN: 5A 05 45 02 A6 Succeed: 5A 05 45 00 A4; Fail: timeout 1s, no response / TTL
Environment Compensation Algorithm Enable:5A 05 64 00 C3; Disable: 5A 05 64 01 C4 Succeed: 5A 05 64 00 C3; Fail: timeout 1s, no response / Enable
Configure offset 5A 06 69 LL HH SU Succeed:5A 05 69 00 C8; Fail: timeout 1s, no response Offset = (HH << 8) + LL, unit: cm 0
Set Trigger level for short distance 5A 05 61 LV SU Succeed: 5A 05 61 00 C0; Fail: timeout 1s, no response LV=0, low level trigger; LV=1, high level trigger Low
Set IO output delay 5A 08 62 L1 H1 L2 H2 SU Succeed: 5A 05 62 00 C1; Fail: timeout 1s, no response Delay1 = (H1 << 8) + L1,Delay2 = (H2 << 8) + L2 (unit:ms), respectively represent the delays of IO level change in short or long distance. Range: 0~65000 0, 0
Set distance threshold and buffer distance 5A 08 63 L1 H1 L2 H2 SU Succeed: 5A 05 63 00 C2; Fail: timeout 1s, no response Dist= (H1 << 8) + L1,Buff=(H2 << 8) + L2 (unit: cm), respectively represent the distance threshold and buffer distance of IO change. Range: 0~18000. 18000,0

Description:

Tutorial

To give users a direct impression on the Laser Range Sensor, this tutorial provides the following information:

  1. How to use this TF03 Laser Range Sensor on Arduino?

  2. How to read the output distance of the sensor on PC?

  3. Black and white line detection.

Requirements

Debugging on Arduino (PC serial port)

Since the TF mini is a serial device and the ordinary Arduino has only one hardware serial, we recommand using the sensor together with a software serial. Of course, users can also use device with multi-serial port, such as Arduino Leonardo, Arduino Mega2560 and so on. Here we use the common Arduino Uno as the controller, and define D12 and D13 as software serial port.

Arduino Connection

SEN0328 TF03 Laser Range Sensor(100m) Arduino Connection

Sample Code(Arduino Debugging)

  * @File  : DFRobot_TFmini_test.ino
  * @Brief : This example use TFmini to measure distance
  *         With initialization completed, we can get distance value and signal strength
  * @Copyright   [DFRobot](https://www.dfrobot.com), 2016
  *             GNU Lesser General Public License
  *
  * @version  V1.0
  * @date  2018-1-10
*/

#include <DFRobot_TFmini.h>

SoftwareSerial mySerial(12, 13); // RX, TX

DFRobot_TFmini  TFmini;
uint16_t distance,strength;

void setup(){
    Serial.begin(115200);
    TFmini.begin(mySerial);
}

void loop(){
    if(TFmini.measure()){                      //Measure Distance and get signal strength
        distance = TFmini.getDistance();       //Get distance data
        strength = TFmini.getStrength();       //Get signal strength data
        Serial.print("Distance = ");
        Serial.print(distance);
        Serial.println("cm");
        Serial.print("Strength = ");
        Serial.println(strength);
        delay(500);
    }
    delay(500);
}

Distance Display on LCD

In actual applications, the sensor may need to be used without a PC. So in this tutorial, the li-ion battery will be power supply and the LCD is used for displaying detected distance.

SEN0328 TF03 Laser Range Sensor(100m) Distance Display on LCD

Arduino Test Code

/*
  * @File  : DFRobot_TFmini_test.ino
  * @Brief : This example use TFmini to measure distance
  *         With initialization completed, we can get distance value and signal strength
  * @Copyright   [DFRobot](https://www.dfrobot.com), 2016
  *             GNU Lesser General Public License
  *
  * @version  V1.0
  * @date  2018-1-10
*/
#include <Wire.h>
#include <DFRobot_LCD.h>         
#include <DFRobot_TFmini.h>            //TF Mini header file

SoftwareSerial mySerial(12, 13);      // RX, TX
DFRobot_TFmini  TFmini;
uint16_t distance,strength;

unsigned int lcd_r = 0, lcd_g = 0, lcd_b = 0;  
unsigned long delaytime = 0, lighttime = 0;
DFRobot_LCD lcd(16, 2); 
void setup()
{lcd.init();  
  delay(5000);
  Serial.begin(115200);
  Serial.println("hello start");

  TFmini.begin(mySerial);
  lighttime = millis();  
  lcd.setCursor(0, 0);
  lcd.print("Dis:");
  lcd.setCursor(0, 1);
  lcd.print("Str:");
  lcd.setRGB(255, 255, 000);
}
void loop() {

/******************LCD*******************/
 lcd_r = random(256);  
  delayMicroseconds(10);  
  lcd_g = random(256);  
  delayMicroseconds(10); 
  lcd_b = random(256); 
  if (millis() - lighttime > 3000)  
  {
    lcd.setRGB(lcd_r, lcd_g, lcd_b);  
    lighttime = millis();   
  }
  //delay(100);
  /**************TF Mini***************/
 if(TFmini.measure()){                          //Measure Distance and get signal strength
        distance = TFmini.getDistance();       //Get distance data
        strength = TFmini.getStrength();       //Get signal strength data

    lcd.setCursor(5, 0);                       //LCD display
    lcd.print(  distance / 10000);            
    lcd.print(  distance/ 1000 % 10); 
    lcd.print('.');
    lcd.print(  distance / 100 % 10);
    lcd.print(  distance / 10 % 10);
    lcd.print(  distance  % 10);
    lcd.print(" m");
    lcd.setCursor(5, 1);
    lcd.print(strength / 10000); 
    lcd.print(strength / 1000 % 10);
    lcd.print(strength / 100 % 10);
    lcd.print(strength / 10 % 10);
    lcd.print(strength % 10);
    }
}        

Distance Display on Upper PC

In addition to reading data through a single chip, we can also use a PC software to read the detected distance.

Connection: connect the TF mini to a computer via a USB-to-TTL module, and read data through the upper PC.

SEN0328 TF03 Laser Range Sensor(100m) Distance Display on Upper PC

Result:

SEN0328 TF03 Laser Range Sensor(100m) Distance Display on Upper PC Result

Detection of Black and White Line

Connection

SEN0328 TF03 Laser Range Sensor(100m) Detection of Black and White Line

Arduino Code

/*
  * @File  : DFRobot_TFmini_test.ino
  * @Brief : This example use TFmini to measure distance
  *         With initialization completed, we can get distance value and signal strength
  * @Copyright   [DFRobot](https://www.dfrobot.com), 2016
  *             GNU Lesser General Public License
  *
  * @version  V1.0
  * @date  2018-1-10
*/

#include <DFRobot_TFmini.h>

SoftwareSerial mySerial(12, 13); // RX, TX

DFRobot_TFmini  TFmini;
uint16_t distance,strength;

void setup(){
    Serial.begin(115200);
    TFmini.begin(mySerial);
}

void loop(){
    if(TFmini.measure()){                      //Measure Distance and get signal strength     
        strength = TFmini.getStrength();       //Get signal strength data
        Serial.print("Strength = ");
        Serial.println(strength);  
    }
}    
SEN0328 TF03 Laser Range Sensor(100m) Result of white and black line detection

Tutorial on Raspberry Pi

Requirements

Connection with Raspberry Pi

SEN0328 TF03 Laser Range Sensor(100m) Connection with Raspberry Pi

Sample Code

# -*- coding:utf-8 -*-

'''
  # DFRobot_TFmini.py
  #
  # Connect board with raspberryPi.
  # Run this demo.
  #
  # Connect TFmini to UART
  # get the distance value
  #
  # Copyright   [DFRobot](https://www.dfrobot.com), 2016
  # Copyright   GNU Lesser General Public License
  #
  # version  V1.0
  # date  2019-8-31
'''

import time

from DFRobot_TFmini import TFMINI

mini = TFMINI()

def main():
    while True:
        if mini.measure():
            distance = mini.getDistance()
            strength = mini.getStrength()
            print("Distance = %.d" % distance)
            print("Strength = %.d" % strength)
            time.sleep(0.5)
        time.sleep(0.5)

if __name__ == "__main__":
    main()

FAQ

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

More Documents