The TCRT5000 shines infrared at the surface below it and measures how much comes back: white reflects, black absorbs. That is all a line-following robot needs. On the Raspberry Pi Pico, DO goes to GP15 and AO to GP26 (ADC0).
Power the module from 3V3. The script prints whether it sees the line, with a bar graph of the analog level, and lights the Pico’s GP25 LED over the line.
Wiring
| Raspberry Pi Pico | TCRT5000 IR reflective sensor module | Wire | Notes |
|---|---|---|---|
| 3V3 | VCC | red | 3V3 is pin 36. DO and AO then stay within the Pico’s 3.3 V range. |
| GND | GND | black | |
| GP15 | DO | yellow | Physical pin 20. |
| GP26 | AO | green | GP26 = ADC0, physical pin 31. |
3.3–5 V part, 3.3 V board. Outputs swing to VCC. Power it from 3.3 V on ESP32/Pico, 5 V on Uno.
Board quirks
- Hold the sensor 2–10 mm above the surface. Black electrical tape on white chart paper is the classic test track.
- Turn the blue pot until DO flips exactly at the line edge. AO shows the raw reflectance, useful for setting the threshold or for smoother “how far off the line” steering.
- A line-follower robot needs two to five of these. The Pico has three ADC pins (GP26–GP28), so use DO for most sensors and AO only where you want proportional steering.
- Sunlight contains plenty of IR and can blind the sensor — test indoors.
Code
# TCRT5000 reflective IR sensor (line follower) on a Raspberry Pi Pico (MicroPython).
# Wiring: VCC -> 3V3 (pin 36), GND -> GND, DO -> GP15 (pin 20), AO -> GP26 / ADC0 (pin 31).
# DO is HIGH over a black line (little IR reflected) on most modules - check yours.
from machine import Pin, ADC
import time
do = Pin(15, Pin.IN)
ao = ADC(26)
led = Pin(25, Pin.OUT) # plain Pico LED
print("TCRT5000: move it over black tape on white paper, 2-10 mm above")
while True:
on_line = do.value() == 1
level = ao.read_u16()
led.value(on_line)
bar = "#" * (level * 30 // 65535)
print("{:5s} AO {:5d} {}".format("LINE" if on_line else "white", level, bar))
time.sleep_ms(100)# TCRT5000 reflective IR sensor (line follower) on a Raspberry Pi Pico (MicroPython).
# Wiring: VCC -> 3V3 (pin 36), GND -> GND, DO -> GP15 (pin 20), AO -> GP26 / ADC0 (pin 31).
# DO is HIGH over a black line (little IR reflected) on most modules - check yours.
from machine import Pin, ADC
import time
do = Pin(15, Pin.IN)
ao = ADC(26)
led = Pin(25, Pin.OUT) # plain Pico LED
print("TCRT5000: move it over black tape on white paper, 2-10 mm above")
while True:
on_line = do.value() == 1
level = ao.read_u16()
led.value(on_line)
bar = "#" * (level * 30 // 65535)
print("{:5s} AO {:5d} {}".format("LINE" if on_line else "white", level, bar))
time.sleep_ms(100)Expected serial output
TCRT5000: move it over black tape on white paper, 2-10 mm above
white AO 8214 ###
LINE AO 51876 #######################TCRT5000: move it over black tape on white paper, 2-10 mm above white AO 8214 ### LINE AO 51876 #######################
Common errors
DO never changes
Too high above the surface, or the pot is at one end. Bring it to about 5 mm and turn the pot slowly.
LINE and white are reversed
Some modules invert DO. Change do.value() == 1 to == 0.