I have a TF-Mini S Lidar. I have hooked it up to my arduino like so:

tf mini s pinout(Above image from learn.sparkfun.com)

tf mini s hookup

And have uploaded this code to the arduino board:

// soft serial port header file
SoftwareSerial Serial1(2,3); // define the soft serial port as Serial1, pin2 as RX, and pin3 as TX
/*For Arduino board with multiple serial ports such as DUE board, comment out the above two codes, and directly use Serial1 port*/
int dist;// LiDAR actually measured distance value
int strength;// LiDAR signal strength
int check;// check numerical value storage
int i;
int uart[9];// store data measured by LiDAR
const int HEADER=0x59;// data package frame header
void setup()
  Serial.begin(9600);//set the Baud rate of Arduino and computer serial port
  Serial1.begin(115200);//set the Baud rate of LiDAR and Arduino serial port
void loop()
  if (Serial1.available())//check whether the serial port has data input
    if(Serial1.read()==HEADER)// determine data package frame header 0x59
      if(Serial1.read()==HEADER)//determine data package frame header 0x59
        for(i=2;i<9;i++)// store data to array
      if(uart[8]==(check&0xff))// check the received data as per protocols
        dist=uart[2]+uart[3]*256;// calculate distance value
        strength=uart[4]+uart[5]*256;// calculate signal strength value
        Serial.print("dist = ");
        Serial.print(dist);// output LiDAR tests distance value
        Serial.print("strength = ");
        Serial.print(strength);// output signal strength value

(from forum.arduino.cc)

An when I run it, the Lidar shows a laser beam, however no serial data is being sent to the arduino board, and if it is, its just random symbols.

Is there anything i can do to fix this?

  • \$\begingroup\$ Try swapping Tx and Rx. I don't know if it will fix the problem, but sometimes they're labeled in reverse. \$\endgroup\$ Commented Aug 14, 2020 at 15:36
  • \$\begingroup\$ Which Arduino is it? Does it run at 8 MHz or 16 MHz? \$\endgroup\$
    – Justme
    Commented Aug 14, 2020 at 16:02
  • \$\begingroup\$ .read from the serial library will return -1 if there is nothing there to read, so your code may be running too fast between reading the header byte, and you requesting the next one. You may have to insert some while (!Serial1.available()) ; waits in there to allow time for the next byte to arrive. Also, do you expect the HEADER byte to come in twice? .reading it removes it from the buffer, so .read again won't work if it only comes in once, it should probably be .peek() for the first call instead of .read. \$\endgroup\$
    – Ron Beyer
    Commented Aug 14, 2020 at 16:48

2 Answers 2


Did you use the sensor on a 5V Arduino Uno without the level converter mentioned in the tutorial? This could have damaged the sensor, because the Arduino Uno I/O pins are 5V and the TF mini can only handle 3.3V levels on its serial pins.


If you have an Arduino Uno,as shown in the diagram, there is only one serial port, at pins 0 and 1, and they're the same as the serial communication with your PC, so they will interfere with each other.

Source: https://www.arduino.cc/reference/en/language/functions/communication/serial/

I suggest that you either get an Arduino with more serial ports (Easiest and best option), or not have any communication with the computer. The latter would make debugging harder, and you'll have to find a way to display the LiDAR data from the Arduino, without using the Serial Monitor.

Another option might be to use software serial, but I don't know how well it works, and it might be too slow for the LiDAR application.

  • 1
    \$\begingroup\$ The code that the OP posted is using SoftwareSerial... \$\endgroup\$
    – Ron Beyer
    Commented Aug 14, 2020 at 18:11
  • \$\begingroup\$ OH, you're right! I missed it somehow. My bad. I'm new here, should I delete the answer in this case? Or just leave it as is? \$\endgroup\$
    – Diatrix
    Commented Aug 14, 2020 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.