2 stepper motor

please help me. how to use 2 stepper motors, the motor 1 forward and then the motor 2 forward and then stop.

this is the code that im using.

#include <AccelStepper.h>

AccelStepper stepper1(AccelStepper::DRIVER, 2, 5);
AccelStepper stepper2(AccelStepper::DRIVER, 4, 7);

void setup()
{
Serial.begin(9600);
stepper1.setMaxSpeed(3000);
stepper1.setAcceleration(1000);
stepper2.setMaxSpeed(3000);
stepper2.setAcceleration(1000);
}

void loop()
{
if (Serial.available() > 0) {
    char a = Serial.read();
switch(a)
{
  case '0':{
    stepper1.moveTo(2000);
    break;
  }
  case '1':{
    stepper2.moveTo(1000);
    break;
  }
  default : {
     // default is optional
 }
}
{
   stepper1.run();
   stepper2.run();
}
}
}

but this code don't work, there may be something wrong

thank you

Try moving these two lines

		   stepper1.run();
		   stepper2.run();

out of the IF clause and just put them as the last two lines in loop()

Those lines need to be called all the time, not just when data is received.

Your code will be much easier to read if you use the AutoFormat tool to indent it consistently.

...R
Stepper Motor Basics
Simple Stepper Code

Hi
Is this related to this old thread?

http://forum.arduino.cc/index.php?topic=286652.0

Tom... :slight_smile: