The Pololu QTR-3RC 3 Channel Digital IR Reflectance Sensor makes it easy to track lines using a few GPIOs.
This sensor has three IR infrared reflectance sensors that are wired to produce digital pulses corresponding to the levels reflected light. White surfaces will reflect a lot of light whereas dark surfaces will not. This sensor is ideal for detecting black lines on a white surface and works particularly well with lines made from standard electrical tape. It can also be used for edge detection and similar purposes.
Unlike similar sensors that output analog voltages levels, this sensor is specifically designed to output digital signals. It works by measuring the time it takes for an RC Resistor-Capacitor circuit to discharge. It's a neat trick for reading analog values with plain digital GPIOs and saves your robot's valuable analog inputs for other purposes.
Attach a 5V power supply to the voltage input (VCC) and common ground (GND) pins. Attach three digital GPIOs to the three output (OUT1/OUT2/OUT3) pins. Charge the three RC circuits by setting each digital GPIO to output a HIGH voltage for several microseconds. Then quickly switch your GPIOs to input mode and measure the time it takes for the pins to transition from HIGH to LOW. It will take longer when there is less reflection. You may perform these operations in parallel to speed up the process.
Library functions are available to make it easier to use this sensor with Pololu Orangutan Robot Controllers and Arduino compatible microcontrollers.
This line sensor module comes with a set of optional header pins that require soldering.