(edit sidebar)
Intro to Physical Computing Syllabus

Research & Learning

Other Class pages

Shop Admin

ITP Help Pages
Tom's pcomp site
DanO's pcomp site


Controlling a Stepper Motor With an H-Bridge

Stepper motors are motors that have multiple coils in them, so that they can be moved in small increments or steps. Stepper motors are typically either unipolar or bipolar, meaning that they have either one main power connection or two. Whether a stepper is unipolar or bipolar, however, you can control it with an H-bridge. This lab shows you how to set up a unipolar stepper motor using an H-Bridge. You can use the same control circuit with a bipolar motor too, however. The H-bridge used in this circuit is a basic one, the Texas Instruments L293NE or a Texas Instruments SN754410.

(:toc Table of Contents:)

Parts

You will need the following parts for this tutorial.

Solderless breadboard
Solderless breadboard
Arduino module
Arduino Microcontroller
module
hookup wire
22-AWG hookup wire
L293 H-bridge
L293NE
or SN754410 H-bridge
DC power supply
12V DC power supply
DC power jack
DC power jack


Prepare the breadboard

Connect power and ground on the breadboard to power and ground from the microcontroller. On the Arduino module, use the 5V and any of the ground connections.

(Diagram made with Fritzing)

Set up the H-bridge

L293 H-bridge
L293NE H-bridge

This example uses an H-bridge integrated circuit, the Texas Instruments L293NE or Texas Instruments SN754410. There is one in your Physical Computing Kit, and the NYU Computer Store and many distributors such as Digikey, SparkFun, Mouser and Jameco sell them as well.

The H-bridge will be used in a manner very similar to the DC Motor Control lab. But because the stepper has two coils instead of one, it'll be as if you were driving two motors with the H-bridge.

How the H-bridge works

The L293NE/SN754410 is a very basic H-bridge. It has two bridges, one on the left side of the chip and one on the right, and can control 2 motors. It can drive up to 1 amp of current, and operate between 4.5V and 36V. The small DC motor you are using in this lab can run safely off a low voltage so this H-bridge will work just fine.

The H-bridge has the following pins and features:

  • Pin 1 (1,2EN) enables and disables our motor whether it is give HIGH or LOW
  • Pin 2 (1A) is a logic pin for our motor (input is either HIGH or LOW)
  • Pin 3 (1Y) is for one of the motor terminals
  • Pin 4-5 are for ground
  • Pin 6 (2Y) is for the other motor terminal
  • Pin 7 (2A) is a logic pin for our motor (input is either HIGH or LOW)
  • Pin 8 (VCC2) is the power supply for our motor, this should be given the rated voltage of your motor
  • Pin 9-11 are unconnected as you are only using one motor in this lab
  • Pin 12-13 are for ground
  • Pin 14-15 are unconnected
  • Pin 16 (VCC1) is connected to 5V

Below is a diagram of the H-bridge and which pins do what in our example. Included with the diagram is a truth table indicating how the motor will function according to the state of the logic pins (which are set by our Arduino).

For this lab, both enable pins are connected to 5V to keep them HIGH all the time so the bridge is constantly enabled. The motor logic pins also connected to designated digital pins on your Arduino so you can send them HIGH and LOW control the stepper. The motor supply voltage connects to the voltage source for the motor, an external 12V DC power supply. Not all steppers run on 12V, but the one used for this example does. Check your stepper's ratings before you power the H-bridge.

Connect the H-bridge as shown below:

(Diagram made with Fritzing)


How the Stepper Motor Works

The stepper motor has two coils to control it. Each coil has a center connection as well, and the center connections are joined together, which is what makes this a unipolar stepper. If you don't connect the center connection, then the motor will work very much like a bipolar stepper, each coil operating independently. This is how you'll use it for this exercise. Each coil will connect to one side of the H-bridge. The pink and orange wires (the first coil) will connect to one side of the bridge, while the yellow and blue wires (the other coil) connect to the other side of the bridge.

Connect the motor to the H-bridge

Connect the motor to the H-bridge as follows:

(Diagram made with Fritzing

Note that the H-bridge's DC power is coming from the 12V DC connector. It shares a common ground with the Arduino, though.

Connect the H-Bridge to the Microcontroller

The H bridge's control inputs are connected to the microcontroller's input pins digital 8 through 11 as follows:

(Diagram made with Fritzing

Once you have those connected, you're ready to program the microcontroller.

Program the Microcontroller

Program the microcontroller to run the stepper motor through the H-bridge using the stepper library. For your first program, it's a good idea to run the stepper one step at a time, to see that all the wires are connected correctly. If they are, the stepper will step one step forward at a time, every half second, using the code below:

#include <Stepper.h>

const int stepsPerRevolution = 512;  // change this to fit the number of steps per revolution
                                     // for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);            

int stepCount = 0;         // number of steps the motor has taken

void setup() {
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one step:
  myStepper.step(1);
  Serial.print("steps:" );
  Serial.println(stepCount);
  stepCount++;
  delay(500);
}

Once you've got that working, try making the stepper move one whole revolution at a time. The number of steps per revolution will depend on your individual stepper, so check the data sheet for the number of steps per revolution:

#include <Stepper.h>

const int stepsPerRevolution = 512;  // change this to fit the number of steps per revolution
                                     // for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);            

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(10);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:
   Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);

   // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
}

With a high-step-count stepper, you may need to change the speed. If the motor steps are run too fast, the motor coils don't have a chance to energize and de-energize in order to step the motor.

Attach something to the Stepper

If you want to mount an arm or pointer to the stepper motor, you need to make a hole for the pointer that fits the shaft perfectly. You could measure this with a caliper. Here is an SVG file of an arrow with a shaft mounting hole perfectly sized for the stepper used in this lab.

  Edit | View | History | Print | Recent Changes | Search Page last modified on November 12, 2013, at 08:47 AM