The self-driving car is technology’s biggest gift to civilization since the birth of the Internet. It’s only a matter of time before these cars take over the roads.

In order for a self-driving car to successfully navigate a road, it must be aware of the physical objects around it. Thanks to the spinning LiDAR sensor mounted on the roof, which helps generate a three-dimensional view of the road around the vehicle.

LiDAR isn’t new and has been around for a while; in fact, it was conceived shortly after the development of the laser. Early work on LiDAR was documented in 1963. The high cost of laser equipment limited the use of LiDAR to only government and military agencies.

However, recent price drops have made LiDAR accessible to DIYers like us, allowing us to incorporate it into our projects. One of the widely used low-cost yet accurate LiDAR sensors is the TFMini-S.

This tutorial will show you how to interface the TFMini-S module with an Arduino to perform high-accuracy distance measurements, but first, a brief introduction to LiDAR.

What is LiDAR and How does it Work?

LiDAR is a combination of the words “Light” and “RADAR” or, if you prefer, a backronym for “Light Detection And Ranging”. LiDAR is like RADAR, except that it uses light instead of radio waves.

At its core, LiDAR works by shooting a laser at an object. The laser bounces off of the object and returns to the sensor. By measuring the time it takes for that light to return to the sensor, the distance to the object can be estimated. The distance measured may vary depending on the environment and the reflectivity of the object.

lidar scanning working

By sweeping or spinning a LiDAR sensor, a 3D map of the area can be quickly constructed. Typically, this is presented as a “point cloud” to better understand what the LiDAR is picking up.

lidar 3d point cloud
Courtesy: Dana Peters – Arduino-based LiDAR Scanner – http://youtu.be/xkut3yRL61U

TFMini-S Hardware Overview

The TFMini-S is a high-accuracy, single-point ToF (Time of Flight) LiDAR sensor from Benewake (Beijing) Co. Ltd. It’s perfect for incorporating high-accuracy laser-based ranging into any robotics or interactive project.

tfmini s

The size of a USB stick, the TFMini-S allows you to integrate LiDAR into projects that were previously reserved for smaller sensors like the SHARP GP-series infrared rangefinders.

The TFMini-S can measure the distance to an object as close as 10 centimeters and as far as 12 meters.

In addition to its low cost, small size, and long range, the TFMini-S has a higher distance measurement accuracy of ±6cm up to 6m and ±1% thereafter.

It should be noted that this sensor does not use laser light for ranging. Instead, it uses a focused 850nm infrared LED and optics. That is why the device is relatively inexpensive.

Effective Detection Range

As with all LiDAR sensors, the effective detection range depends on lighting conditions, weather, and the reflectivity of your target object.

The graph below shows the operating range of the TFMini-S under various conditions.

lidar effective detection range
  • 0-10cm is TFMini-S’s blind zone; within this range, data is unreliable.
  • Under extreme conditions, the operating range of the TFMini-S is 0.1-3m. Extreme condition refers to the outdoor glare (of which illumination intensity is around 100klux outdoors at noon in summer) and detection of black target (with reflectivity of 10%).
  • Under normal sunlight conditions (with illumination intensity of around 70klux), the operating range of the TFMini-S is 0.1-7m.
  • In an indoor environment or with low ambient light, the operating range of the TFMini-S is 0.1-12m.

Communication Interfaces

The TFMini-S communicates over the UART interface by default, with commonly used UART RX and TX pins operating at 115200bps.

You can also configure the sensor to communicate over I2C by sending the appropriate commands.

Detection Frequency

According to the datasheet, the TFMini-S can perform at up to 1000 measurements per second (default is 100). This frequency can be changed by sending the appropriate commands.

It should be noted that increasing the output frequency reduces accuracy. Therefore, depending on how accurate you want the measurements to be, you should adjust the output frequency.

Input Power

According to the datasheet, the TFMini-S operates on 5V and draws about 140 mA during an acquisition. The maximum current it could draw is around 200 mA.

During testing, however, the sensor was drawing about 70mA on its own. So, if you use a 5V Arduino, a logic level converter, and the sensor, you can expect to consume around 100mA. Therefore, for basic tests, the sensor can be powered by the USB port (5V/500mA) without issue.

Please keep in mind that the TFMini-S has no overvoltage protection, so keep the power supply voltage fluctuations within 0.1V.

Logic Levels

While the TFMini-S can be powered at 5V, the I/O pins are only 3.3V logic. Therefore, it is recommended to use a logic level converter when using the sensor with a 5V microcontroller.

However, if you only want to read the TFMini-S (in UART mode), you don’t need a logic level converter because 3.3V devices output logic levels that are compatible with 5V devices.

Technical Specifications

Here are the specifications:

