MyRoboPathOpen Robotics Lab
Arduino Uno #34 of 35
Est. 0.5 Hours
Budget: $2 - $4
Beginner

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.

Arduino Uno R3TCRT5000 Optical IR950nm PhototransistorLine TrackingContrast Calibration
TCRT5000 Reflective Infrared Optical Line & Surface Sensor Blueprint
TCRT5000 Reflective Infrared Optical Line & Surface SensorCAD Blueprint

Key Learning Objectives & Robotics Concepts

By building and programming this project, you will master the following core engineering skills:

1Understand why TCRT5000's built-in daylight blocking filter isolates 950nm reflections cleanly.
2Measure optical reflectance contrast (White ~50–150 ADC vs Matte Black ~600–950 ADC) at 5–10mm clearance.
3Set an automatic midpoint threshold halfway between calibrated white and black surfaces.
4See how two or five TCRT5000 modules form a PID line-following robot array or optical wheel encoder.

Power Architecture & Voltage Staging

5V / 3.3V Regulated Power

The 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.

TCRT5000 Reflective Infrared Optical Line & Surface Sensor Power Architecture Schematic
Figure: Regulated Arduino Uno supply rails, current budget, and component protection.Power Schematic

Bill of Materials (BOM) & Hardware Components

Bill of Materials for TCRT5000 Reflective Infrared Optical Line & Surface Sensor
ComponentSpecifications & AlternativeQtyApprox Cost
Arduino Uno R3ATmega328P @ 16MHz1$8.00
TCRT5000 Reflective Optical Sensor Module950nm emitter + daylight-filtered phototransistor + LM3931$1.50
5mm LED + 220Ω ResistorBlack-line detected indicator1$0.15
White Paper + Black Electrical Tape StripHigh-contrast test track surface1$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.

Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for TCRT5000 Reflective Infrared Optical Line & Surface Sensor.
Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for TCRT5000 Reflective Infrared Optical Line & Surface Sensor.Wiring Schematic

Autonomous Behavior & Finite State Machine (FSM)

Deterministic Arduino loop handling TCRT5000 Reflective IR Optical Module acquisition, filtering, and real-time output updates.

Figure: Firmware execution flow and state transitions for TCRT5000 Reflective Infrared Optical Line & Surface Sensor.
Figure: Firmware execution flow and state transitions for TCRT5000 Reflective Infrared Optical Line & Surface Sensor.Control Algorithm

Step-by-Step Physical Assembly & Wiring Tutorial

Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.

1

Inspect TCRT5000 Dual-Lens Housing

Duration: 5 Mins

Observe the blue/clear IR emitter side and black phototransistor side molded inside the TCRT5000 package.

TCRT5000 Reflective Infrared Optical Line & Surface Sensor hardware layout diagram
Stage 1: TCRT5000 Reflective IR Optical Module hardware inspection & pinout overview.Stage 1 Diagram
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: Glossy black ink sometimes reflects 950nm IR like silver—matte black electrical tape is the gold standard for robotics tracks!
2

Wire TCRT5000 to A0/D2 & Track LED to D8

Duration: 5 Mins

Connect power, analog/digital signals, and the indicator LED.

TCRT5000 Reflective Infrared Optical Line & Surface Sensor breadboard wiring check diagram
Stage 2: Breadboard layout & Arduino Uno pin-to-pin wiring audit.Stage 2 Diagram
Step Action Checklist:
  • Connect TCRT5000 VCC → 5V, GND → GND, AO → A0, and DO → D2.
  • Wire LED (+220Ω) to D8.
  • Connect USB power to the Arduino Uno.
Engineering & Tuning Tip: Using AO lets your robot compute proportional line error, while DO gives instant crisp binary triggers.
3

Measure White vs. Matte-Black Reflectance Gap

Duration: 5 Mins

Hold sensor 8mm over white paper vs. black tape and record exact ADC contrast.

