How do I power eight 5v 28BYJ-48 - ULN2003 ?

Hello,

I have connected 8 5v 28BYJ-48 stepper motors to an Arduino Mega 2560. I am using a separate 5v power supply for the motors and the Arduino is connected to the computer via a USB cable . The motors turn smoothly to begin with but then they begin to stall/stutter and the LED's on the driver boards flicker.

I tried again but with only 4 motors and these ran smoothly. I have attached a rough schematic of how everything is connected and code I am using below.

Would you say I need a bigger power supply?
Many thanks.

#include <AccelStepper.h>


// Define step constants
//#define FULLSTEP 4
#define HALFSTEP 8

// Define Motor Pins (2 Motors used)

#define motorPin1  22     // Blue   - 28BYJ48 pin 1
#define motorPin2  23    // Pink   - 28BYJ48 pin 2
#define motorPin3  24    // Yellow - 28BYJ48 pin 3
#define motorPin4  25    // Orange - 28BYJ48 pin 4
                        
                        
#define motorPin5  26     // Blue   - 28BYJ48 pin 1
#define motorPin6  27    // Pink   - 28BYJ48 pin 2
#define motorPin7  28     // Yellow - 28BYJ48 pin 3
#define motorPin8  29    // Orange - 28BYJ48 pin 4

#define motorPin9  30     // Blue   - 28BYJ48 pin 1
#define motorPin10 31    // Pink   - 28BYJ48 pin 2
#define motorPin11 32     // Yellow - 28BYJ48 pin 3
#define motorPin12 33    // Orange - 28BYJ48 pin 4

#define motorPin13 34     // Blue   - 28BYJ48 pin 1
#define motorPin14 35   // Pink   - 28BYJ48 pin 2
#define motorPin15 36   // Yellow - 28BYJ48 pin 3
#define motorPin16 37  // Orange - 28BYJ48 pin 4

#define motorPin17 38     // Blue   - 28BYJ48 pin 1
#define motorPin18 39   // Pink   - 28BYJ48 pin 2
#define motorPin19 40   // Yellow - 28BYJ48 pin 3
#define motorPin20 41  // Orange - 28BYJ48 pin 4

#define motorPin21 42     // Blue   - 28BYJ48 pin 1
#define motorPin22 43   // Pink   - 28BYJ48 pin 2
#define motorPin23 44   // Yellow - 28BYJ48 pin 3
#define motorPin24 45  // Orange - 28BYJ48 pin 4

#define motorPin25 46     // Blue   - 28BYJ48 pin 1
#define motorPin26 47   // Pink   - 28BYJ48 pin 2
#define motorPin27 48   // Yellow - 28BYJ48 pin 3
#define motorPin28 49  // Orange - 28BYJ48 pin 4


#define motorPin29 50     // Blue   - 28BYJ48 pin 1
#define motorPin30 51   // Pink   - 28BYJ48 pin 2
#define motorPin31 52   // Yellow - 28BYJ48 pin 3
#define motorPin32 53  // Orange - 28BYJ48 pin 4


// Define two motor objects
// The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
AccelStepper stepper2(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8);
AccelStepper stepper3(HALFSTEP, motorPin9, motorPin11, motorPin10, motorPin12);
AccelStepper stepper4(HALFSTEP, motorPin13, motorPin15, motorPin14, motorPin16);
AccelStepper stepper5(HALFSTEP, motorPin17, motorPin19, motorPin18, motorPin20);
AccelStepper stepper6(HALFSTEP, motorPin21, motorPin23, motorPin22, motorPin24);
AccelStepper stepper7(HALFSTEP, motorPin25, motorPin27, motorPin26, motorPin28);
AccelStepper stepper8(HALFSTEP, motorPin29, motorPin31, motorPin30, motorPin32);
void setup() {
  // put your setup code here, to run once:
stepper1.setMaxSpeed(1000.0);
  stepper1.setAcceleration(100.0);
  stepper1.setSpeed(50);
  stepper1.moveTo(4072);  
  
  // 1 revolution Motor 2 CCW
  stepper2.setMaxSpeed(1000.0);
  stepper2.setAcceleration(100.0);
  stepper2.setSpeed(50);
  stepper2.moveTo(4072); 
  
  stepper3.setMaxSpeed(1000);
  stepper3.setAcceleration(100.0);
  stepper3.setSpeed(50);
  stepper3.moveTo(4072); 

 stepper4.setMaxSpeed(1000.0);
  stepper4.setAcceleration(100.0);
  stepper4.setSpeed(50);
  stepper4.moveTo(4072); 

   stepper5.setMaxSpeed(1000.0);
   stepper5.setAcceleration(100.0);
   stepper5.setSpeed(50);
   stepper5.moveTo(4072); 

   stepper6.setMaxSpeed(1000.0);
   stepper6.setAcceleration(100.0);
   stepper6.setSpeed(50);
   stepper6.moveTo(4072); 

   stepper7.setMaxSpeed(1000.0);
   stepper7.setAcceleration(100.0);
   stepper7.setSpeed(50);
   stepper7.moveTo(4072); 

   stepper8.setMaxSpeed(1000.0);
   stepper8.setAcceleration(100.0);
   stepper8.setSpeed(50);
   stepper8.moveTo(4072); 
}

