Use a Stepper Motor As a Rotary Encoder

by KushagraK7 in Circuits > Electronics

13269 Views, 42 Favorites, 0 Comments

Use a Stepper Motor As a Rotary Encoder

IMG_1847.JPG

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!

Watch the Video

HACKED: Stepper Motor as a Rotary Encoder

Get All the Stuff

IMG_2148.JPG

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

Study the Circuit Diagram

Circuit schematic.png

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.

Assemble the Circuit on a Breadboard and Test It

IMG_2144.JPG

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'.

Make a Permanent Version

IMG_2145.JPG

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.

Test It With a Microcontroller, Upload the Arduino Code

Arduino code.PNG
IMG_2110.PNG

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.

Make the Wiring Connections

IMG_2146.JPG

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!

Power Up the Setup

IMG_2150.JPG
IMG_2151.JPG
IMG_2152.JPG

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

Expand It Furthur

Controlling model locomotives using a stepper motor | Stepper motor as rotary encoder | Arduino

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!'.