Welcome to TinyF Laser Ranging Module repository
arduino
TinyF and Arduino serial communication
TinyF and Arduino serial communication0.Introduction to TinyF1.Experimental Preparation2.Experimental wiring3. Main code explanation4.Experimental phenomenon5.Some important parameters of TinyF
0.Introduction to TinyF
- The TinyF laser ranging module is based on a D-TOF single-point laser sensor, an onboard MCU, and a housing. It features built-in sunlight rejection and anti-cover contamination algorithms, enabling accurate and rapid distance measurement. Even in extremely bright ambient light (100-190K Lux), it can accurately measure even the smallest objects, unaffected by variations in reflectivity, achieving precise ranging of 2m to 4m.
1.Experimental Preparation
- TinyF Laser Distance Measurement Module
- This tutorial uses an Arduino
2.Experimental wiring
| Arduino | TinyF |
|---|---|
| TX(1) | RX |
| RX(0) | TX |
| GND | GND |
| 5V | 5V |
Wiring diagram

Note: If you are using a USB to TTL module, refer to the following table for wiring the Arduino and USB to TTL
| Arduino | TinyF |
|---|---|
| RX(0) | TX |
| GND | GND |
| 5V | 5V |
| Arduino | USB转TTL |
|---|---|
| TX(1) | RXD |
| GND | GND |
3. Main code explanation
void parseDistanceData(String &data) { // 去除首尾空白字符 Remove the first and last whitespace characters data.trim(); // 查找逗号位置 Find the position of the comma int commaPos = data.indexOf(','); if (commaPos == -1) { return; } // 提取距离 Extraction distance String distanceStr = data.substring(0, commaPos); distanceStr.trim(); // 提取置信度 Extract the confidence level section String confidenceStr = data.substring(commaPos + 1); confidenceStr.trim(); // 转换为整数 Convert to an integer long distance = distanceStr.toInt(); long confidence = confidenceStr.toInt(); if ((distance <=20 || distance>=4000) && distanceStr != "0") { return; } if (confidence == 0 && confidenceStr != "0") { return; } // 输出结果 output result Serial.print("Distance:"); Serial.print(distance); Serial.print(" mm, Confidence: "); Serial.println(confidence);}The above program is used to parse data from the TinyF laser ranging module. Only when the protocol is met can the data be correctly parsed.
4.Experimental phenomenon
1.Upload the program provided by the example to the Arduino
2.Connect the wires according to the wiring diagram.
3.The serial port assistant is set to the interface as shown in the figure
4.After power on, the serial assistant will print the distance information
5.Some important parameters of TinyF
Related parameter description
| name | value |
|---|---|
| Baud rate | 115200 |
| Effective minimum distance (theoretical value) | 20,unit:mm |
| Effective maximum distance (theoretical value) | 4000,unit:mm |
| Confidence | 0~62,The larger the value, the higher the distance reliability. |
Data format
Data frame structure: 
Example: 
| Field | Number of bytes | Example(Hex) | ASCII characters |
|---|---|---|---|
| Frame header (fixed value) | 1 | 20 | space |
| Distance value(distance) | 1~5 | 33 32 37 | 327 |
| Delimiter (fixed value) | 2 | 2C 20 | ,space |
| Confidence(confidence) | 1~2 | 36 31 | 61 |
| Frame tail (fixed value) | 1 | 0A | \n |