can stepper library run a 28BYJ-48 in reverse?

Hi,

I am trying to run a 28BYJ-48 stepper motor with driver board from a nano using the stepper library.

The motor only turns in 1 direction, regardless of the sign of the steps argument "myStepper.step(steps). This is my code:

#include <Stepper.h>
int rotate = 0;
char h = '0';
int turn = 0;
const int stepsPerRevolution = 64;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  Serial.begin(9600);
  myStepper.setSpeed(40);
}

void loop() 
{

// check for serial input:
//-------------------------------------------------------------------------------------------

  if (Serial.available())
  {
    h = Serial.read();
    Serial.print("byte received = ");
    Serial.println(h);
  }
  
// if turn selected then determine direction and turn.  Turn off outputs when done.
//--------------------------------------------------------------------------------------------
  if (turn == 1)
  {    
    Serial.println("positive rotation");
    if(rotate == 1)
    {
      Serial.println("rotate = 1");
      myStepper.step(stepsPerRevolution*5);
      digitalWrite(8, 0);
      digitalWrite(9, 0);
      digitalWrite(10, 0);
      digitalWrite(11, 0);
      rotate=0;
    }

    if(rotate == -1)
    {
      Serial.println("rotate = -1");
      myStepper.step(-stepsPerRevolution*5);
      digitalWrite(8, 0);
      digitalWrite(9, 0);
      digitalWrite(10, 0);
      digitalWrite(11, 0);
      rotate=0;
    }
    turn = 0;
  }

// if serial received then set up driver direction:
//-------------------------------------------------------------------------------------------

  if (h == '1')
  {
    Serial.println("positive rotation selected");
    h = 0;
    turn = 1;
    rotate = 1;
  }
  
  if (h == '2')
  {
    Serial.println("negative rotation selected");
    h = 0;
    turn = 1;
    rotate = -1;
  }
}

The motor is a 5 wire unipolar design. I have 2 of them and 2 different driver boards. One is from SeeedStudio (here) the other from Ebay, the motors look the same but the drivers boards look different. I have tried lots of combinations of connections to figure this out. I tried each motor with each driver board. Then, I tried switching the logic inputs to the driver board in every possible combination. For every test I did, the motor only turns in the same direction, at the same speed, even when the code has a negative step argument.

The driver IC is the ULN2003A TI darlington array on both driver boards. I don’t understand the type of stepper this represents to the nano, because a unipolar stepper has 5 wires, but somehow the driver only needs 4 wires as an input.

Has anyone successfully run these in reverse with a negative step argument? Should this be possible? It looks like AccelStepper night do it from other info I have found but there seems to be different versions of it, has anyone used this successfully recently with the 28BYJ-48?

Thanks

When you have a question like that the first thing to do is write a short program that does nothing else except make the motor move forwards for (say) 2 revolutions and backwards for 2 revolutions without any need for serial input or anything else. Indeed, make it even simpler - just run in one direction for a few revolutions. Then change the program so it should work in the other direction.

The short answer to your title is YES.

I am not familiar with 28byj motors. Maybe your wiring is incorrect - or your code. There are hundreds of Threads on the Forum about those motors.

...R

Robin2,

Thanks for your reply and advice. I did get it to work as expected using the AccelStepper library using “myStepper.move(steps)” when ‘steps’ was - it did move in the opposite direction. And I did find some great documentation on the motor including this page I HIGHLY reccomend (one of the best Arduino related “documentaries” I have seen (here)

perigalacticon:
I did get it to work as expected

Glad to hear you have solved the problem.

…R