Arduino UNO with more than one stepper

Hello,

I'm working on a head-mounted device that requires the use of 6 stepper motors. I am attempting to simultaneously drive two motors in this manner, as shown in the diagram.

Arduino is powered from USB, and motors are powered from a 9V battery.In reality, the motors are connected to drivers, but they are not drawn in the diagram because the simulator does not include them.
When I drive only one motor at a time, everything functions properly, indicating that the components are each functioning correctly. But when I drive two motors in this way, they don't work.

So I would like to ask if there is an error in my program, or what is the correct way to drive two motors simultaneously?

Stepper: ULN2003 driver+ 28BYJ-48
Thanks for answer in advance.

#include <Stepper.h>

const int stepsPerRevolution = 2048;  // 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);
Stepper myStepper_second(stepsPerRevolution, 2, 4, 3, 5);

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

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

}

Welcome to the forum

Please do not post pictures of code

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

In my experience this is the easiest way to tidy up the code and add the code tags

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

1 Like

That's perfectly normal using a PP3 battery. Put it back in the firealarm.
Technical specifications for steppers and driver, please...

1 Like

Reading helps :wink:

The stepper.h library isn't really able to drive two steppers in parallel. Use a better library like Accelstepper or MobaTools.

1 Like

That battery is not suitable for motors. It does not deliver the current needed. Try 6 AA cells or a real power supply.
Nothing the code can fix.

1 Like

Thanks for reminding. It has been modified.

Thanks for your advice. I will try that library.

It's helpful. Thanks.

I 2nd the MobaTools library. Easier to learn and use than AccelStepper

1 Like

Thanks for sharing. I would try !

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.