Arduino and stepper motor test.

Arduino and stepper motor test.

Recently I collected a broken hard drive to experiment on making a POV clock that I found on the web. After taking the hard drive apart, my first idea was to drive the stepper motor in the hard drive using Arduino. I looked around the web for writeup and tutorials about the principles of driving stepper motors. I particularly found this resource very useful: http://www.cs.uiowa.edu/~jones/step/. Reading this tutorial I found out the type of stepper motor the hard drive had, as there are couple of types of stepper motors available in the market. This hard drive had a Variable Reluctance Stepper Motor and the internal construction of it is like the figure below.

 . . . . . . . . 1 ---/\/\/\-  .            1 | . .      2   X   3 2 ---/\/\/\-|-- C        Y o Y |          3   X   2 3 ---/\/\/\-               1
The motor has 4 pins, the common pin is usually connected to the positive power supply and the three other pins are required to be supplied negative voltage in a sequence to get the stepper motor moving. The logic is visualized in the figure below:

Now that I understood the logic of driving the motor, I wrote up the code for Arduino. The code uses 3 arduino digital pins in output mode (Pin 2,3,4) to drive the 3 coils of the stepper motor. However the arduino digital I/O pins does not produce enough current to drive the motor coils. Therefore power transistors or Darlington array chips (ULN2003 etc.) or H-Bridge motor drive chip (L293D etc.) are required to successfully drive the motor. For the experiment I used couple of regular NPN switching transistors (2N3904). These transistors yield quite low current (around 150-200mA), so I couldn’t drive the motor beyond a certain speed. I wrote the code that will start spinning the motor at a lower speed and then gradually speed up. You can play with the steppingDealy value to control the speed of the motor.

Here is the arduino code:

int pinA = 2;
int pinB = 3;
int pinC = 4;
int steppingDelay = 100;

void setup() {
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinC, OUTPUT);

digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
}

void loop() {
stepping(1);
delay(steppingDelay);
stepping(2);
delay(steppingDelay);
stepping(3);
delay(steppingDelay);
if(steppingDelay > 10)
{
steppingDelay–;
}
}

void stepping(int stage)
{
switch(stage)
{
case 1:
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
break;
case 2:
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
digitalWrite(pinC, HIGH);
break;
default:
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, LOW);
break;
}
}

Arduino sketch download:

StepperTest.pde (829.00 bytes)

8 thoughts on “Arduino and stepper motor test.

  1. Renan Chagas

    Hi,

    Pretty cool this code. I’m trying to run a hd motor for weeks without sucess… Could you send me the schematics? (by e-mail)

  2. MaxiD

    This works but is not strong and does not give over 500rpm. This method does not work to get all the engine speed.

    Esto funciona pero no tiene fuerza y no da mas de 500rpm. Este metodo no funciona para sacar toda la velocidad del motor

Leave a Reply

Your email address will not be published. Required fields are marked *


6 + five =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>