TCRT5000 Reflective Infrared Optical Line & Surface Sensor power rail protection diagram
Stage 3: Supply rail check (USB 5.0V Regulated Rail (≈20mA IR LED)) and circuit protection verification.Stage 3 Diagram
Step Action Checklist:
  • 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).
Engineering & Tuning Tip: Notice that open air (a table cliff!) produces the exact same high ADC as black tape—that's how cliff-avoiding rovers work!
4

Upload Calibrated Line & Surface Detector

Duration: 10 Mins

Flash the contrast analyzer and slide the black tape back and forth underneath the optics.

TCRT5000 Reflective Infrared Optical Line & Surface Sensor serial telemetry verification diagram
Stage 4: Firmware upload & 115200 baud Serial Monitor verification.Stage 4 Diagram
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: Dial the blue trimpot on the module so its onboard DO LED matches your software threshold.
5

Test Optimal Mounting Height Curve

Duration: 5 Mins

Raise the sensor from 2mm to 25mm above white paper to find the crispest contrast height.

TCRT5000 Reflective Infrared Optical Line & Surface Sensor live operational logic diagram
Stage 5: Live operational logic flow & calibration verification.Stage 5 Diagram
Step Action Checklist:
  • 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!
Engineering & Tuning Tip: Paint a white stripe on a black spinning motor wheel and point TCRT5000 at it to build a contactless optical tachometer!

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 Diagnostic

Minimal standalone sketch to verify pin wiring and signal response for TCRT5000 Reflective IR Optical Module before running the full project firmware.

Arduino IDE Diagnostic ScriptC++ / Arduino
// 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);
}
Expected Output: Low ADC (~80) over white paper; high ADC (~820) over matte black tape or open air.

Complete Production Firmware

Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.

arduino_uno_tcrt5000_reflective_ir_sensor.ino
arduino_uno_tcrt5000_reflective_ir_sensor.inoArduino C++
/**
 * 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

1Double-check all 4 Arduino Uno pin connections against the wiring schematic before plugging in USB.
2Upload the Bench Diagnostic sketch first and confirm Serial Monitor at 115200 baud matches: Low ADC (~80) over white paper; high ADC (~820) over matte black tape or open air.
3Upload the complete production sketch and verify every condition in the operational truth table below.

Input Signal vs. System Output Truth Table:

Operational truth table for TCRT5000 Reflective Infrared Optical Line & Surface Sensor
Input / StatePin / SignalDetected ConditionExpected Output
White Surface (8mm)A0 < 450Strong 950nm ReturnD8 LED OFF (Surface)
Black Tape / CliffA0 ≥ 450IR Absorbed / LostD8 LED ON (Line/Edge)

Engineering Troubleshooting Matrix

Engineering troubleshooting matrix for TCRT5000 Reflective Infrared Optical Line & Surface Sensor
ProblemLikely CauseDiagnostic CheckEngineering Solution
Black electrical tape reads almost like white paperUsing shiny black printed paper instead of matte tape, or sensor held >20mm highLower sensor to 8mm and test matte black electrical tapeKeep clearance at 5–10mm and use matte black tape.
AO stays pinned high (>950) even on white paperSensor too far away or IR emitter LED unpoweredView 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 cleanlyLM393 trimpot dialed to extreme endObserve onboard DO LED while rotating blue potRotate trimpot until DO toggles cleanly between white and black.

Engineering Challenges & Upgrades

Take your build to the next level with these progressive engineering upgrades:

Level 1Optical Wheel RPM Tachometer

Put a white tape stripe on Project 29 DC motor wheel and measure real-time RPM.

Level 2Dual-Sensor Line Follower Logic

Wire two TCRT5000 modules (A0 & A1) to output STEER LEFT / STRAIGHT / STEER RIGHT commands.

Level 3Auto-Calibrating Contrast Finder

Sweep over white and black for 3 seconds at boot to auto-compute optimal LINE_THRESHOLD.