Detection range10cm – 12m
Resolution1cm
Ranging Accuracy±6cm up to 6m and ±1% thereafter
Input Voltage5V
UART TTL Voltage3.3V
Current Consumption140mA (typ.), 800mA (peak)
Detection Frequency1 to 1000 scans per second (adjustable)
Light Wavelength850nm
Field of view2.3°
Communication interfacesUART and I2C
Baud Rate115200

For more information about the TFMini-S LiDAR sensor, please refer to the datasheet below.

TFMini-S Pinout

Now let’s have a look at the pinout. The TFMini-S has four pins.

tfmini s pinout

GND is the Ground connection.

VCC is the power input pin. Connect it to 5V power supply only.

RXD/SDA is the pin that you can use to send data to the sensor (when communicating via UART) or send/receive data (when communicating via I2C). It is 3.3V logic level.

TXD/SCL is the pin that either transmits data from the sensor to your microcontroller (when communicating via UART) or functions as a clock (when communicating via I2C). Note that it is also 3.3V logic level.

Wiring a TFMini-S Sensor to an Arduino

Connecting a TFMini-S sensor to an arduino is a breeze. You only need to connect four wires.

Begin by connecting the Red wire (VCC) of the TFMini-S sensor to the Arduino’s 5V output pin and the Black wire (GND) to the Arduino’s GND pin.

Now connect the White wire (RXD/SDA) of the TFMini-S sensor to the Arduino’s digital pin 3 and Green wire (TXD/SCL) to the Arduino’s digital pin 2, as we will be implementing a software UART.

The image below shows how to build the circuit.

wiring tfmini s to arduino

Arduino Example Code

Now that we have everything hooked up, let’s run a simple sketch to demonstrate the capabilities of the TFMini-S sensor.

#include <SoftwareSerial.h>   //header file of software serial port
SoftwareSerial Serial1(2, 3); //define software serial port name as Serial1 and define pin2 as RX & pin3 as TX
 
int dist;                     //actual distance measurements of LiDAR
int strength;                 //signal strength of LiDAR
int check;                    //save check value
int i;
int uart[9];                   //save data measured by LiDAR
const int HEADER = 0x59;      //frame header of data package
 
 
void setup()
{
  Serial.begin(9600);         //set bit rate of serial port connecting Arduino with computer
  Serial1.begin(115200);      //set bit rate of serial port connecting LiDAR with Arduino
}
 
 
void loop() {
  if (Serial1.available())                //check if serial port has data input
  {
    if (Serial1.read() == HEADER)        //assess data package frame header 0x59
    {
      uart[0] = HEADER;
      if (Serial1.read() == HEADER)      //assess data package frame header 0x59
      {
        uart[1] = HEADER;
        for (i = 2; i < 9; i++)         //save data in array
        {
          uart[i] = Serial1.read();
        }
        check = uart[0] + uart[1] + uart[2] + uart[3] + uart[4] + uart[5] + uart[6] + uart[7];
        if (uart[8] == (check & 0xff))        //verify the received data as per protocol
        {
          dist = uart[2] + uart[3] * 256;     //calculate distance value
          strength = uart[4] + uart[5] * 256; //calculate signal strength value
          Serial.print("distance = ");
          Serial.print(dist);                 //output measure distance value of LiDAR
          Serial.print('\t');
          Serial.print("strength = ");
          Serial.print(strength);             //output signal strength value
          Serial.print('\n');
        }
      }
    }
  }
}

Once the sketch is uploaded, open your serial monitor, setting the baud rate to 9600 bps.

Try pointing the sensor at objects lying around you. You should see the measured distance begin to stream by.

tfmini s arduino output

If there is no information displayed, make sure the TFmini-S is properly connected; when turned on a red light should be visible inside the transmitting lens when viewed from in front.

TFMini Software

The TFMini software is a powerful tool for testing TFMini sensors. It is a free tool, but it can only be used on the Windows platform.

You can download this program from the official Benewake website.

Connecting TFMini to Software

To use the TFMini software, connect your TFMini-S to your PC using a USB to TTL converter. Just make sure that you are providing 5V for VCC.

wiring tfmini s to usb to ttl converter

Using TFMini Software

The software itself comes as a “Portable” RAR package. Download it and extract to a folder of your choice. Launch the WINCC_TF.exe.

The program will start up as shown below.

tfmini software

Find the Settings section and choose TFMiniS for the product type. Next, select the COM port to which the TFMini-S is connected. Finally, press the Connect button.

tfmini software settings

Once the device is connected, the program begins to display a distance-over-time waveform in the “Time Line Chart” section. Down below, the “Real Time Data” section displays the current distance (Dist), the number of effective data points per second (Effective Points), and the signal strength (Strength).

tfmini software waveform

Login
ADS CODE