There is a type of detector known as a “slotted switch” that consists of a phototransistor/LED pair mounted on a solid frame with a small air gap between the two elements. A typical circuit might be:
o +5v o +5v | | | | \ \ 220 ohms / / 4.7K \ \ / / | | | +-------> Vout _|_ / \ / |/ ----- |\ NPN | \ | | | | | | GND GND | air gap |
When the air gap is unobstructed, the transistor saturates, pulling Vout to ground; when the gap is blocked, the transistor cuts off and Vout is +5 volts.
- Paul Hitchcock