TF-Luna distance sensor and multicolor connection cable, angled front view

TF-Luna 8m LiDAR Distance Sensor | ShillehTek Product Manual

ArduinoESP32Raspberry PiPicomanual-product-10645385937183
$33.99 USD In stock · Order by 3pm ET, ships today

Overview

The TF-Luna is a single-point LiDAR distance sensor. It sends out pulses of invisible 850 nm infrared light and times how long they take to come back, which gives the distance to whatever is directly in front of it. It measures from 0.2 to 8 m with 1 cm resolution, updates 100 times a second by default (adjustable from 1 to 250 Hz) and weighs under 5 g.

Compared with an ultrasonic sensor it has a much narrower 2° beam, a far longer range and a faster update rate. It needs a 5 V supply (3.7 to 5.2 V), but its signal pins use 3.3 V logic. Out of the box it streams readings over UART at 115200 baud, and grounding pin 5 at power-up switches it to I2C at address 0x10. One sensor and its connection cable are included.

Typical uses are robot obstacle detection, drone altitude hold, level and presence sensing, and handheld rangefinders. This manual covers the connector pinout, wiring for Arduino, ESP32, Raspberry Pi and Pico, working code for each, and answers on power, I2C mode, signal strength and range limits.

At a Glance

Type
Single-point ToF LiDAR
Range
0.2 – 8 m
Accuracy
±6 cm to 3 m, ±2% beyond
Interface
UART (default) or I2C
Supply
5 V (3.7 – 5.2 V)
Logic Level
3.3 V

Specifications

Parameter Value
Operating range 0.2 – 8 m at 90% reflectivity (0.2 – 2.5 m at 10%)
Accuracy ±6 cm from 0.2 to 3 m · ±2% from 3 to 8 m
Resolution 1 cm
Frame rate 1 – 250 Hz, default 100 Hz
Field of view 2°
Light source 850 nm VCSEL, Class 1 eye-safe
Ambient light Works in up to 70 klux
Supply voltage 3.7 – 5.2 V, no reverse-polarity or overvoltage protection
Supply current ≤ 70 mA average, 150 mA peak
Interface UART 115200 8N1 (default) or I2C at 0x10, 3.3 V logic
Temperature -10 to 60 °C
Size and weight 35 × 21.25 × 13.5 mm, under 5 g

Pinout Diagram

Hold the sensor with the lenses facing you and the connector at the bottom: pin 1 is then on the left. Pin 1 is +5V power, pin 2 is RXD (SDA in I2C mode), pin 3 is TXD (SCL in I2C mode) and pin 4 is GND. Pin 5 selects the interface: leave it open for UART, or connect it to GND before power-up for I2C. Pin 6 is a data-ready output used only in I2C mode. Wire colors differ between cable batches, so identify each wire by its position in the connector, not by its color.

TF-Luna LiDAR distance sensor pinout diagram showing the six connector pins: +5V, RXD/SDA, TXD/SCL, GND, configuration input and multiplexing output

Wiring Guide

All four setups use the default UART mode, so pins 5 and 6 stay unconnected. The TF-Luna sends its readings on TXD (pin 3), which goes to the receive pin of your board. Double-check power and ground before plugging in: the sensor has no reverse-polarity protection.

Arduino Uno / Nano Wiring

TF-Luna Pin Arduino Pin Notes
1 · +5V 5V Power
2 · RXD Not used 3.3 V input
3 · TXD D2 Data out
4 · GND GND Ground
3.3 V logic: Do not wire the Arduino's 5 V TX pin straight to RXD (pin 2). Reading distance needs only TXD. To send commands to the sensor, bring the Arduino's TX down to 3.3 V with a voltage divider or level converter first.
Serial port: An Uno or Nano has one hardware serial port and USB uses it, so the sketch reads the sensor with SoftwareSerial on D2. 115200 baud is near the limit for that, which is why the sketch checks every frame's checksum and drops damaged frames.

ESP32 Wiring

TF-Luna Pin ESP32 Pin Notes
1 · +5V 5V or VIN Power
2 · RXD GPIO 17 Serial2 TX
3 · TXD GPIO 16 Serial2 RX
4 · GND GND Ground
Use 5 V power: The 3V3 pin is below the TF-Luna's 3.7 V minimum, so use the 5V or VIN pin, which carries USB power. The 3.3 V data lines connect directly to the ESP32.

Raspberry Pi Wiring

