Help Required: Stepper motor control

Hey there!
Somehow I can't get my stepper motor sketch working.
I use a unipolar Howard 1-19-4201 with ULN2803A and would like it to do a sequence of steps by pressing a button.
Now the button is no problem. but somehow my stepper just vibrates and doesn't move a step.
The wiring shouold be correct, as I tried it with another sketch without the stepper.h library and it worked....

Would be great if someone could help me.

#include <Stepper.h>

#define STEPS 100

// attached to
Stepper stepper(STEPS, 28, 30, 32, 34);


void setup() {
stepper.setSpeed(60);

}

int x = 0;

void loop()
{
   stepper.step(50);            // How many Steps
   x++;
   delay(5);  

   if(x == 50)
   {
       delay(5000);           // Wait for 5 seconds
       x = 0;
   }
}

You are giving the stepper motor 5 milliseconds to step 50 times. You've defined that the motor takes 100 steps to complete a revolution, so you are allowing it 10 milliseconds to complete one revolution. That's 100 revolutions per second, or 6000 rpm.

Is your stepper capable of that speed?

The wiring shouold be correct, as I tried it with another sketch without the stepper.h library and it worked....

Same pins? Post that code, please.

Well I dont really know what my stepper is capable of :slight_smile: there was no description...
The stepper is moving forward and backward very fast and "vibrates"
just as if the wiring was incorrect...

I made some pics and posted the Code thats working...

      /* Bi-Directional Stepper Control - Full Step, High Torque
      *  -------------------------------------------------------
      *
      *  Program to drive stepper motor. Send HIGH signal
      *  to (2) successive pins to create higher torque.
      *  Motor speed is controlled by delayTime. Higher
      *  speed results in lower torque. Make sure to use
      *  a pull-down resistor on pin 12.
      *
      *  @author: Andrew Browning
      *  @date: 2009-10-07
      *  @modified: 2009-10-08
      */
       
      int motorPins[] = {28,30,32,34};
      int testPin = 50;
      int count = 0;
      int phase = 1;
      int phasenext = 0;
      int delayTime = 6;



      void setup() {
        for (count = 0; count < 4; count++) {
          pinMode(motorPins[count], OUTPUT);
        }
        pinMode(testPin, INPUT);
      }
       
      void moveForward() {
        if (phase == 5) {
          phase = 1;
        }
        phasenext = phase + 1;
        if (phasenext == 5) {
          phasenext = 1;
        }
        digitalWrite(motorPins[(phase-1)], HIGH);
        digitalWrite(motorPins[(phasenext-1)], HIGH);
        delay(delayTime);
        digitalWrite(motorPins[(phase-1)], LOW);
        digitalWrite(motorPins[(phasenext-1)], LOW);
        phase++;
      }
       
      void moveReverse() {
        if (phase == 0) {
          phase = 4;
        }
        phasenext = phase + 1;
        if (phasenext == 5) {
          phasenext = 1;
        }
        digitalWrite(motorPins[(phase-1)], HIGH);
        digitalWrite(motorPins[(phasenext-1)], HIGH);
        delay(delayTime);
        digitalWrite(motorPins[(phase-1)], LOW);
        digitalWrite(motorPins[(phasenext-1)], LOW);
        phase--;
      }
       
      void loop() {
        if (digitalRead(testPin) == LOW) {
          moveForward();
        }
        if (digitalRead(testPin) == HIGH) {
          moveReverse();
        }
      }

Okay thats interessting...

It was a wiring problem
but i dont understand why...

in the first code i had to put in

Stepper stepper(STEPS, 32, 28, 30, 34);

and it started to work...

in the other code i had to put in

int motorPins[] = {28,30,32,34};

Why is that? ?????

Thx for your help!

Why is that? ?????

Well, clearly the stepper class has a different expectation for the order of the pins.

It's not all that clear what order the pin numbers are supposed to be specified in.

pin1, pin2: two pins that are attached to the motor (int)

pin3, pin4: optional the last two pins attached to the motor, if it's connected to four pins (int)

But which is which?