0

I want to control multiple stepper motors one after another and at different speeds/directions. I am using the ULN2003 driver and the stepper has 5 coils.

My current code for controlling one motor is:

#include 

const int stepsPerRevolution = 500;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);


void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(50);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
}

How would I define each stepper motor differently?

Sorry if I have not asked the question properly. I will try to clarify as time goes on.

  • How about multiple variables of the type Stepper, each representing one stepper motor? Do you understand how the code above works? – chrisl Dec 31 '18 at 19:20
  • @chrisl Yes, I do understand how the code works. I just want to know how to control two different stepper motors. For example, above we have a stepper motor being defined as myStepper.... Oh, do I just have to replace ‘myStepper’ with ‘Stepper2’? Right?? – 12944qwerty Dec 31 '18 at 19:30
  • Exactly. Each Stepper variable controls 1 motor. That should work. – chrisl Jan 1 at 1:00
  • just a note: that is a Stepper object, not a Stepper variable – jsotola Jan 1 at 1:56
0

Like @chris! suggested, you could include two Stepper variables. So in the line where you were initializing the variable, you could instead have:

Stepper steppermotor1(stepsPerRevolution, 8, 10, 9, 11);

Stepper steppermotor2(stepsPerRevolution, 4, 5, 6, 7);

and then continue on with the code for speed, rotation and so on for each motor.

  • just realized you got your answer after reading through the comments. Never mind then. Thanks :) – Danush Jul 15 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.