TCRT5000 Infrared Line Tracking Sensor Tutorial: Reflective IR Sensing, Threshold Tuning, and Arduino Examples
This tutorial is a comprehensive, practical guide to the TCRT5000 Infrared Line Tracking & Tracing Sensor Module (Leobot Product #251). It explains how reflective infrared sensing works, how this specific module is built, how to tune the detection threshold correctly, and how to use it reliably with Arduino for line-following, edge detection, and contrast-based surface sensing.
1) What the TCRT5000 sensor does
The TCRT5000 is a reflective infrared optical sensor. It emits infrared light downward and measures how much light is reflected back from a nearby surface.
- Light surfaces reflect more IR
- Dark surfaces absorb more IR
- The sensor converts this difference into an electrical signal
This contrast-based detection makes the module ideal for:
- Line-following robots (black line on white surface)
- Edge or cliff detection
- Short-range object presence detection
2) Reflective IR sensing principle
The sensor contains:
- An IR LED emitter (usually ~940 nm)
- A phototransistor receiver
When the IR LED emits light:
- White/light surfaces reflect IR strongly
- Black/dark surfaces reflect IR weakly
3) Module overview and internal circuitry
The TCRT5000 module typically includes:
- TCRT5000 reflective IR sensor
- Current-limiting resistor for IR LED
- LM393 comparator (on digital-output variants)
- Potentiometer for threshold adjustment
- Indicator LED
4) Pinout and electrical characteristics
| Pin | Label | Description |
|---|---|---|
| 1 | VCC | Supply voltage (3.3V β 5V) |
| 2 | GND | Ground |
| 3 | DO | Digital output (threshold-based) |
| 4 | AO | Analog output (reflectivity level) |
- Logic compatible with 3.3V and 5V MCUs
- DO typically goes LOW when reflection is high (line detected)
5) Analog vs digital output behavior
Analog Output (AO):
- Voltage proportional to reflected IR
- Higher value = more reflection
- Used for fine-grained control and calibration
Digital Output (DO):
- Comparator-based ON/OFF signal
- Threshold set by onboard potentiometer
- Ideal for simple line detection
6) Detection distance and surface effects
- Typical working distance: ~2 mm β 15 mm
- Best contrast at 5β10 mm
- Surface texture and gloss strongly affect readings
7) Wiring to Arduino
TCRT5000 VCC ? Arduino 5V
TCRT5000 GND ? Arduino GND
TCRT5000 AO ? Arduino A0
TCRT5000 DO ? Arduino D2
8) Arduino Example 1: Analog reflectivity reading
/*
TCRT5000 Analog Read
Product #251
*/
const int IR_AO = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int value = analogRead(IR_AO); // 0β1023
Serial.print("Reflectivity: ");
Serial.println(value);
delay(200);
}
9) Arduino Example 2: Digital line detection
/*
TCRT5000 Digital Detection
*/
const int IR_DO = 2;
void setup() {
pinMode(IR_DO, INPUT);
Serial.begin(9600);
}
void loop() {
if (digitalRead(IR_DO) == LOW) {
Serial.println("Line detected");
} else {
Serial.println("No line");
}
delay(200);
}
10) Arduino Example 3: Simple line-following logic
/*
Simple Line Logic (single sensor)
*/
const int IR_DO = 2;
void setup() {
pinMode(IR_DO, INPUT);
}
void loop() {
bool onLine = (digitalRead(IR_DO) == LOW);
if (onLine) {
// move forward
} else {
// adjust direction
}
}
11) Threshold adjustment and calibration
- Place sensor over target surface
- Turn potentiometer until LED switches cleanly
- Calibrate under actual lighting conditions
- Re-calibrate if sensor height changes
12) Mechanical placement guidelines
- Mount perpendicular to surface
- Avoid IR LED shadowing the receiver
- Shield from strong sunlight if possible
- Use rigid mounting to avoid vibration
13) Troubleshooting
Always detecting line
- Threshold set too low
- Sensor too close to surface
- Highly reflective background
Never detecting line
- Threshold set too high
- Sensor too far from surface
- Insufficient contrast
14) Quick checklist
TCRT5000 Line Tracking Sensor (#251) Checklist
---------------------------------------------
? Power with 3.3V or 5V
? Maintain consistent sensor height (5β10 mm ideal)
? Use AO for calibration, DO for simple logic
? Adjust threshold under real lighting
? Expect reflectivity, not color detection
? Shield from sunlight for outdoor use
? Rigidly mount sensor to avoid vibration