Anth's Computer Cave Tutorials

How to use stepper motors from old printers

Two stepper motors from a printer

I have been using stepper motors for a while now, and they are fantastic for all sorts of robotic projects.

Today I will share the things I have learnt so far about reusing old stepper motors salvaged from printers.

Identifying Stepper Motors

Stepper motors are easily identified by their shape, the number of connecting wires and the vibration you feel when you turn the shaft.

For starters, they tend to be wider and shorter than DC motors. The body generally looks like a flat cannister, while a brushed DC motor is usually longer than it is wide.

An assortment of stepper motors
A collection of stepper motors.

Two stepper motors from a printer
A brushed DC motor.

Stepper motors will have at least four connecting wires, and as many as eight. DC motors, on the other hand have two wires, and servo motors have three.

Lastly, stepper motors tend to "cog" if you turn them by hand. You will feel a sort of grinding vibration. DC motors usually turn more smoothly.

Bipolar or Unipolar stepper motors?

There are two types of stepper motors, bipolar and unipolar. If the motor has four wires it is most-likely a bipolar motor. If it has more than four wires it is a unipolar motor.

For this tutorial we will be working with bipolar motors.

What You Need

To run these stepper motors you will need a motor controller and a power supply.

Motor Controller

Two different stepper motor controllers.

A motor controller allows you to use low-voltage signals from your computer to send higher-voltage pulses to the motor.

The red motor controller pictured above costs around four dollars from this Ebay seller. It has a 25 watt maximum power rating and can run one bipolar stepper motor or two brushed DC motors.

The green motor-controller is for small unipolar motors.

Power Supply

Stepper motors used in printers tend to run on 24v but they will generally operate at lower voltage, albeit with less torque and rotation speed. Most of the units I have tried will spin up with 12v - 14v at around 400ma.

Current is an important consideration, especially if you choose to power the motors at 24v. Most cheap motor controllers are around 20 to 25 watts. Twenty-four volts at 1000ma is 24 watts meaning you will need to keep the current below that to avoid drawing more power than your motor controller can handle.

At the moment I have my power supply set to conservative 14v at 460ma (6.4 watt), and that seems to run all the motors I have tried so far.

If you need some help setting up a variable current and voltage power supply see my tutorial, Build an Adjustable Power Supply Using LM317 Regulators.

Determining Pinouts

One of the tricky aspects of stepper motors is finding which wires are which and where they go. Bipolar steppers have two pairs of wires, but they may not be adjacent to each other.

Now if you have motors from a Canon printer with black, brown, yellow and orange wires (see image below), you are in luck because I have already done the work for you. All Canon motors I have tried with this color scheme were exactly the same. Brown and black are one pair and yellow and orange are the other pair.

A stepper motor from a Canon printer.
A stepper motor from a Canon printer.

Alternately, if your stepper motor has a flat gray cable with a blue stripe on one edge (pictured below), I have you covered there, too. The first pair consists of the wire on the blue edge, then the third wire in the cable. The second pair is the second and fourth wires in the cable.

A stepper motor with a flat gray cable and blue edge.
A stepper motor with a flat gray cable and blue edge.

Unfortunately most other printer motors have no colour coding so you will need to do some detective work.

The first thing I do before I tear down a printer is download a full service manual. This can be difficult in itself because of all the crappy sites that pop up in search results offering free manuals only to send you around in circles before asking for money. You will need to persist, and you may find you'll download a few manuals before you get the right one. You need the actual service manual, not the user manual.

Once you have the service manual you can study the diagrams to determine the pinouts by the circuit boards the motor plugs into.

If all this fails, you will need a multimeter. Many people identify these pairs by looking for resistance between the wires, but I use a different technique.

Stepper motors actually produce real voltage when you turn them by hand. Set your multimeter to volts and connect it to two of the wires then turn the motor. If you see the voltage jump, you have found a pair. If not, disconnect one wire and try another. Once you have found both pairs you are half way there.

Connect to the motor controller.

The setup for running a stepper motor. Picture: Anthony Hartup

Bipolar stepper motor controllers have four screw terminals for the motor (usually two on each side) and three screw terminals on the front for Voltage in (Vin), ground (GND) and 5v. Do not connect anything to the 5v terminal. Plug your power supply to Vin and GND.

The motor terminals will be labelled in one of the following ways:

OUTA, OUTB, OUTC, OUTD

OUT1, OUT2, OUT3, OUT4

MOTA, MOTB, MOTC, MOTD

MOT1, MOT2, MOT3, MOT4

The motor controller wiring. Picture: Anthony Hartup

In this example I am using a controller with"OUTA", "OUTB", etc.

