Go Down

Topic: Stepper motor example does not work? (Read 245 times) previous topic - next topic

JB47

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

Anybody who has a hint as to what I do wrong???

gcjr

post the code inside the code tags (</> icon)
greg - somerset, nj

JB47

Hi, it's the standard example in the IDE, here you go and thnks for helping!
Code: [Select]
/*
 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);
}

Robin2

The 28BYJ-48 motor comes with a gearbox so you need about 2048 steps IIRC to get the output shaft to make one revolution.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

JB47

OK Robin,
Thanks, will try that out, but it still is no explanation for it to only turn clockwise, right?
Any explanation for that?

JB47

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

Robin2

Try a much lower speed for initial tests.

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.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

JB47

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

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

Thanks for helping Robin, I was just a bit too worried to damage things!

Robin2

but only works with much reduced speed :  10 instead of 60 in the example.
Just the same as any other motor a stepper motor needs to be accelerated to higher speeds. Maybe have a look at the AccelStepper library

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

MarkT

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.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up