An optical encoder is an electro-mechanical motion sensor and feedback device consisting of an LED light source, a photodetector, and a disc with slot-like apertures.
A light pulse is created when an opening in the rotating disc allows light from the LED to pass through and strike a paired photodetector. The photodetector is typically an array of photodiodes arranged so they provide two signals which are out of phase by 90 electrical degrees.
The light pulses alternate between on/off as the disc turns with the rotation of the shaft, alternately blocking or allowing light to pass through. The photosensor is connected to an electronic circuit which translates the light pulses into an digital square waveforms (high and low signals).