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
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.
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 |
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 |
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 |
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 |
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 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
#!/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 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)



