The Sharp GP2Y0A21YK is a low cost ($13.95) infrared proximity sensor with an analog output that varies from 3.1V at 10cm to 0.4V at 80cm. It has a JST (Japanese Solderless Terminal) connector and needs either a pigtail jumper wire or direct soldering to the back of the module in order to be hooked up to an Arduino.
The sensor emits a beam of IR light from an internal LED, and then uses a phototransistor to measure the intensity of the light that is bounced back. There are two variations of this sensor: GP2Y0A21YK and GP2Y0D21YK, providing analog and digital outputs respectively. Because the sensor measures the intensity of its reflected light, there is always a small delay between the actual measurement and the response (~39ms). As seen from the timing chart , the GP2Y0D21YK is a little bit slower than the GP2Y0A21YK:
Hooking up the GP2Y0A21YK is very easy; it is exactly the same procedure that we followed using the potentiometer during the last lab: the black wire goes to the ground, the red one goes to the 5V power, and the yellow one goes to the analog input.
There is a free library here, written specifically for the GP2Y0A21YK in order to facilitate the usage of the sensor. Despite a couple of drawbacks, such as nonlinear output, conflicts with the other IR devices (such as a remote control pointed directly into the sensor) and irrelevant data readings within the close proximity to the sensor, the Sharp GP2Y0A21YK is very widely used in many different applications, from TVs to complex robotics.
Available from these sellers: