Applying micro controllers to the real world often involves sensing motion, position or the proximity of objects. A very simple sensor is the optical switch consisting of an IR LED emitter and an IR-sensitive phototransistor. These can be arranged to detect directly transmitted light (photo interrupter) or the reflection of light (proximity detector) and they can be packaged into a self-contained sensor or used as separate emitter / receivers. The photo below shows an interrupter type and a proximity detector type that may be purchased for less than a buck a piece.
Via and Source: Digital DIY