[Solved] Example stepper sketches and 28BYJ-48 motor with ULN2003 Board

I'm completely flummoxed since neither the stepper_OneStepAtATime nor the stepper_OneRevolution work the way I expected.

Motor and board is this one http://www.geeetech.com/wiki/index.php/Stepper_Motor_5V_4-Phase_5-Wire_%26_ULN2003_Driver_Board_for_Arduino

I got to the stage of producing my own version of the stepper_oneRevolution sketch, and found by a bit of trial and error that

  1. I could get the motor to complete one complete revolution, clockwise, using 2048 steps instead of 64. It takes 30 seconds to do so
    2)If I make the number of steps negative, it still goes clockwise
    Addendum - forgot to add that if stepsperrevolution is set to 2048 as well, then the motor does not move at all! And the motor power is a separate 6-volt supply fed into the controller board.

I've checked and double checked all connections, and even tried reversing the connections between the Arduino pins and the controller board, this makes no difference

My arduino is the Uno R3 and my version of the sketch is below

Any ideas?

/* 
 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
const int motorpin1 = 8;
const int motorpin2 = 9;
const int motorpin3 = 10;
const int motorpin4 = 11;
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, motorpin1,motorpin2,motorpin3,motorpin4);            

void setup() {
// Introduce setting of pins as output - not in original code. RESULT - made no fifference
  pinMode(motorpin1, OUTPUT);   // set the digital pins as output:
  pinMode(motorpin2, OUTPUT);
  pinMode(motorpin3, OUTPUT);
  pinMode(motorpin4, OUTPUT);
 
  // 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(-64);          //simply changing this to a negative number makes no difference to direction, always goes clockwise

    myStepper.step(2048);        //2048 does do a full circle, and takes 30 seconds. -2048 still goes clockwise 4096 seems to do 2 revolutions                 
  delay(1000);
  
   // step one revolution in the other direction:
//  Serial.println("counterclockwise");
//  myStepper.step(-stepsPerRevolution);
//  delay(1000); 
}

It's always fascinating when people refer to problems with code but don't bother to provide the code or a link to it. But it's not very useful.

There seems to be good information in that link which should enable you to write some working code. All that's needed is to energize the wires in the right order.

It might be worth looking at the AccelStepper library. I haven't used it but it seems to cover a wide range of stepper drivers.

Driver boards like the ULN2003 make controlling a stepper very complicated compared to a proper stepper driver - for example the Pololu A4988 - which just require step and direction outputs from the Arduino. However I don't think the A4988 will work with 5-wire motors.

...R

Well, a bit of googling revealed this 4tronix Arduino , copying his code seems to work.

All I have to do now is understand why!

Robin2 - thanks for the reply but I'm not sure what you're getting at? I did provide my version of one of the samples supplied with the IDE, "butchered" to try and isolate what was happening. Oh well ...

At the top of the code you posted it said it was last modified in 2009 - so I assumed it was not the code you had developed.

...R

well, I think I understand what was going wrong at last - having eliminated a hardware problem by using the 4tronix script.

I'll have a look at the AccelStepper library Robin, in the meantime this link http://arduino-info.wikispaces.com/SmallSteppers (oops - added 23/1 :blush:) explains why I had problems with the steps-per-revolution using the example sketches provided with the IDE. Something to move forward with!

Addendum - in the meantime I've included the sketch I've produced using the information gleaned, enabling me to control motor movement using the Arduino stepper library and information from this source : http://arduino-info.wikispaces.com/SmallSteppers , from which the motor details section is especially enlightening

/* 
 Stepper Motor Control 
 
B Version - change to "Firing Sequence 1-3-2-4" and change speed to 200
  RESULT: Full turn in 8 seconds instead of 30 at speed of 30. Try speed 300? no faster
  
C Version - re-jig from Yourduino example "Yourduino1"
 
 */

#include <Stepper.h>

const int stepsPerMotorRevolution = 32;  //No of steps per internal revolution of motor,
                                         //4-step mode as used in Arduino Stepper library
                                     
const int stepsPerOutputRevolution = 32*64; //no of steps per revolution of the output shaft

const int motorpin1 = 8;                    //Assign motor (ie board) pins to Arduino pins
const int motorpin2 = 9;                    //
const int motorpin3 = 10;                   //
const int motorpin4 = 11;                   //

// initialize the stepper library on pins 8 through 11, Motor rev steps, "Firing" sequence 1-3-2-4, 
Stepper myStepper(stepsPerMotorRevolution, motorpin1,motorpin3,motorpin2,motorpin4);            

void setup() {
// Stepper library sets pins as output
 
  myStepper.setSpeed(200);                 //Set the speed
  Serial.begin(9600);                      // initialize the serial port:

}
//                                          MAIN LOOP +++++++++++++++++++
void loop() {
  // step one revolution  in one direction:
   Serial.println("clockwise");
   myStepper.step(stepsPerOutputRevolution);                           
   delay(1000);
  
   // step one revolution in the other direction:
   Serial.println("counterclockwise");
   myStepper.step(-stepsPerOutputRevolution);
   delay(1000); 
   
   // Quarter revolution clockwise
   Serial.println("clockwise 1/4 rev");
   myStepper.step(stepsPerOutputRevolution/4);                           
   delay(1000);
   
   // Half revolution counterclockwise
   Serial.println("counterclockwise clockwise 1/2 rev");
   myStepper.step(-stepsPerOutputRevolution/2);                           
   delay(1000);
}
//                                  END OF MAIN LOOP +++++++++++++++++++++

@RMurphy195
Thank you for your post, you got me going again.
I too was having problem with the yourdino test sketch. I will still have to examine the code and library, but at least now I know the hardware is working.

Perfect thanks it was all in the firing sequence

change to "Firing Sequence 1-3-2-4"
so for the default setup
IN1 >> 8
IN2 >> 9
IN3 >> 10
IN4 >> 11

Stepper myStepper(stepsPerMotorRevolution, 8, 10, 9, 11);