Sensing Proximity

Sensing proximity or distance can be done easily using a variety of different sensors. Most of them output an analog voltage depending on the sensed distance, so they are very easy to incorporate into any project.

Choosing a sensor
For sensing very short (under 1cm), the Optical Detector / Phototransistor can be used.

For measurements up to a foot, an infrared proximity sensor such as the Infrared Proximity Sensor - Sharp GP2Y0A21YK is a good bet.

Over a foot, and under a few meters, an ultrasonic range sensor may be the best bet.