How to control Stepper motor ?

UnipolarKnob_bbsmStepper motors, due to their unique design, can be controlled to a high degree of accuracy without any feedback mechanisms. The shaft of a stepper, mounted with a series of magnets, is controlled by a series of electromagnetic coils that are charged positively and negatively in a specific sequence, precisely moving it forward or backward in small “steps”.


There are two types of steppers, Unipolars and Bipolars, and it is very important to know which type you are working with. For each of the motors, there is a different circuit. The example code will control both kinds of motors. See the unipolar and bipolar motor schematics for information on how to wire up your motor.


In this example, a potentiometer (or other sensor) on analog input 0 is used to control the movement of a stepper motor using the Arduino Stepper Library. The stepper is controlled by with digital pins 8, 9, 10, and 11 for either unipolar or bipolar motors.

The Arduino will connect to a U2004 Darlington Array if you’re using a unipolar stepper or a SN754410NE H-Bridge if you have a bipolar motor.


For more information about the differences of the two types, please take a look at Tom Igoe’s page on stepper motors.

Hardware Required

  • Arduino Board
  • potentiometer
  • stepper motor
  • U2004 Darlington Array (if using a unipolar stepper)
  • SN754410ne H-Bridge (if using a bipolar stepper)
  • power supply appropriate for your particular stepper
  • breadboard
  • hookup wire

Code

For both unipolar and bipolar steppers

#include <Stepper.h>

// change this to the number of steps on your motor #define STEPS 100

// create an instance of the stepper class, specifying // the number of steps of the motor and the pins it’s // attached to Stepper stepper(STEPS, 8, 9, 10, 11);

// the previous reading from the analog input int previous = 0;

void setup() { // set the speed of the motor to 30 RPMs stepper.setSpeed(30); }

void loop() { // get the sensor value int val = analogRead(0);

// move a number of steps equal to the change in the // sensor reading stepper.step(val previous);

// remember the previous value of the sensor previous = val; }


 

 

Leave a Reply