TF-Luna Pin Raspberry Pi Pin Notes
1 · +5V 5V (Pin 2) Power
2 · RXD GPIO 14 (Pin 8) Pi TXD
3 · TXD GPIO 15 (Pin 10) Pi RXD
4 · GND GND (Pin 6) Ground
Enable serial: Run sudo raspi-config, open Interface Options and then Serial Port. Answer No to the login shell and Yes to the serial port hardware, then reboot.

Raspberry Pi Pico Wiring

TF-Luna Pin Pico Pin Notes
1 · +5V VBUS (Pin 40) USB 5 V
2 · RXD GP4 (Pin 6) UART1 TX
3 · TXD GP5 (Pin 7) UART1 RX
4 · GND GND (Pin 38) Ground
VBUS power: VBUS carries 5 V only while the Pico is plugged into USB. On battery power, feed the TF-Luna from its own 3.7 to 5.2 V supply and join the grounds.

Code Examples

View or download this product's example code on GitHub.

Each example reads the sensor's 9-byte data frames, verifies the checksum and prints distance, signal strength and chip temperature about ten times a second. The Arduino sketch picks SoftwareSerial on an Uno or Nano and Serial2 on an ESP32 automatically.

Arduino and ESP32 — Distance over UART

tf_luna_uart.ino
// TF-Luna LiDAR - read distance frames over UART (115200 baud)
// Uno/Nano: TF-Luna TXD (pin 3) -> D2. Leave RXD (pin 2) unconnected for reading.
// ESP32:    TF-Luna TXD (pin 3) -> GPIO 16, RXD (pin 2) -> GPIO 17
#if defined(ESP32)
  #define LIDAR Serial2
#else
  #include <SoftwareSerial.h>
  SoftwareSerial lidarPort(2, 3);   // RX = D2, TX = D3 (TX is not wired)
  #define LIDAR lidarPort
#endif

uint8_t frame[9];
unsigned long lastPrint = 0;

void setup() {
  Serial.begin(115200);
#if defined(ESP32)
  Serial2.begin(115200, SERIAL_8N1, 16, 17);   // RX = GPIO 16, TX = GPIO 17
#else
  lidarPort.begin(115200);
#endif
}

// Returns true when frame[] holds a complete 9-byte frame with a valid checksum
bool readFrame() {
  while (LIDAR.available() >= 9) {
    if (LIDAR.read() != 0x59) continue;        // first header byte
    if (LIDAR.peek() != 0x59) continue;        // second header byte
    frame[0] = 0x59;
    for (uint8_t i = 1; i < 9; i++) frame[i] = LIDAR.read();
    uint8_t sum = 0;
    for (uint8_t i = 0; i < 8; i++) sum += frame[i];
    if (sum == frame[8]) return true;
  }
  return false;
}

void loop() {
  if (!readFrame()) return;
  if (millis() - lastPrint < 100) return;      // print 10 readings per second
  lastPrint = millis();

  uint16_t distance = frame[2] | (frame[3] << 8);   // centimeters
  uint16_t strength = frame[4] | (frame[5] << 8);
  float tempC = (frame[6] | (frame[7] << 8)) / 8.0 - 256.0;

  if (strength < 100 || strength == 65535) {
    Serial.println("Signal unreliable - target too far, too dark, or overexposed");
  } else {
    Serial.print("Distance: ");
    Serial.print(distance);
    Serial.print(" cm   Strength: ");
    Serial.print(strength);
    Serial.print("   Chip temp: ");
    Serial.print(tempC, 1);
    Serial.println(" C");
  }
}

Raspberry Pi — Python

tf_luna_uart.py
#!/usr/bin/env python3
# TF-Luna LiDAR on Raspberry Pi over UART (GPIO 14 = TXD, GPIO 15 = RXD)
# Install once: sudo apt install python3-serial
# raspi-config -> Interface Options -> Serial Port: login shell NO, serial hardware YES
import time
import serial

port = serial.Serial("/dev/serial0", 115200, timeout=1)


def read_frame():
    """Return (distance_cm, strength, temp_c), or None if no valid frame arrived."""
    if port.read(1) != b"Y":            # 0x59, first header byte
        return None
    if port.read(1) != b"Y":            # 0x59, second header byte
        return None
    body = port.read(7)
    if len(body) != 7:
        return None
    if (0x59 + 0x59 + sum(body[:6])) & 0xFF != body[6]:
        return None                     # checksum mismatch
    distance = body[0] | (body[1] << 8)
    strength = body[2] | (body[3] << 8)
    temp_c = (body[4] | (body[5] << 8)) / 8.0 - 256.0
    return distance, strength, temp_c


