One Possible Line Follower Sensor

Print Friendly, PDF & Email

To follow a line, a robot needs a sensor that can tell whether it is positioned over a white background or a black line. In fact, a robot likely needs an array of these to tell for certain whether the line is to the left or right of the correct position. One of the better of the many devices available for this is a Reflective Optical Sensor made by Vishay Semiconductor, the TCRT5000L.

This little sensor consists of an infrared LED (peak light output at a wavelength of 940nm) and a phototransistor in a black molded housing with a barrier to prevent crosstalk. Light from the LED bounces off of a surface and reflects back into the phototransistor causing current to flow that depends on the light intensity.

The sensor is about 10mm long by 6mm wide by 7mm high and is designed to ride about 2.5mm above the surface whose reflectance is being measured. This size and spacing is perfect for determining the location of a black line on a white floor.

These components can be purchased from Amazon or others for less than a dollar each. They are also available on a small PC board with circuitry to provide a digital output with an adjustable threshold. The LM393 comparator output switches from high to low if the + input is a lesser voltage than the – input. So for applications where a digital signal works better, this little circuit can help.

The cost jumps up to about $6-7 however, so it is cheaper to use just the TCRT5000 and a pair of resistors. Taking just that portion of the above schematic, we connect a 180Ω resistor from Vcc to the LED anode, 10KΩ to the phototransistor collector, connect the LED cathode and phototransistor emitter to ground, and a 0.1 μF capacitor from collector to ground.  Then, we can connect the collector voltage to an analog input pin on our Arduino board and use software to determine whether the sensor is looking at background or black line based on the measured voltage.

Here is a simple demonstration program to show how this can be done:

// Read light level from infrared reflectance sensor
// on pin A0 and send the result to the Serial Monitor.

const int lightPin = A0;
int lightlevel;
void setup()
 pinMode(lightPin, INPUT);

void loop()
 lightlevel = analogRead(lightPin);
 if (lightlevel < 200) Serial.println(": white");
 else Serial.println(": black");

When the sensor is positioned about 2.5mm (0.1 inches) above a white surface, a typical reading is about 30. When over a strip of black electrical tape, the reading rises to about 600. The scale for an Arduino analog input reading is from 0 to 1023, so when the sensor sees white, the reading is nearly zero. When the sensor sees black, the reading rises to over half of the maximum. Putting in an if statement with a threshold of somewhere around 200 lets our program reliably distinguish between tape and background. This is really no more difficult than using a digital pin and saves quite a bit of cost.