Interfacing rotary encoder to AVR microcontroller

Recently I was working on a project where I used a rotary encoder. I could share some thoughts on how the rotary encoder should be interfaced to AVR MCU and write a code to read its value. It is relatively easy to connect and program rotary encoders – only three wires are required to connect to the microcontroller (two for signal quadrature outputs) and one for reference GND). When the encoder knob is turned in either direction, it generates a Grey code on the outputs, allowing tracking turn speed and direction. Rotary encoder allows including a convenient user interface option with a single knob. Many rotary encoders also come with an integrated button on the knob itself – so menu navigation becomes even more comfortable. In our example project, we are going to use a 12-step mechanical rotary encoder from SparkFun. It is interfaced to ATMega32 board with graphical LCD.