I don't know the programming and pin connection but I know what you need. I am working on same project.
You need Magnetic Encoder. I like AS5045.
The magnet you need is :- NdFeB Rod Magnet, Ni-Cu-Ni Plated, Matte
finish, Diametrically Magnetized, Grade N40
Magnet with circumferential field distribution, 2.5mm high, 6mm in diameter.
Here are two links which are helpful for you :-
http://code.google.com/p/zosupermodified/
http://code.google.com/p/zoavrlib
Some tutorial links:-
http://www.reprap.org/wiki/Magnetic_Rotary_Encoder_1_0
I am trying with Arduino UNO 3 and AS5045. If you write any code then please share it with me. I want to make high torque servo motor.