# How to drive three stepper motors one by one?

Hi all, I am new here. I am trying to drive 3 stepper motors via AccelStepper library. however, when I run the following codes in my Arduino UNO, the 3 motors run simultaneously. So how can I make them run one by one? Say 10 rounds for stepperA, then 10 rounds for stepperB, and 10 rounds for stepper C?

``````#include <MultiStepper.h>
#include <AccelStepper.h>

AccelStepper stepperA(1, 6, 7);
AccelStepper stepperB(1, 8, 9);
AccelStepper stepperC(1, 4, 6);

void setup() {
stepperA.setCurrentPosition(0);
stepperA.setMaxSpeed(25600);
stepperB.setCurrentPosition(0);
stepperB.setMaxSpeed(25600);
stepperC.setCurrentPosition(0);
stepperC.setMaxSpeed(25600);
}

void loop() {
{
stepperA.moveTo(-64000);
stepperA.setSpeed(-6400);
stepperA.runSpeedToPosition();
}
{
stepperB.moveTo(-64000);
stepperB.setSpeed(-6400);
stepperB.runSpeedToPosition();
}
{
stepperC.moveTo(-64000);
stepperC.setSpeed(-6400);
stepperC.runSpeedToPosition();
}
}
``````

That's not how runSpeedToPosition works.

Try

``````    stepperA.setSpeed (-6400);  // need to set speed before moving
stepperA.moveTo (-64000L); // need a long constant for a 32 bit value
while (! stepperA.runSpeedToPosition ())  // wait till gets there.
{}
``````

But why are you trying to do things in a blocking way in the first place? Look at the MultiStepper example for the normal way to use AccelStepper without blocking - you can call moveTo() whenever you like for any motor then.

gerryho: however, when I run the following codes in my Arduino UNO, the 3 motors run simultaneously.

The way you have written the program that is inevitable.

You don't have any mechanism in that program to run each motor separately. The usual way to do that is update move() or moveTo() for the motor (or motors) that you want to move.

Try this

``````void loop() {
{
// stepperA.moveTo(-64000);
// stepperA.setSpeed(-6400);

// stepperB.moveTo(-64000);
// stepperB.setSpeed(-6400);

if (stepperC.distanceToGo() == 0) {
stepperC.moveTo(-64000);
stepperC.setSpeed(-6400);
delay(1000);  // just for the demo
}

stepperA.runSpeed();
stepperB.runSpeed();
stepperC.runSpeed();
}
}
``````

I don't think AccelStepper can work with such high speeds. I think somewhere around 1000 or 2000 is its limit.

What does a negative speed mean?