One possible error could be that You rotated the item too fast. Try with a slow rotation, not advancing until You receive a value that reflects the last move.
And... please use code tags when posting code. How to? How to get the best out of this forum - Using Arduino / Project Guidance - Arduino Forum