Measuring rotation with a shaft encoder:

There are typically two sensing methods implemented with encoders, either based on optical or inductive sensing. With optical rotary encoder, the encoder disc modulates a light beam whose intensity is sensed by photo-electrical cells. These produce two 90-degree phase shifted sinusoidal incremental signals A and B. B lags A with clockwise rotating viewed from the shaft of the encoder. The number of periods of the signals A and B over one mechanical revolution equals the line count N of the encoder. A further track carries the reference marker R, which occurs once per mechanical revolution. The reference marker allows for an absolute angle position measurement. 


Optical encoders with high precision are usually expensive. However, you can find a very good one from any printer. A shaft encoder in a printer is responsible for aligning the paper and can be used easily. Here is a shaft encoder i took from an HP inkjet printer and used in my experiment:

The encoder disk is located under the gear and optical sensors are on the left side of the image. I could find the input voltage for the sensors and the power it up by using an external power source. But everything was already in the printer! and i ended up keeping the front panel because of the "cover open" and "paper out" errors!! The whole setup looked like this:

On the right, there is printer board and power supply. On the left, the amplifier for force-moment sensor.

The encoder disk had 1320 lines which means it can measure down to 360/1320 (around 0.3) degree. But it's possible to make it even better by interpolating the rotation between two consecutive lines based on the voltage of each sensor. Here, i used Matlab for digitizing and analyzing the signals from the sensor:

[chA ,TimeA]=A2D(cha,time);%converting signal to digital
[chB ,TimeB]=A2D(chb,time);%converting signal to digital

[pos]=decodeitI(cha,chb,chA ,chB);%converting signals to rotational position
pos=pos*360/1320;%converting to degree

You can download Matlab functions from here.