Line sensor, TCRT5000
An infrared LED and eye side by side. Low over white, high over the black line.
- 4 pins
- 1 setting
- In 3 projects
The Line sensor, TCRT5000 in brief
What it is, and every setting the properties panel gives it.
The TCRT5000 is Vishay’s reflective sensor, an infrared LED and a phototransistor side by side in one black block, and its blue LM393 board is the eye of most line-following robots. The pins are VCC, GND, DO and AO, at 3.3 to 5 volts. On an Uno, VCC goes to 5 V, DO to a digital pin and AO to an analog pin if you want the level; on an ESP32, power it from 3.3 V so DO’s pull-up stays at 3.3 V. The phototransistor sits under a 10 k pull-up, so reflection pulls AO down, and DO goes low over white and stays high over the black line. Mokxi models the datasheet’s distance hump as 2x / (1 + x^2) with x = d / 2.5 mm, peaking at 0.58 mA at the board’s LED current, with white reflecting 90 percent and black 5; the slider runs from 0.2 to 40 mm, and a swatch swaps white paper for black tape. By about 15 mm white reads like black. The classic mistakes are the line backwards, since low is white, and mounting it too high. Ambient sunlight, gray or glossy surfaces and part-to-part spread are not modeled.
- Family
- Sensors
- Pins
- 4
- threshold
- 0.5
4 pins
Named as the editor names them, so a wire lands where you expect it.
How to use the TCRT5000 line sensor with an Arduino
Wire VCC to 5 V, GND to GND and DO to a digital pin; in the kit circuit here DO goes to pin 3 and the sketch prints digitalRead(3) four times a second. Drag its slider to raise or lower the surface, and click the swatch beside it to swap white paper for black tape.
Low is white and high is the black line. White reflects the infrared back, the phototransistor pulls AO down past the trimmer and DO goes low with its lamp lit; black swallows it and DO stays high. A line follower that steers the wrong way usually has this backwards.
Height matters as much as color. The response peaks at about 2.5 mm, and by about 15 mm white reads like black, so a robot’s sensors ride a few millimeters off the floor.
The board runs from 3.3 V, so on an ESP32 power it from 3.3 V and DO’s 10 k pull-up stays at the ESP32’s own logic level.
void setup() {
pinMode(3, INPUT);
Serial.begin(9600);
}
void loop() {
Serial.println(digitalRead(3)); // 0 white, 1 black
delay(250);
}What is true about the Line sensor, TCRT5000, here
In its help article’s own words: what the simulation gets right, and where it stops.
Modeled
The distance curve. The datasheet draws the collector current against distance as one hump: nothing at contact, the most at 2.5 mm (the "peak operating distance"), and falling away to about a fifth of the peak by 15 mm. The model's hump peaks in the same place and falls at the same order of rate. The sheet's 1 mA at the peak is with the LED at 60 mA; the board's 100 ohm resistor runs it at about 35 mA, so the peak here is 0.58 mA.
The surface. White reflects 90% and black 5%. Over white at a couple of
millimeters the transistor saturates and DO is low; over black it barely conducts
and DO is high. Lift it and white fades until, at about a centimeter and a half, it
reads like black. That is why a line follower's sensors ride a few millimeters off the
floor.
Not modeled
Ambient light. A real one outdoors sees plenty of infrared in the sunlight and reads nonsense; here the room is dark in the infrared. Surfaces that are neither white nor black, glossy surfaces that mirror the LED away, and the sheet's two-to-one spread between parts are not modeled. The comparator has no hysteresis, as on the real board.
From TCRT5000 line sensor, in full.
See the Line sensor, TCRT5000 in a project
3 built-in projects use it. Each opens in the editor, already wired.
The boards it is shown on
This board has a built-in project with the Line sensor, TCRT5000 in it.
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the Line sensor, TCRT5000
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.