The Sharp IS471F is an infrared (940nm) light sensor with a built-in pulsed LED driver circuit. The sensor is impervious to external disturbing lights, because the sensor synchronizes its detection with this pulsed signal. In other words, the sensor circuit is only sensitive to signals with the same frequency as the driver circuit.
This makes the sensor very suitable for detecting objects. If the sensor and its LED are mounted opposite each other, than the sensor can detect if the light beam is interrupted. A distance of more than 15cm can be reached. Although this is depending on the actual light circumstances. This may sound strange, because the circuit is not sensitive to environmental light. But the internal photo transistor can still be ‘blinded’ for example by the light of the sun and become (temporarily) less sensitive.
Of course the sensor and the LED can also be mounted next to each other, but make sure that the sensor does not detect the LED light directly as it is very sensitive.
Because of the light pulses it is recommended to use a 330 nF, or larger, capacitor across the power supply, check the datasheet.
We have made a booster circuit to extend the sensor range, take a look at this tutorial.