2

I am brand new to Arduino but have good experience with Raspberry Pi's and Microchips.

My problem is that I am having trouble driving many stepper motors at once. I am using the AccelStepper library(https://www.airspayce.com/mikem/arduino/AccelStepper/index.html). The code is pretty simple and I got it to work perfectly for a long time with three motors, however it had trouble running more than three motors, I have 5 motors hooked up right now and all of them vibrate or skip steps.

Can anyone help me get the 5 motors working.

Here is the code I'm running:

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

AccelStepper stepper1(AccelStepper::FULL4WIRE, 8, 10, 9, 11);
AccelStepper stepper2(AccelStepper::FULL4WIRE, 4, 5, 6, 7);
AccelStepper stepper3(AccelStepper::FULL4WIRE, 12, 13, 2, 3);
AccelStepper stepper4(AccelStepper::FULL4WIRE, A0, A1, A2, A3);
AccelStepper stepper5(AccelStepper::FULL4WIRE, 0, 1, A4, A5);

void setup()
{  
    //Serial.begin(9600);
    pinMode(0, OUTPUT);
    pinMode(1, OUTPUT);
    pinMode(A0, OUTPUT);
    pinMode(A1, OUTPUT);
    pinMode(A2, OUTPUT);
    pinMode(A3, OUTPUT);
    pinMode(A4, OUTPUT);
    pinMode(A5, OUTPUT);
    Serial.print(" a0:");
    Serial.print(digitalRead(A0));
    stepper1.setMaxSpeed(600.0);
    stepper1.setAcceleration(50.0);
    stepper1.moveTo(3240);
    
    stepper2.setMaxSpeed(50);
    stepper2.setAcceleration(1);
    stepper2.moveTo(800);
    
    stepper3.setMaxSpeed(300.0);
    stepper3.setAcceleration(200.0);
    stepper3.moveTo(1500); 

    stepper4.setMaxSpeed(300.0);
    stepper4.setAcceleration(200.0);
    stepper4.moveTo(1500000);

    stepper5.setMaxSpeed(300.0);
    stepper5.setAcceleration(200.0);
    stepper5.moveTo(1500000);
}
void loop()
{
    // Change direction at the limits
    
    if (stepper1.distanceToGo() == 0)
        stepper1.moveTo(-stepper1.currentPosition());
    if (stepper2.distanceToGo() == 0)
        stepper2.moveTo(-stepper2.currentPosition());
    if (stepper3.distanceToGo() == 0)
        stepper3.moveTo(-stepper3.currentPosition());
    if (stepper4.distanceToGo() == 0)
        stepper4.moveTo(-stepper4.currentPosition());
    if (stepper5.distanceToGo() == 0)
        stepper5.moveTo(-stepper5.currentPosition());
    stepper1.run();
    stepper2.run();
    stepper3.run();
    stepper4.run();
    stepper5.run();
}

I don't think it is the code that is the problem because as I stated before it worked with three motors just fine and the code for 4 and 5 is just copy paste.

I think it could be a power problem, I have a wall outlet that can convert to a range of dc voltages between 3 and 12, at 5V the motors are clearly lacking the power to run. At 6V they do turn on but dont work well at all(as I stated above) and at 7.5V the Arduino seems to continually restart: the motors start for just a second.

Here are the 28BYJ-48 motors with drivers I bought from amazon: https://www.amazon.com/gp/product/B01CP18J4A/ref=ppx_yo_dt_b_asin_title_o02_s00?ie=UTF8&psc=1

Can anyone explain to me why it restarts at 7.5 volts? I've read that the minimum power should be around 7 volts so this doesn't make sense to me.

Appreciate any help I can get, please remember I'm new to this. Thank you.

6
  • 1
    How is this all wired up? How much power can your supply deliver and how much do the motors need? – Mat Apr 29 at 15:10
  • @Mat The motors connect to the drivers plug-and-play and the wiring from the drivers to the board can be seen in lines 4-7 of the code. The power to the boards is gotten from the 5V pin of the Arduino and the ground is also from the Arduino. Amazon states that the motors are rated at 5V. Finally Mat if you read my paragraph above you can see how my power supply works – KidWithComputer Apr 29 at 15:15
  • 1
    You're only talking volts. That's not enough, you need amps too to deliver watts (i.e. power). – Mat Apr 29 at 15:17
  • pins 0 and 1 are used for Serial – jsotola Apr 29 at 15:53
  • @jsotla, they are only used for serial if you have a serial begin statement in your code – KidWithComputer Apr 29 at 16:00

Your Answer

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

Browse other questions tagged or ask your own question.