Robots running on wheels need to know how long they did run. For this purpose wheels are equipped by encoders - sensors which register rotation angle changes.
Usually robot's wheels are rotated by a motor via some gear - a set of gear wheels decreasing rotation speed of motor in many times. The gear wheel rotating robot's wheel has already several times more rotation speed the wheel. The next gear wheel rotating this gear wheel has even more speed and so on. If drill holes in one of these gear wheels and situate optical sensors there - it's possible to register rotation angle changes with fine precision.
LED and optical receiver are taken from an old mouse with a ball inside instead of optical sensor. Actually optical receiver is a photo-transistor or a photo-diode which has resistance about hundreds Ohms and noticeable less when LED lights on it.
Step 1: Drill Holes in the Gear Wheel
Drill holes in the gear wheel. It may be 4, 6 or 8 depending of size of a gear wheel. Important to make them in equal distances between each other.
Step 2: Soldering LED and an Optical Receiver
Solder to wires LED (1) with its lens (2) against optical receiver (3). Light proof cover (5) with a window defends receiver from surrounding light.
This receiver has one pin (4) left free because it has one more receiver inside - it may be used to define the rotation direction. Not used this time.
Step 3: Attach LED and Receiver
Attach LED and receiver against each other in the way holes in the gear wheel let LED light to the receiver through holes and be interrupted when the gear wheel gets turned.
Step 4: Glue Attached LED and Receiver
Glue attached LED and receiver by thermal glue
Step 5: Another Design
Same construction with connector for encoder and motor