Presented here is a project for controlling stepper motor using rotary encoder. It consists of a Raspberry Pi (Raspi) board, 5-pin rotary encoder, 5V stepper motor and an L293D motor driver. Author’s prototype is shown in Fig. 1.
A rotary encoder, also called a shaft encoder, is an electromechanical device that converts the angular position or motion of a shaft or an axle to analogue or digital code.
There are two main types: absolute and incremental (relative). Output of the absolute encoder indicates the current position of the shaft, making it an angle transducer. Output of the incremental encoder provides information about the motion of the shaft, which is further processed elsewhere into information such as speed, distance and position.
Rotary encoders are used in various applications that require precise but unlimited shaft rotation, including industrial controls, robotics, special-purpose photographic lenses, computer input devices (such as optomechanical mice and trackballs), controlled stress rheometers and rotating radar platforms.
Raspberry Pi in action
Here is the solution based on Raspi using a rotary encoder to drive a stepper motor.
The rotary encoder is an easy, efficient and inexpensive device for creating directional rotation in digital format. A typical rotary encoder has three or more leads, wherein the common lead goes to ground.
By following which lead goes to ground through the common lead, a direction of rotation is established and a counter is incremented at the same time.
Each movement of the rotary encoder is read by the program and fed to the stepper motor for making the same amount of stepped movement. This principle can be employed to control feeding of the heavy motor control such as in a paddle feeder.
The same technique can be employed for aligning a telescope’s focus mechanism, direction of a dish antenna to re-adjust satellite drifting, mast of a crane for placing it on the load and much more.
A 5-pin rotary encoder is shown in Fig. 2. Only three wires have been used for the project. The orange wire is the common lead, while blue wires are the two points, namely A and B.