Electronics Projects: Controlling a Stepper Motor Using a Rotary Encoder

Somnath Bera. He is an avid user of open source software. Professionally, he is a thermal power expert and works as additional general manager at NTPC Ltd


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.

Fig. 1: Author’s prototype
Fig. 1: Controlling stepper motor using rotary encoder: Author’s prototype

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.

Fig. 2: A 5-pin rotary encoder
Fig. 2: A 5-pin rotary encoder

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.

Fig. 3: Controlling stepper motor using rotary encoder: circuit connection
Fig. 3: Controlling stepper motor using rotary encoder: circuit connection

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.


Enter your email address:

Delivered by FeedBurner


Please enter your comment!
Please enter your name here