One of the most popular sensors on the market this is the replacement of the Sharp GP2D12. The Sharp GP2Y0A21YK0F infrared (IR) sensor takes a continual distance reading from 10cm to 80cm (4-30") and outputs an analog voltage.
This is a very easy to use sensor. Supply power and the sensor outputs an analog voltage related to the distance. You do not need any extra control algorithms or circuitry. The is a direct ROHS compliant replacement for the previous GP2D12.
We recommend the 3-Pin JST connector to go with this sensor to make hooking it up to your project a snap. The connector on these Sharp sensors is smaller than the normal 2.54mm header spacing expected.
Combining an IRED (infrared diode), an infrared detector and some control circuitry the GP2Y0A21YK0F is able to compensate for changes in reflectivity, ambient light and temperature.
Instead of measuring the intensity of the returned light like simple cheaper IR distance sensors, the Sharp GP2Y0A21YK0F uses triangulation determine the distance which is far less susceptible to outside influences.
Here is a chart of the output voltage as a function of distance
Despite the large difference between the reflectivity of the gray and white paper the sensor is still able to output reliable readings. Note though that the reading at very close distances is the same as very far distances. Don't drive your robot full speed into the wall!