The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats or dolphins do. It offers excellent range accuracy and stable readings in an easy-to-use package. It operation is not affected by sunlight or black material like Sharp rangefinders are (although acoustically soft materials like cloth can be difficult to detect). Similar in performance to the SRF005 but with the low-price of a Sharp infrared sensor.
This posts details the process of building a line following robot. The robot can follow both black and white lines. It uses a sensor array to sense the line and a PID control to follow the line. With the help of a PID control the robot does not follow the line by oscillating to the left and to the right like conventional line followers but follows the line smoothly without wavering too much the left and right, conserving battery power while at the same time following the line much more faster.