How to Use TCRT5000 Infrared Line Tracking Sensor with Arduino
How to Use TCRT5000 Infrared Line Tracking Sensor with Arduino
The TCRT5000 is an infrared reflective sensor that detects surfaces by measuring light reflection. White surfaces reflect IR light back to the receiver, outputting a digital HIGH (1), while black surfaces absorb the light, outputting LOW (0). This behavior makes it ideal for line-following robots and basic object detection projects.
Required Components
- Arduino UNO R3 with USB cable
- TCRT5000 Infrared Line Tracking Sensor Module
- MB-102 Breadboard (830 points)
- Male-to-male jumper wires, 20 cm (5 pieces)
- White paper and black electrical tape (for testing)
- Optional: Red 5mm LED with 220Ω resistor for status indicator
Wiring Diagram
Connect the TCRT5000 module to your Arduino UNO as follows
| Arduino | TCRT5000 Module |
|---|---|
| 5V | VCC (positive) |
| GND | GND (negative) |
| Pin 2 | OUT (signal) |
If you want a visible LED indicator, connect an LED in series with a 220Ω resistor between Pin 13 and GND.
Arduino Code Example
Open Arduino IDE, paste the code below, select Board as Arduino UNO, and upload.
// TCRT5000 Digital Output Reading
// Connect OUT pin to Arduino Pin 2
const int sensorPin = 2; // Signal pin from TCRT5000 OUT
const int ledPin = 13; // Built-in LED on Pin 13
void setup() {
Serial.begin(9600);
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.println("TCRT5000 Line Tracking Test");
Serial.println("===========================");
}
void loop() {
int sensorValue = digitalRead(sensorPin);
// Display value on Serial Monitor
Serial.print("Digital Output: ");
Serial.println(sensorValue);
// White surface -> value = 1
// Black line -> value = 0
if (sensorValue == 1) {
Serial.println(">> White surface detected");
digitalWrite(ledPin, HIGH);
} else {
Serial.println(">> Black line detected");
digitalWrite(ledPin, LOW);
}
delay(500);
}
Testing Procedure
- Open Serial Monitor (Tools > Serial Monitor)
- Set Baud Rate to 9600
- Hold the sensor above white paper with the sensing face pointing down
- Observe the output shows 1 with message “White surface detected”
- Slide the sensor over black electrical tape, the value changes to 0 showing “Black line detected”
- Slide back to white paper, the value returns to 1
Testing Object Detection
The TCRT5000 can also detect objects using the same reflective principle
- Hold the sensor above a desk surface until Serial Monitor shows 1
- Bring an object close to the sensor, the output changes to 0 when the object blocks the reflected IR
- Remove the object, the value returns to 1
The principle is straightforward: when an object blocks the IR light that would normally reflect from a surface, the phototransistor stops receiving a signal and the output changes.
Adjusting Sensitivity
The potentiometer on the TCRT5000 module adjusts detection sensitivity
- Turn left: Decrease sensitivity (object must be closer)
- Turn right: Increase sensitivity (detects from farther away)
Note: In environments with fluorescent lighting or sunlight, high sensitivity may cause false triggers. Adjust the potentiometer until the sensor responds reliably without interference.
Summary
The TCRT5000 module is a practical choice for beginner projects involving line detection or object proximity sensing. The wiring is straightforward, the output is digital and clean, and it works well with Arduino without needing extra libraries. You can apply this directly to line-following robots, conveyor belt monitoring, or simple automation systems.
Reference Video
อยากทำโปรเจคแบบนี้?
รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน
If you need Arduino project service or urgent IoT development, see full service details on the home page
จ้างทำโปรเจคเลย