Introduction: Use a Stepper Motor As a Rotary Encoder

Rotary encoders are great for use in microcontroller projects as an input device but their performance is not very smooth and satisfactory. Also, having a lot of spare stepper motors around, I decided to give them a purpose. So if have some stepper motors lying around and want to make something, get the supplies and let's get started!

Step 1: Watch the Video

Step 2: Get All the Stuff

For this project, you will need:

  • A stepper motor(Unipolar or bipolar).
  • An LM358P op-amp chip.
  • A 1k Ohm resistor.
  • 2x 100k Ohm resistors.
  • 2x 4.7k Ohm resistors.
  • 2x 47k Ohm resistors.
  • An LED.
  • Connecting wires.

Optional components:

  • 2x LEDs
  • 2x 330 Ohm resistors

Step 3: Study the Circuit Diagram

Thanks, Andriyf1!

Make sure you go through the circuit schematic before proceeding.

Since the two pins in the middle of the header to be connected to the stepper motor are connected to the same point in the circuit(Say, common), you can use a 1x3 header instead of the 1x4 header in the permanent version, but then for connecting a bipolar stepper motor, you will need to connect one wire of the two coils each together and connect them to the common point of the circuit with the remaining two wires to be connected to the pins P and S respectively.

Step 4: Assemble the Circuit on a Breadboard and Test It

Start by placing the op-amp ship on the board and proceed by connecting resistors to the appropriate locations. Try to use shorter wires and avoid entangling the wires. Make sure no connections are loose and are made according to the circuit schematic.

Connect the stepper motor to the amplifier and power it up with a 5-volt power source.

If you are using the optional LEDs, connect each LED's anode to each of the outputs through a 330 Ohm resistor and connect their cathodes to 'GND'.

Step 5: Make a Permanent Version

Click on the image to know more.

A permanent version of the amplifier will be recommended to make as it will be more compact and practical to use in projects.

Step 6: Test It With a Microcontroller, Upload the Arduino Code

This example controls the brightness of an LED connected to pin 'D13' by adjusting the duty cycle on that output pin, controlled by a rotary encoder.

Step 7: Make the Wiring Connections

Connect the amplifier's power to *'+5-V pin, '-ve' to 'GND' pin, and the output pins to the pins 'D6' and 'D7' of the Arduino board. The sequence of the connection of the output pins of the amplifier to the input pins of the Arduino determines whether the particular direction of movement of the stepper motor will be registered as clockwise or anticlockwise.

*If you are using a microcontroller which works on a 3.3-V logic level, make sure you power the amplifier with 3.3-V DC only!

Step 8: Power Up the Setup

Connect the setup to an appropriate power source(5-12 volt DC) and power it up.

Step 9: Expand It Furthur

Now that you have got it working, you can do all sorts of projects which can be done with a rotary encoder. If you make something with it, try sharing some pictures of your work with the community by clicking on 'I Made It!'.