Help needed controlling three stepper motors

57 views
Skip to first unread message

Butch Alline

unread,
Apr 25, 2025, 5:09:31 PMApr 25
to accelstepper

Goal is to control three 28BYJ-48 Unipolar, 4 wire stepper motors using generic ULN2003AN driver boards, an ESP32 Dev board, an independent 5V supply, and the Arduino IDE 2.

All motors should run continuously, simultaneously, and smoothly without pause.  Speed and direction of each motor should be independently controlled by code.  Max. speed needed is about 1 rev/3 seconds.  Min. speed should be barely susceptible 😊.

Torque load is negligible, no need for setting accelerations, and no other tasks are required in the loop function.

I have used the Arduino Stepper.h example with two steppers but each motor runs sequentially and not simultaneously.  Code below:

#include <Stepper.h>

//motor1 setup

const int stepsPerRevolution = 2048;  // change this to fit the number of steps per revolution

const int IN1 = 19;                   // ULN2003 Motor Driver Pins for motor1

const int IN2 = 18;

const int IN3 = 5;

const int IN4 = 17;

int m1Speed = 16;

Stepper motor1(stepsPerRevolution, IN1, IN3, IN2, IN4);  // initialize the stepper library

 

//motor2 setup

const int IN5 = 32;  // ULN2003 Motor Driver Pins for motor1

const int IN6 = 33;

const int IN7 = 25;

const int IN8 = 26;

int m2Speed = 8;

Stepper motor2(stepsPerRevolution, IN5, IN7, IN6, IN8);  // initialize the stepper library

 

void setup() {

  motor1.setSpeed(m1Speed);  // set the speed, zero = off, min =1, max = 19

  motor2.setSpeed(m2Speed);  // set the speed, zero = off, min =1, max = 19

}

void loop() {

  motor1.step(stepsPerRevolution);  // plus stepsPerRevolution = CW     rotation, minus stepsPerRevolution = CCW

 

  motor2.step(stepsPerRevolution);

{

 

I have used the AccelStepper example ConstantSpeed.ino with one motor, but found the speed and smoothness not acceptable.  Code below:

 

#include <AccelStepper.h>

AccelStepper stepper;  // Defaults to AccelStepper::FULL4WIRE (4 pins)

 

void setup() {

  stepper.setMaxSpeed(1000); // Speeds of more than 1000 steps per second are unreliable.

  stepper.setSpeed(340); // 350 is smooth, 360 pauses, 380 jitters

}

void loop() {

  stepper.runSpeed();

  //delay(100); // any delay reduces speed dramatically

}

 I also tried the AccelStepper example AFMotor_ConstantSpeed.pde but could not find <AFMotor.h> and do not have the Adafruit shield.

 Apologies for the formatting.  Any and all help appreciated.

 Thanks,

 Butch Alline


Jim Larson

unread,
Apr 26, 2025, 12:00:17 AMApr 26
to accelstepper
Hi Butch! Welcome to the AccelStepper Forum.

Let me first address the code you have posted.
First, the Arduino Stepper library will not do what you want. So let's focus on AccelStepper. It may or may not solve your problem.
Certainly the AFMptpr example won't work with an AFMotor shield.

To get things going, you may want to take a look at the Missing Manual and look at the examples provided.That will show you how to declare your motors and the connections to them.

Beyond saying that all three motors should run continuously, you haven't really said anything about how the motors are controlled. How and when do you change speed and direction? Knowing this will let us help you determine if AccelStepper will do what you want it to.

Please tell us more and experiment with AccelStepper some more using the examples I've linked.

         -jim

Butch Alline

unread,
Apr 30, 2025, 9:33:40 AMApr 30
to accelstepper
Found example here and used the "continuous rotation" example.
Added code for two additional motors and now have three steppers that rotate continuously, are reversible, can vary speed from 4sec/rev to glacial
- all independently.  I used an UNO,  three 28BYJ-48 Unipolar steppers, three  generic ULN2003AN driver boards, and a 5VDC regulated power supply.
The whole set up draws 470mA when running with no load.

My thanks to all who responded and a special thanks to Geoff Smith for his help and patience.

Butch
Message has been deleted

gjgsm...@gmail.com

unread,
Apr 30, 2025, 9:04:06 PMApr 30
to accelstepper

No problem Butch, glad I could help.

BTW, if you are wanting more examples, the the place to look is the Arduino app under ‘Examples’ where the Accelstepper library  Continuous Rotation example can also be found.

For anybody else, some interesting things about the 28BYJ-48 Unipolar stepper/ULN2003AN driver combo are:

- If the pin assignments are not given valid pin numbers for the MCU board in use it will not turn  (seems obvious I know). So if you create multiple Accelstepper stepper objects and are testing only one stepper, all the pin assignments have to be correct not just the stepper being tested for it to work.

- There are a couple of motor wiring combinations that don’t pulse the coils correctly and so if the motor doesn’t turn initially some of the wires may need to be swapped around. Some combinations will simply change the direction of rotation.

- The 28BYJ-48 Unipolar stepper appears to have a top speed limitation.
 MAX stepper Speed ≈ 568 steps/s. (3.6 sec/rev) per revolution.  The ULN2003 itself can handle much higher pulse rates; the motor’s inductance, winding resistance, and mechanical inertia probably set the real ceiling for stepper max speed. The motor (5v power) will not turn at the higher speed of 3 sec/rev. A digital driver and/or higher voltage may turn it faster.

Reply all
Reply to author
Forward
0 new messages