The output of an optical rotary encoder can be read using an interrupt on a digital input pin of the Arduino. When the encoder wheel has a slot that passes over the encoder head, the digital input pin will go from a low state to a high state, and then back to a low state. Each of these transitions can be counted and used to calculate the speed and position of the wheel.