void loop() {

stepper1.run();
stepper2.run();
stepper3.run();
stepper4.run();
stepper5.run();
stepper6.run();
stepper7.run();  
stepper8.run(); 


  // put your main code here, to run repeatedly:

}

I see no attached schematic, you aren't allowed to attach in your first post I believe as an spam-block precaution, so
try again?

Also where is the data on your hardware? Power supply in particular.

If the supply can provide enough current for the steppers (about 250mA each), then I expect that the Mega can't keep up with the computations.
Play a bit with max speed and acceleration values.
Leo..

Do you have the power supply Gnd connected to the Arduino Gnd?

I did similar to you, with 7 motors and a supply with motors controlled by Atmega1284P and Stepper.h library, with motors just going back and forth.
Video of it working
(http://“http://“7-motor display - YouTube””)]https://www.youtube.com/watch?v=5-9pqTQP_SQ

You could try my code and see if things are working ok. This is for 17 motors on a mega, shorten it to just 6 if you want.
I was testing for speed impact to have so many, but only had 1 28BYJ-48 motor hooked when I last ran this. millis() was being used to see how long one 360 turn took. It actually measures one full circle and back, I just did the math with calculator to see how long it was taking (7.1 seconds I think).

#include <Stepper.h> //include the function library, standard Arduino library
#define STEPS 64 // 64 steps per rev // hardware dependent
byte x;
unsigned long startTime;
unsigned long endTime;
unsigned long elapsedTime;


int speed[] = {
  270, 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, 270,
}; // speed to move motor, 540 seems to be max for these motors


int numSteps[] = {
  2048, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500,
}; // steps to move in total = distance


int countSteps[] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
}; // track how much moved


byte stepsDir[] =  {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
}; // counterclockwise or clockwise, 0 or 1


int stepSize[] = {
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
}; // how big of a step, 2,4,8,10; 16 max to look smooth


// delayed starting times for movement effect
int delayStart[] = {0, 1500, 2500, 3500, 4500, 5500, 6500, 7500, 8500, 9500, 10500, 11500, 12500, 13500, 14500, 15500,};


Stepper steppers[] = {
  {STEPS, 5, 3, 4, 2},//create the stepper0  <<< Declare the pins to use, Order here is important
  {STEPS, 6, 8, 7, 9}, //create the stepper1  <<< Order here is important
  {STEPS, 10, 12, 11, 13}, //create the stepper2  <<< Order here is important
  {STEPS, 17, 15, 16, 14}, //create the stepper3  <<< Order here is important
  {STEPS, 21, 19, 20, 18}, //create the stepper4  <<< Order here is important
  {STEPS, 22, 24, 23, 25}, //create the stepper5  <<< Order here is important
  {STEPS, 29, 27, 28, 26}, //create the stepper5  <<< Order here is important
  {STEPS, 33, 31, 32, 30}, //create the stepper7  <<< Order here is important
  {STEPS, 37, 35, 36, 34}, //create the stepper8  <<< Order here is important
  {STEPS, 41, 39, 40, 38}, //create the stepper9  <<< Order here is important
  {STEPS, 45, 43, 44, 42}, //create the stepper10  <<< Order here is important
  {STEPS, 49, 47, 48, 46}, //create the stepper11  <<< Order here is important
  {STEPS, 53, 51, 52, 50}, //create the stepper12  <<< Order here is important
  {STEPS, 57, 55, 56, 54}, //create the stepper13  <<< Order here is important
  {STEPS, 61, 59, 60, 58}, //create the stepper14  <<< Order here is important
  {STEPS, 65, 63, 64, 62},  //create the stepper15  <<< Order here is important
};


void setup()
{
  Serial.begin(115200); // initialize serial communication:
  for (x = 0; x < 16; x = x + 1) {
    //  steppers[i].whatever();  // example of using loop with this command
    steppers[x].setSpeed(speed[x]);
  }
}
void loop() {
  for (x = 0; x < 16; x = x + 1) {
    if (millis() > delayStart[x]) {
      // Motor x
      if (stepsDir[x] == 0) {
        countSteps[x] = countSteps[x] + stepSize[x];
        if (countSteps[0] == 2048){
          startTime = millis();
          Serial.println (startTime);
        }
        if (countSteps[x] >= numSteps[x]) {
          countSteps[x] = numSteps[x];
          stepsDir[x] = 1;
        }
      }


      if (stepsDir[x] == 1) {
        countSteps[x] = countSteps[x] - stepSize[x];
        if (countSteps[x] <= 0) {
          countSteps[x] = 0;
          stepsDir[x] = 0;
        }
      }


      if (stepsDir[x] == 0) {
        steppers[x].step(stepSize[x]); //move one direction
      }
      if (stepsDir[x] == 1) {
        steppers[x].step(-stepSize[x]); //move the other direction
      }
    }
  }
}