The first pair of motor wires goes OUTA and OUTB. The second pair goes to OUTC and OUTD

Now to connect the motor controller to your Arduino or Raspberry Pi.

The Arduino Uno wired to run the stepper motor. Picture: Anthony Hartup

I am assuming you are familiar with using the GPIO pins on your Arduino or Pi. If you need help with this leave a comment at the bottom of this page and I will get back to you with some help.

You will need to use two GPIOs to enable your motor and four GPIO pins to drive the stepping sequence. You can use a jumper on the enable pin (ENB) to save using an extra two GPIOs but this tutorial and the code we will write uses dedicated enable wires.

Which GPIO pins you choose is not important as long as you change the pins in the code to suit.

The motor controller should have four pins called in1, in2, in3 and in4, as well as two ENB pins. If the ENB pins have jumpers attached, remove them.

A connection diagram for connecting a stepper motor to an Arduino. Picture: Anthony Hartup.

On my Arduino set up I have GPIO 12 and 13 connected to the ENB pins on the motor controller. I have GPIO 2 connected to in1, GPIO 3 to in2, GPIO 6 to in3 and GPIO 7 to in4. If you use these pins the code I provide will work out of the box. If you use different pins you will need to change the code to suit.

The Code

Okay, there's the drudgery out of the way, now for the fun part. Let's write some code to run your motor.

We will start with the Arduino code, then we'll try out some Python code for the Raspberry Pi.

Arduino

Here is the complete code I use to test stepper motors. You should be able to copy and paste it into the Arduino IDE.

#include <Stepper.h> //This includes the stepper.h library for Arduino
#define STEPS 96 //96 steps per revolution  for a 3.75 deg motor 
#define D0 2 // These are the GPIO pins you are using for the sequence.
#define D1 3
#define D2 6
#define D3 7
const int enab1 = 12; // These are the GPIO pins connected to the ENB pins
const int enab2 = 13;


Stepper stepper(STEPS, D0, D1, D2, D3); //create a stepping sequence.

void setup() 
{ digitalWrite(enab1, HIGH); //This enables your motor controller.
  digitalWrite(enab2, HIGH);
  stepper.setSpeed(30); //This sets the motor speed to 30 rpm
  delay(1000); //This delay lets the motor stop turning before changing direction
  stepper.step(980); //980 steps should turn 10 revolutions one way
  delay(1000); 
  stepper.step(-980); //turn 10 revolutions the opposite way
  delay(1000); 
  stepper.step(980); //turn 10 revolutions the other way again 
}

void loop() 
{}
	

Now I will go through it in detail.

#include <Stepper.h>

This line tells your Arduino to use stepper.h, a library of pre-built functions to run stepper motors. There are other stepper libraries I plan to cover in future but we will use this one today.


#define STEPS 96

Here we set the step size for your motor. Some motors will have their step size written on the label, others will not.

If you know the step size for your motor you simply divide 360 by the step size. For instance, a 3.75 degree stepper has 96 steps per revolution.

Your motor will still run if you get this wrong so don't stress too much if you can't find the step size for your motor. This is more to do with setting an accurate amount of revolutions for the motor to turn and you can adjust it later by counting revolutions.


#define D0 2
#define D1 3
#define D2 6
#define D3 7

These four lines tell the Arduino which pins you are using to drive the sequence. You need to get these right.


const int enab1 = 12;
const int enab2 = 13;

These lines tell the Arduino which pins are the enable pins.


Stepper stepper(STEPS, D0, D1, D2, D3);

This line sets the stepping sequence the code will generate.


{ digitalWrite(enab1, HIGH);
  digitalWrite(enab2, HIGH);

These lines set the enable pins to high which enables your motor controller ready for use.


stepper.setSpeed(30);

This line sets the speed in revolutions per minute (RPM), if you have your step size correct.


  delay(1000);
  stepper.step(980);
  delay(1000); 
  stepper.step(-980);
  delay(1000); 
  stepper.step(980);
  		

These lines turn the motor 980 steps (10 revolutions with a 3.75 degree motor) in different dirrections


That is all there is to it as far as the Arduino goes.

Python on the raspberry PI

Now we will move on to my favourite method, running the motor from the Raspberry Pi. It is not too much different to the Arduino, but I like how you can control things live with the Pi, rather than having to upload sketches to the Arduino every time I want to modify the code.

For now, though, I need a break. I will continue this tutorial soon.

See you then!

Cheers

Anth

_____________________________________________

Comments

Leave a comment on this article




qaaq _________ 21/08/2016 - 07:26:31pm

Can u please do video tutorial on this. Do u mean General Purpose Input/Output Pins for GPIO , can u please explain, . and thanks for the tutorial

___________________________