Acceuil‎ > ‎Solutions Matériels‎ > ‎

Connecting a stepper to Arduino

Connecting a stepper to Arduino

(First version, march 2012 )

By Ahmed Aboutajeddine

(This tutorial is a collection of information adapted from the links at the bottom of the page)

 

1-Introduction to stepper motors:

Stepper motors are one kind of electric motor used in the robotics industry. Stepper motors move a known interval for each pulse of power. These pulses of power are provided by a stepper driver and are referred as steps. As each step moves the motor a known distance, the motor's position is controlled precisely without any feedback mechanism (an open-loop controller). However, the motor have to be carefully sized to your application.

Stepper motors can be found in printers, disk drives, and other devices where precise positioning of the motor is necessary.

Hints:

1-Steps in a revolution vs rotation of each step

steps per revolution

Angle for each step (degree)

200

1.8

100

3.6

48

7.5

24

15

20

18

2-Like other motors, stepper motors require more power than a microcontroller can give them, so you’ll need a separate power supply for it. Ideally you’ll know the voltage from the manufacturer, but if not, get a variable DC power supply, apply the minimum voltage (hopefully 3V or so), apply voltage across two wires of a coil (e.g. 1 to 2 or 3 to 4) and slowly raise the voltage until the motor is difficult to turn. It is possible to damage a motor this way, so don’t go too far. Typical voltages for a stepper might be 5V, 9V, 12V, 24V.

2- Basic types of stepper motors

There are two major types of stepper motor known as bipolar and unipolar.

Bipolar stepper motor

The bipolar stepper motor usually has four wires coming out of it. They have two independent sets of coils. To figure out the wires you have to measure the resistance between the wires. You should find two pairs of wires with equal resistance. If you’ve got the leads of your meter connected to two wires that are not connected (i.e. not attached to the same coil), you should see infinite resistance (or no continuity).


Unipolar stepper motor

Unipolar motors have two coils, each one has a centre tap. They are readily recognizable because they have 5, 6 or even 8 leads. It is possible to drive 6 or 8 lead unipolar motors as bipolar motors if you ignore the centre tap wires. 5 lead motors have both centre taps connected, so re-wiring them to a 4 lead version requires at least opening the motor, if it can be done at all. The main beauty of unipolar motors is that you can step them without having to reverse the direction of current in any coil, which makes the electronics simpler


Sorting out which wire is which in a 5- or 6-wire unipolar stepper motor:

1·  Isolate the Common Power wire(s) by using an ohmmeter to check the resistances between pairs of wires. The Common Power wire will be the one with only half as much resistance between it and all the others.


This is because the Common Power wire only has one coil between it and each other wire, whereas each of the other wires have two coils between them. Hence half the resistance.

2·  Identify the wires to the coils by supplying a voltage on the Common Power wire(s) and keeping one of the other wires grounded while grounding each of the remaining three wires in turn and observing the results.


3-Circuits for stepper motors

Circuit for Bipolar Stepper Motor, Two-Wire Control


Circuit for unipolar Stepper Motor, Two-Wire Control


4- Code example for driving stepper motors

Because both unipolar and bipolar stepper motors are controlled by the same stepping sequence, we can use the same microcontroller code to control either one. In the code examples below, connect either the Darlington transistor array (for unipolar steppers) or the dual H-bridge (for bipolar steppers) to the pins of your microcontroller as described in each example above.

Code:

Stepper myStepper(motorSteps, motorPin1,motorPin2,motorPin3,motorPin4);

/*

 Stepper Motor Controller

 language: Wiring/Arduino

 

 This program drives a unipolar or bipolar stepper motor.

 The motor is attached to digital pins 8 and 9 of the Arduino.

 

 The motor moves 100 steps in one direction, then 100 in the other.

 

 Created 11 Mar. 2007

 Modified 7 Apr. 2007

 by Tom Igoe

 

 */

 

// define the pins that the motor is attached to. You can use

// any digital I/O pins.

 

#include <Stepper.h>

 

#define motorSteps 200     // change this depending on the number of steps

                           // per revolution of your motor

#define motorPin1 8

#define motorPin2 9

#define ledPin 13

 

// initialize of the Stepper library:

Stepper myStepper(motorSteps, motorPin1,motorPin2);

 

void setup() {

  // set the motor speed at 60 RPMS:

  myStepper.setSpeed(60);

 

  // Initialize the Serial port:

  Serial.begin(9600);

 

  // set up the LED pin:

  pinMode(ledPin, OUTPUT);

  // blink the LED:

  blink(3);

}

 

void loop() {

  // Step forward 100 steps:

  Serial.println("Forward");

  myStepper.step(100);

  delay(500);

 

  // Step backward 100 steps:

  Serial.println("Backward");

  myStepper.step(-100);

  delay(500);

 

}

 

// Blink the reset LED:

void blink(int howManyTimes) {

  int i;

  for (i=0; i< howManyTimes; i++) {

    digitalWrite(ledPin, HIGH);

    delay(200);

    digitalWrite(ledPin, LOW);

    delay(200);

  }

}

 

5- References

- http://arduino.cc/en/Reference/Stepper?from=Tutorial.Stepper

- http://www.astrosurf.com/2ad/montage/pasapas/moteur.htm

- http://www.tigoe.com/pcomp/code/circuits/motors/stepper-motors/

- Ian Harries on steppers (this page is no longer available)

- http://reprap.org/wiki/Stepper_motor#What_is_a_Stepper_Motor_.3F

- http://en.wikipedia.org/wiki/Stepper_motor#Stepper_motor_characteristics

- http://www.romanblack.com/stepper.htm

 

 



Comments