How rotary encoder works and how to interface it with Arduino with examples to control servo motor direction