Rotation, and Linear Motion Sensor
Plug this sensor to the RCX and set it on light sensor or rotation sensor. If it is on light sensor the value will hover around 15 to 30 and drop to 0 if there is something in the sensor. If it is on rotation it will normally read 0 and -1 if something is in the sensor. Here are some uses:
Rotation Sensor: The slot is wide enough to accommodate various Lego parts. In particular, a 0.95 inch wheel/pulley with six holes in it can be mounted so that it breaks the infrared beam six times in each rotation. The direction of rotation cannot be determined by monitoring the signal from the phototransistor, but this is not important if a motor is driving the wheel, as the direction of rotation of the motor will be known.
Linear Motion Sensor: A similar scheme can be used to monitor the position of a sliding component, e.g. a round ended strip with holes in it, if the it is mounted so that the holes slide in the slot in the sensor. Alternatively, a sliding component can be driven by a rack and pinion system with the rotation of the pinion shaft being monitored as in the rotation sensor example above.
The opto-interrupter was found in an old floppy drive, but they can also be found in printers and many other devices with moving parts. You could even make your own. They contain an infrared LED on one side and a phototransistor on the other. Inserting something into the sensor will block the beam to the phototransistor.
*Most information was taken form http://www.umbra.demon.co.uk/sensor1.html