TCRT5000 Reflective Infrared Optical Line & Surface Sensor
Differentiate black tracks from white surfaces and measure close-range reflectance at 950nm for line-following robots.
Master the exact optical sensor powering thousands of autonomous line-following and cliff-detecting robots! Wire the TCRT5000 950nm reflective optocoupler module to Arduino Uno A0 and D2, inspect analog reflectance contrast across matte black vs. bright white surfaces, and build a calibrated line/surface detector.
Key Learning Objectives & Robotics Concepts
By building and programming this project, you will master the following core engineering skills:
Power Architecture & Voltage Staging
5V / 3.3V Regulated PowerThe TCRT5000 breakout draws ~20mA from Arduino Uno 5V to power its built-in 950nm IR emitter LED, matched phototransistor, and LM393 comparator. Optimal focal sweet spot is 3mm–12mm from the target surface; shield module from direct overhead sunlight.
Bill of Materials (BOM) & Hardware Components
| Component | Specifications & Alternative | Qty | Approx Cost |
|---|---|---|---|
| Arduino Uno R3 | ATmega328P @ 16MHz | 1 | $8.00 |
| TCRT5000 Reflective Optical Sensor Module | 950nm emitter + daylight-filtered phototransistor + LM393 | 1 | $1.50 |
| 5mm LED + 220Ω Resistor | Black-line detected indicator | 1 | $0.15 |
| White Paper + Black Electrical Tape Strip | High-contrast test track surface | 1 | $0.20 |
Electrical & System Architecture
Connect TCRT5000 VCC to 5V, GND to GND, AO to A0, and DO to D2. Wire a Black-Line detection indicator LED (+220Ω) to D8.
Autonomous Behavior & Finite State Machine (FSM)
Deterministic Arduino loop handling TCRT5000 Reflective IR Optical Module acquisition, filtering, and real-time output updates.
Step-by-Step Physical Assembly & Wiring Tutorial
Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.
Inspect TCRT5000 Dual-Lens Housing
Observe the blue/clear IR emitter side and black phototransistor side molded inside the TCRT5000 package.
- Verify 4-pin header labels: VCC, GND, DO, AO.
- Prepare a white index card with a 2cm strip of matte black electrical tape across the center.
- Hold the TCRT5000 eyes 6–10mm above the card for maximum focal peak.
Wire TCRT5000 to A0/D2 & Track LED to D8
Connect power, analog/digital signals, and the indicator LED.
- Connect TCRT5000 VCC → 5V, GND → GND, AO → A0, and DO → D2.
- Wire LED (+220Ω) to D8.
- Connect USB power to the Arduino Uno.
Measure White vs. Matte-Black Reflectance Gap
Hold sensor 8mm over white paper vs. black tape and record exact ADC contrast.
- Upload the diagnostic snippet and open Serial Monitor.
- Hold 8mm over white paper → note low ADC (typically 40–150).
- Move 8mm over black tape (or lift into open air) → note high ADC (typically 650–960).
Upload Calibrated Line & Surface Detector
Flash the contrast analyzer and slide the black tape back and forth underneath the optics.
- Set LINE_THRESHOLD halfway between your white and black readings (default 450).
- Upload the production sketch below.
- Confirm D8 LED snaps ON sharply over the black tape and OFF cleanly over white paper.
Test Optimal Mounting Height Curve
Raise the sensor from 2mm to 25mm above white paper to find the crispest contrast height.
- Measure ADC at 3mm, 8mm, 15mm, and 25mm height.
- Verify peak reflectance sits cleanly around 5–10mm.
- Use this exact height measurement whenever mounting TCRT5000 on a robot chassis!
Subsystem Benchtop Verification Scripts
Test each hardware subsystem independently before deploying the full autonomous firmware.
1Bench Diagnostic: TCRT5000 Reflective IR Optical Module Hardware Check
Subsystem DiagnosticMinimal standalone sketch to verify pin wiring and signal response for TCRT5000 Reflective IR Optical Module before running the full project firmware.
// Diagnostic: TCRT5000 White vs Black Reflectance Readout
void setup() { pinMode(2, INPUT); Serial.begin(115200); }
void loop() {
Serial.print("A0 Reflectance: "); Serial.print(analogRead(A0));
Serial.print(" | D2 DO: "); Serial.println(digitalRead(2));
delay(150);
}Complete Production Firmware
Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.
/**
* Project 34: TCRT5000 Reflective IR Line & Surface Analyzer
* Board: Arduino Uno R3 | Pins: A0 (AO), D2 (DO), D8 (Line LED)
*/
const uint8_t TCRT_AO = A0;
const uint8_t TCRT_DO = 2;
const uint8_t LINE_LED = 8;
const int LINE_THRESHOLD = 450; // Midpoint between White (~90) and Black (~820)
int readReflectance() {
long sum = 0;
for (uint8_t i = 0; i < 4; i++) sum += analogRead(TCRT_AO);
return sum / 4;
}
void setup() {
pinMode(TCRT_DO, INPUT);
pinMode(LINE_LED, OUTPUT);
Serial.begin(115200);
Serial.println(F("TCRT5000 Reflective Optical Sensor Ready"));
}
void loop() {
int raw = readReflectance();
bool onBlackOrDrop = (raw >= LINE_THRESHOLD);
int reflectPct = constrain(map(raw, 900, 60, 0, 100), 0, 100);
digitalWrite(LINE_LED, onBlackOrDrop ? HIGH : LOW);
Serial.print(F("Raw ADC: ")); Serial.print(raw);
Serial.print(F(" | Reflectance: ")); Serial.print(reflectPct);
Serial.print(F("% | Surface: "));
Serial.println(onBlackOrDrop ? F("BLACK LINE / EDGE") : F("WHITE SURFACE"));
delay(120);
}Firmware Architecture Explanation:
- Averages 4 fast ADC samples to suppress ambient lighting flicker while staying sub-millisecond responsive.
- Converts raw phototransistor voltage into intuitive 0–100% IR reflectance.
- Detects both dark track lines and sudden table drop-offs cleanly via LINE_THRESHOLD.
Operational Verification & Pin State Matrix
Input Signal vs. System Output Truth Table:
| Input / State | Pin / Signal | Detected Condition | Expected Output |
|---|---|---|---|
| White Surface (8mm) | A0 < 450 | Strong 950nm Return | D8 LED OFF (Surface) |
| Black Tape / Cliff | A0 ≥ 450 | IR Absorbed / Lost | D8 LED ON (Line/Edge) |
Engineering Troubleshooting Matrix
| Problem | Likely Cause | Diagnostic Check | Engineering Solution |
|---|---|---|---|
| Black electrical tape reads almost like white paper | Using shiny black printed paper instead of matte tape, or sensor held >20mm high | Lower sensor to 8mm and test matte black electrical tape | Keep clearance at 5–10mm and use matte black tape. |
| AO stays pinned high (>950) even on white paper | Sensor too far away or IR emitter LED unpowered | View TCRT5000 blue lens through smartphone camera (faint purple glow confirms IR emitter) | Check 5V/GND power and lower sensor to 8mm. |
| DO never toggles while AO changes cleanly | LM393 trimpot dialed to extreme end | Observe onboard DO LED while rotating blue pot | Rotate trimpot until DO toggles cleanly between white and black. |
Engineering Challenges & Upgrades
Take your build to the next level with these progressive engineering upgrades:
Put a white tape stripe on Project 29 DC motor wheel and measure real-time RPM.
Wire two TCRT5000 modules (A0 & A1) to output STEER LEFT / STRAIGHT / STEER RIGHT commands.
Sweep over white and black for 3 seconds at boot to auto-compute optimal LINE_THRESHOLD.