Since I have two small stepper motors (28BYJ-48) with ULN2003 modules and wanted to find out how they work, I loaded the example "Stepper_OneRevolution" into an UNO, after adjusting the steps to 64, which is according to the datasheet of the motor the number of steps per revolution.
I hooked up UNO pin 8-11 to pin 1-4 of the module, attached an external 5V power supply as well, (grounds connected) and got the motor to turn.
However, although the example states that my motor should turn forward and then backward, it did just go forward and kept going forward. I decided to switch wires backward (UNO pin 8-11 to 4-1 of the module) but that did not change anything.
And both motors and ULN2003 modules behaved the same.
The stepper library is 1.1.3
Hi, it's the standard example in the IDE, here you go and thnks for helping!
/*
Stepper Motor Control - one revolution
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
The motor should revolve one revolution in one direction, then
one revolution in the other direction.
Created 11 Mar. 2007
Modified 30 Nov. 2009
by Tom Igoe
*/
#include <Stepper.h>
const int stepsPerRevolution = 64; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
Result: 2048 steps means the shaft does not move at all, or at least not visible (understandibly so)
It seems 64 is also not correct, because the shaft moves no more than roughly 20 degrees.
But more importantly, why does it not run counterclockwise???
If that does not help my guess is that your connections are wrong.
If this was my problem I would have tried lots of variations in the number of steps to see what the effect is. The Arduino system is great for learning by doing.
I have a 28BYJ motor and I don't recall having any problems getting it to work.
2048 turns out to be correct for a complete rotation, but only works with much reduced speed : 10 instead of 60 in the example.
Still does not turn counterclockwise, although it seems to start to run in the other direction, it hesitates, then goes on clockwise
Robin,
You're absolutely right of course and I had tried various pin positions already. One I had not tried till now was moving connections up one pin. So the connection of pin 8 goes to 11, 9 to 8, 10 to 9, 11 to 10.
Result: shaft turns counterclockwise ! ................and does not reverse, but keeps going counterclockwise.
Some more experimenting: Finally: uln2003 pin 1 to UNO pin 8, 2 to 10, 3 to 9, 4 to 11.
BINGO!!
Thanks for helping Robin, I was just a bit too worried to damage things!
JB47:
Robin,
You're absolutely right of course and I had tried various pin positions already. One I had not tried till now was moving connections up one pin. So the connection of pin 8 goes to 11, 9 to 8, 10 to 9, 11 to 10.
Result: shaft turns counterclockwise ! ................and does not reverse, but keeps going counterclockwise.
Some more experimenting: Finally: uln2003 pin 1 to UNO pin 8, 2 to 10, 3 to 9, 4 to 11.
BINGO!!
There are 24 ways to connect 4 pins, and only 8 of them will work. 4 of those are cyclically equivalent and will turn it one way (for a given drive sequence), the other 4 turn it the other way.
With a 5-wire motor like this there's no obvious way to figure out the wiring except trial and error. 4-wire bipolars and 6 or 8 wire motors can be figured out with a multimeter.
Just for reference, i you have bought the Jaycar (XC-4458) or Altronics (Z6330) stepper and driver kits kit, much of the documentation with them is incorrect,so while okto wire the pins in the order shown, the Stepper instance needs the pin order changing to 8, 10, 9, 11 so the motor reverses ok.
BTW I can only get max of 15 RPM on the output shaft (not 30 as claimed by Jaycar)
see this post by Michael Schoeffler
#include <Stepper.h>
#define STEPS 2038 // the number of steps in one revolution of your motor (28BYJ-48)
Stepper stepper(STEPS, 8, 10, 9, 11);
void setup() {
// nothing to do
}
void loop() {
stepper.setSpeed(1); // 1 rpm
stepper.step(2038); // do 2038 steps -- corresponds to one revolution in one minute
delay(1000); // wait for one second
stepper.setSpeed(6); // 6 rpm
stepper.step(-2038); // do 2038 steps in the other direction with faster speed -- corresponds to one revolution in 10 seconds