LiDARs are great devices for detecting obstacles and measuring distances. Here we use one for taking precise distance readings up to 12 meters with a resolution of 1 cm. My original idea of buying a TFMini-S LiDAR was to build some kind of radar with it. But, as happens so often, nothing really got done with the device until I had an enlightening experience at my job.

Electric Resistance Welded (ERW) pipes are long pipes with a diameter of 300 mm or more and with a length of up to twelve meters. They are used in our power plant for ash slurry transportation. One day, while handling these long pipes for assembly line-up of ash slurry discharge pipelines, I found that my team had to measure each pipe precisely before taking them out through the exit gate. Every day, at least 30 to 50 times, someone has to devote time for doing these measurements. Out in the open under a 47°C scorching sun, holding the tape measure at one end and a supervisor on the other end, then recording the length, is a very tiresome job. The idea of creating a precision measuring gauge took birth here. 
Source: ElisaRiva, Pixabay

LiDAR Modules

The TFMini-S single-point ranging LiDAR (Figure 1) can take distance readings very fast (100 Hz) and very precisely (1 cm resolution, 1% accuracy) up to 12 m, which is exactly right for the job. There’s also a Plus version which is faster (1 kHz) and has an IP65-rated enclosure. Both come with a serial interface.
 

Figure 1: The low-cost TFMini-S LiDAR features a range of 12 m
with a resolution of 1 cm.

Placing the LiDAR at one end of the pipe and then directing it towards the edge plate on the other end will give an accurate length of the pipe. Both versions of the LiDAR have a Field of View (FOV) of 3.4 degrees; therefore, pointing it properly is very important for getting correct readings. To make this easier, we added a push-button-operated laser pointer to our system.

I used an ESP32 module for controlling the LiDAR and for doing the calculations. A small OLED display was added to show the distance readings. Incorporating a running average of a few measurements increases precision. Then the result can be printed as a floating-point value, but for speed and simplicity we have kept it as a plain integer value.

The TFMini LiDARs use the reflection of invisible infrared laser light from the surface of the object that they are aimed at. In case the object does not reflect or completely absorbs or defuses the incoming laser light, the reading will be erroneous. For instance, avoid water and slanted and highly reflective glass windows. Most other objects reflect enough light and measurements are taken easily, even when the object is moving.

Constructing the Range Gauge

When building the device, I had to keep in mind that it had to be portable to allow my team to use it out in the field. The device must therefore be battery powered. The circuit I ended up with is shown in Figure 2. Both the LiDAR and the laser diode that I used for pointing need 5 V. The ESP32 WROOM module needs only 3.3 V. Therefore, I added a mini boost converter which can generate a 5 V supply out of an input voltage of as low as 2 V. I connected a low-dropout HT7333-A voltage regulator to the 5 V output to make 3.3 V for the ESP32. If you use an ESP32 module with on-board voltage regulator, then you don’t need the HT7333-A. The complete setup runs from two 1.5-volt batteries or from a 3.7-volt LiPo battery. Note that the HT7333-A is a surface-mount device (SMD); therefore, be careful while mounting it.

Figure 2: The prototype used an ESP32-WROOM module, which does not have a 5-V regulator built in.
When using a DevMod-C- or Pico-Kit-kind of module, IC1 can be omitted. In that case,
connect the 5-V supply to the module’s 5-V input, not to its 3.3-V pin!

A Word About the Software for TFMini-S LiDAR

The software I wrote for the device is an Arduino sketch and can be downloaded from Elektor Labs. It requires the TFMini library and Adafruit’s GFX SSD1306 libraries that are available from the Arduino IDE’s library manager.

The LiDAR and the ESP32 communicate with each other over a serial port (Serial1). Every 25 ms, a new data point is requested. All the hard work is done by the TFMini library, while the sketch simply provides a user interface. Distance- and signal strength values are printed on the OLED screen and are also transmitted on the “Arduino” serial port (Serial0).

Using the Device

After assembling all the parts on a general-purpose PCB (Figure 3), position the LiDAR on the edge of the board such that it has a clear view of the object. The laser pointer is a plain red laser diode controlled by a push button. If possible, fix it on top of the LiDAR with hot glue (or something similar) such that both point in the same direction.

Figure 3: The prototype of the LiDAR-based precision gauge was built on a general-purpose prototyping board. Note how the laser pointer is hot-glued on top of the LiDAR module.

The minimum distance the TFMini-S LiDAR can handle is 30 cm. Therefore, point it at an object or wall somewhere in the range of 30 cm to 12 m. Measure the distance and cross check with a tape measure. Eventually you will find that the reading is precise up to a centimeter.
The second line on the display indicates the strength of the received signal. As the object moves away, the strength diminishes.

Use the Automator with TFMini-S LiDAR!
The Elektor Automator is the perfect platform for playing with the TFMini-S LiDAR. Based on an ESP32 module, it has a Grove connector compatible with the LiDAR module, it has an OLED display and the necessary power supplies. We (at Elektor Labs) therefore created an Arduino sketch for this project that runs on the Automator.
It uses the TFLidar and U8g2 libraries, available from the Arduino IDE’s library manager. The software can easily be extended to add Wi-Fi or Bluetooth connectivity and to control the Automator’s relay and LEDs. It can be downloaded from here.