I've removed the rotary encoder from the scroll button of a defect mouse. Let's see how we can use that in a microcontroller design.
In post 1, I wired up the electronics.
In part 2, I'm capturing the encoder's info on a Cypress PSoC4.
This time, I'm checking an existing example on an Arduino UNO.
Well, that was easy. I found a number of examples on http://playground.arduino.cc/Main/RotaryEncoders.
I bet the majority of the projects on that page will work. I chose rafbuff's implementation because it was clean code and uses interrupts (several examples on that page do that, but you have to make a choice).
It's less than 100 lines of code, provides additional in-software debouncing and doesn't require an external library.
And it works straight away.
The source is available on http://playground.arduino.cc/Main/RotaryEncoders.
Search for rafbuff.
If you think that I should have tried another implementation, post it in the comments.
Wiring the Hardware
Look back at my first post to check how to components are wired up.
Then connect the encoder with the board.
Ground to Ground, 5V to 5V,
PINA to Digital 3, PINB to Digital 2 (that's different than the code comments. My setup counted backwards when I wired it up as written in the code, but I used a different encoder).
Connect the Arduino, execute the program and open the Serial Monitor.
The count is logged to the monitor on every spin.