Pages

Saturday, 27 November 2021

Cheap 24BYJ01 Stepper Motor + ULM2003 + Arduino

Back in 2012 (wow, it's been almost 10 years already) I posted quickly some info about the 24BYJ01 stepper motor, mostly because this was not really the most common one in the internet and I thought it might be of some help to somebody. 

In this time I did some projects at home with this motors and arduino, but I never added extra info about them, and I think (again) that some info here might be of some help.

Now I bring you here some working code for arduino, right after the jump.


Based on the specs I had back then, the motor is the same as the much more common 28BYJ-48, but I'm not 100% sure, as trying some arduino scripts written for the 28BYJ-48, my motors were not reacting at all. 

Both motors (24BYJ01 and 28BYJ-48) can be controlled with the same ULM2003 based board, or by whatever other board that can help in driving the needed current to the different motor phases under the signals given by the arduino.

Regarding the scripts, I was not able to make them turn with the codes based on the arduino stepper.h library. I'm sure with some deeper investigation into this library one could make them work, at the end the library is able to drive the ULM2003, which means that tuning it properly should make the motor turn.

However, I did find all the scripts based on the AccelStepper.h library to work at first trial. 

I leave you here some examples I borrowed from this link.

 

// Example sketch to control a 28BYJ01 stepper motor with ULN2003 driver board, AccelStepper and Arduino UNO: continuous rotation
// Include the AccelStepper library:
#include <AccelStepper.h>
// Motor pin definitions:
#define motorPin1 8 // IN1 on the ULN2003 driver
#define motorPin2 9 // IN2 on the ULN2003 driver
#define motorPin3 10 // IN3 on the ULN2003 driver
#define motorPin4 11 // IN4 on the ULN2003 driver
// Define the AccelStepper interface type; 4 wire motor in half step mode:
#define MotorInterfaceType 8
// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper library with 28BYJ-48 stepper motor:
AccelStepper stepper = AccelStepper(MotorInterfaceType, motorPin1, motorPin3, motorPin2, motorPin4);
void setup() {
// Set the maximum steps per second:
stepper.setMaxSpeed(1000);
}
void loop() {
// Set the speed of the motor in steps per second:
stepper.setSpeed(500);
// Step the motor with constant speed as set by setSpeed():
stepper.runSpeed();
}


// Example sketch to control a 28BYJ01 stepper motor with ULN2003 driver board, AccelStepper and Arduino UNO: acceleration and deceleration
// Include the AccelStepper library:
#include <AccelStepper.h>
// Motor pin definitions:
#define motorPin1 8 // IN1 on the ULN2003 driver
#define motorPin2 9 // IN2 on the ULN2003 driver
#define motorPin3 10 // IN3 on the ULN2003 driver
#define motorPin4 11 // IN4 on the ULN2003 driver
// Define the AccelStepper interface type; 4 wire motor in half step mode:
#define MotorInterfaceType 8
// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper library with 28BYJ-48 stepper motor:
AccelStepper stepper = AccelStepper(MotorInterfaceType, motorPin1, motorPin3, motorPin2, motorPin4);
void setup() {
// Set the maximum steps per second:
stepper.setMaxSpeed(1000);
// Set the maximum acceleration in steps per second^2:
stepper.setAcceleration(200);
}
void loop() {
// Set target position:
stepper.moveTo(8192);
// Run to position with set speed and acceleration:
stepper.runToPosition();
delay(1000);
// Move back to original position:
stepper.moveTo(0);
// Run to position with set speed and acceleration:
stepper.runToPosition();
delay(1000);
}

No comments:

Post a Comment