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
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.