The Sharp line of analog infrared rangefinders are back, and with their usual high-level of noise and color immunity. These are great distance sensors that should be near the top of anybody's list for simple & effective obstacle detection!
The Sharp GP2Y0A02YK0F is an excellent IR rangefinding device in a small package.
If you are familiar with the GP2D12 version, this one is has a better range. Rather than 10-80cm (3.9"-31.5") of the GP2D12, this one is officially spec'd to run 20-150cm (7.9"-59"). Our own tests show that the GP2D12 started giving us usable results at 9cm (3.54"), and the GP2Y0A02YK0F started at 15cm (5.9") . The analog output range started a bit higher (2.56V vs 2.85V) and was offset a bit from the GP2D12 curve, so some adjustments will have to be made to designs replacing GP2D12 with the GP2Y0A02YK0F.
The GP2Y0A02YK0F sensor is an analog sensor, so, to use it with a microcontroller, you must have an available Analog-to-Digital Converter channel or use an external A/D converter. Using a comparator chip to use this sensor as a threshold detector (yes-I-see-something vs. no-nothing-there).
The GP2Y0A21 uses a 3-pin JST connector that works with the 3-pin JST cables for Sharp distance sensors (not included). It is also simple to solder three wires to the sensor where the connector pins are mounted. When looking at the back, the three connections from left to right are power, ground, and the output signal. Or you can use Sharp Sensor Cable if that suits your project better.
Please note: The sensor does NOT come with the cable.
Please see the documentation for the AIRRS sensor for general principles of usage and operation.