Index
Introduction
The TCRT5000 Infrared Line Tracking Sensor is a reflective optical sensor used for line-following and object detection applications. It contains an infrared emitter and receiver. The sensor detects the amount of reflected infrared light from a surface and provides a digital output signal. The ESP32 can read this signal and determine whether a dark or light surface is present. In this tutorial, we’ll interface a TCRT5000 Sensor with the ESP32 and monitor detection status through the Serial Monitor.
Required Components
- ESP32 Board
- TCRT5000 Infrared Line Tracking Sensor Module
- Jumper Wires
- Breadboard
Pinout

Circuit Diagram / Wiring

- TCRT5000 VCC → 3.3V (ESP32)
- TCRT5000 GND → GND (ESP32)
- TCRT5000 OUT → GPIO 15 (ESP32)
Code / Programming
/*
Filename: ol_tcrt5000_sensor.ino
Description: Reads TCRT5000 sensor status and prints detection result via Serial Monitor
Author: www.oceanlabz.in
Modification: 1/4/2025
*/
#define TCRT5000_PIN 15
void setup() {
Serial.begin(115200);
pinMode(TCRT5000_PIN, INPUT);
}
void loop() {
int sensorState = digitalRead(TCRT5000_PIN);
if (sensorState == LOW) {
Serial.println("Line Detected");
} else {
Serial.println("No Line Detected");
}
delay(500);
}
Explanation
- The TCRT5000_PIN reads the digital output from the TCRT5000 sensor.
- The sensor emits infrared light and measures the reflected signal from nearby surfaces.
- Dark surfaces reflect less infrared light, while light surfaces reflect more.
- The ESP32 continuously monitors the sensor output and determines whether a line or object is detected.
- The detection status is displayed on the Serial Monitor.
Troubleshooting
- Ensure that the sensor is powered correctly (VCC to 3.3V and GND to GND) and that the output pin is connected to GPIO 15.
- Adjust the onboard potentiometer to set the desired detection sensitivity.
- If the sensor does not detect lines correctly, verify the distance between the sensor and the surface.
- If the readings are unstable, check the wiring connections and ensure a stable power supply.
- If no messages appear in the Serial Monitor, verify that the correct COM port and ESP32 board are selected in the Arduino IDE.