try:
    while True:
        port.reset_input_buffer()       # drop old frames so the reading is fresh
        reading = read_frame()
        while reading is None:
            reading = read_frame()
        distance, strength, temp_c = reading
        if strength < 100 or strength == 65535:
            print("Signal unreliable - target too far, too dark, or overexposed")
        else:
            print(f"Distance: {distance} cm   Strength: {strength}   Chip temp: {temp_c:.1f} C")
        time.sleep(0.1)
except KeyboardInterrupt:
    port.close()

Raspberry Pi Pico — MicroPython

tf_luna_pico.py
# TF-Luna LiDAR on Raspberry Pi Pico (MicroPython) over UART1
# TF-Luna TXD (pin 3) -> GP5 (Pico RX), RXD (pin 2) -> GP4 (Pico TX), +5V -> VBUS, GND -> GND
from machine import UART, Pin
import time

uart = UART(1, baudrate=115200, tx=Pin(4), rx=Pin(5))


def read_frame():
    """Return (distance_cm, strength, temp_c), or None if no valid frame is waiting."""
    while uart.any() >= 9:
        if uart.read(1) != b"Y":        # 0x59, first header byte
            continue
        if uart.read(1) != b"Y":        # 0x59, second header byte
            continue
        body = uart.read(7)
        if body is None or len(body) != 7:
            return None
        if (0x59 + 0x59 + sum(body[:6])) & 0xFF != body[6]:
            continue                    # checksum mismatch
        distance = body[0] | (body[1] << 8)
        strength = body[2] | (body[3] << 8)
        temp_c = (body[4] | (body[5] << 8)) / 8 - 256
        return distance, strength, temp_c
    return None


while True:
    latest = None
    reading = read_frame()
    while reading:                      # drain the buffer and keep the newest frame
        latest = reading
        reading = read_frame()
    if latest:
        distance, strength, temp_c = latest
        if strength < 100 or strength == 65535:
            print("Signal unreliable - target too far, too dark, or overexposed")
        else:
            print("Distance: {} cm   Strength: {}   Chip temp: {:.1f} C".format(distance, strength, temp_c))
    time.sleep(0.1)

Frequently Asked Questions

Which wire is which on the cable?
Go by position, not color. With the lenses facing you and the connector at the bottom, pin 1 is on the left: +5V, RXD/SDA, TXD/SCL, GND, the mode-select pin and the data-ready pin. Wire colors vary between cable batches, and the sensor has no reverse-polarity protection, so trace power and ground twice before you connect them.
Can I power the TF-Luna from 3.3 V?
No. The supply range is 3.7 to 5.2 V, and 5 V is the normal choice. Only the signal pins use 3.3 V logic. That means an ESP32, Raspberry Pi or Pico connects to the data pins directly, while a 5 V Arduino must not drive RXD without a voltage divider or level converter.
How do I switch it to I2C?
Connect pin 5 to GND before applying power. Pins 2 and 3 then become SDA and SCL at address 0x10, at up to 400 kbps, and pin 6 becomes a data-ready output. The mode is read only at power-up, and I2C needs firmware newer than V1.0.7. The examples in this manual use the default UART mode.
Why do I get no readings, or only garbage?
The usual cause is crossed data lines: the TF-Luna's TXD (pin 3) must go to your board's receive pin. Then check the 5 V supply and the 115200 baud rate. On a Raspberry Pi the serial hardware must be enabled and the login shell disabled. A Raspberry Pi 5 may also need dtparam=uart0=on in config.txt and may list the port as /dev/ttyAMA0. On ESP32 modules where GPIO 16 and 17 are not free, change the two pin numbers in Serial2.begin.
What does the strength value mean?
It is the amplitude of the returned light. Below 100 the signal is too weak, usually because the target is too far away or too dark. A value of 65535 means the receiver is overexposed. In both cases the distance is unreliable, so the examples print a warning instead of a number.
How accurate is it, and what limits the range?
Accuracy is ±6 cm up to 3 m and ±2% from 3 to 8 m. The 8 m figure applies to a 90% reflective target indoors, and dark surfaces of about 10% reflectivity cut it to roughly 2.5 m. Anything closer than 0.2 m is inside the blind zone. Strong sunlight, glass, mirrors and water also reduce reliability.
Is the laser safe?
Yes. The TF-Luna uses an 850 nm VCSEL rated Class 1, which is eye-safe in normal use. The light is invisible to the eye, so do not expect to see a dot on the target. Keep the two lenses clean, because dust and fingerprints scatter the beam and shorten the usable range.

Related Tutorials

Datasheets & downloads

Reference documents for the TF-Luna 8m LiDAR Distance Sensor. This manual covers wiring and code; the documents below carry the full electrical specifications.