TFMini - Micro LiDAR Module Hookup Guide
Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.
Download and install Peter Jansen's Arduino TFMini library using the library manager. You can also manually install it from the GitHub Repository by downloading the library from the button below.
Grab a mini-USB cable and connect the Arduino to your computer. Upload the BasicReading.ino that was included in the library's examples to your Arduino. Make sure to use the correct COM port and board selection.
Once uploaded, try moving an object in front of the sensor to test. In the example below, a third hand was used to hold the TFMini when detecting an object at a certain distance away from the sensor. Since the sensor is not able to detect an object when less than 11.8 inches (or 30cm = 0.3m) away, the object under test was placed at 20 inches and 30 inches.
|TFMini Reading an Object at 20 Inches||TFMini Reading an Object at 30 Inches|
Opening the serial monitor at 115200, you may see an output similar to the values printed below. Using a yard stick, the values responded as expected when moving an object between 20 inches and 30 inches.
Initializing... 54 cm sigstr: 457 54 cm sigstr: 456 54 cm sigstr: 456 54 cm sigstr: 456 55 cm sigstr: 456 54 cm sigstr: 456 54 cm sigstr: 456 54 cm sigstr: 457 67 cm sigstr: 340 70 cm sigstr: 315 71 cm sigstr: 315 77 cm sigstr: 283 77 cm sigstr: 283 77 cm sigstr: 283 77 cm sigstr: 283 77 cm sigstr: 284 78 cm sigstr: 281 78 cm sigstr: 281 78 cm sigstr: 282 78 cm sigstr: 282 78 cm sigstr: 283
This may be caused by your Arduino not properly communicating with the TFMini. For example, the maximum baud an Arduino at 8MHz can handle with the software serial library is 57600 baud. If you are using a 3.3V/8MHz Arduino Pro Mini with a baud rate of 115200, it is probably too high which can cause unreliable readings. It is recommended to use a 5V/16MHz Arduino if you are using the software serial library to communicate with the sensor at 115200.
TF Mini error: too many measurement attempts Last error: ERROR_SERIAL_NOHEADER 65535 cm sigstr: 65535
As an alternative to check if the TFMini is still functioning at small distances, you can try using the TFMini's GUI with a USB-to-Serial cable. Just make sure that you are providing 5V for Vcc and communicating with 3.3V logic levels.