ULN2003 Stepper Driver - A+B Stay Lit

Hi,
I have a ULV2003 driving a 28BYJ Stepper motor (it’s the first time I’ve attempted using one of these), and am using an RF receiver and remote to be able to turn it in one direction or the other. The ‘issue’ I’m having is that when I supply power to the setup initially, the lights A,B,C & D are all off. When I press one of the buttons on the RF remote to turn the motor, all four lights illuminate, however once the motor has finished its rotation lights A+B remain on, and never go out. If I then press either of the buttons on the remote again, the motor turns as it should and lights C+D illuminate until the rotation has finished, but again lights A+B never go out. I’ve tried replacing both the motor and the driver, but still get the same issue, so am assuming a problem with my code. If anyone can tell me why these lights stay on all the time, and if there’s anything obviously wrong with the below please, I’d really appreciate it.

Physical setup:
Pins IN1 to In4 are connected to Pins 8 - 12 respectively on the Arduino, and I’m using 2 x 18650 batteries to power both the motor and the Arduino. The ± cables from the battery pack are split to go to the vcc & ground pins on the arduino (nano) and the ± pins on the ULV2003. The rf receiver is connected to 5v, gnd, and d2 pins of the arduino for vcc, gnd and signal pins respectively on the receiver.

Code:

#include <RCSwitch.h>
#include <Stepper.h>

RCSwitch mySwitch = RCSwitch();

// Define number of steps per rotation:
const int stepsPerRevolution = 2048;


// Create stepper object called 'myStepper', note the pin order:
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
 
void setup() {
  // Set the speed to 5 rpm:
  myStepper.setSpeed(5);
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
}

void loop() {
  if (mySwitch.available()) {
    
    if( mySwitch.getReceivedValue()== 10004741 ) {
      myStepper.step(stepsPerRevolution);
    }

    if( mySwitch.getReceivedValue()== 10004747 ) {
      myStepper.step(-stepsPerRevolution);
    }

    mySwitch.resetAvailable();
  }
}

Have you tried a short program that just makes the motor move - do the lights operate as expected with it?

...R

Robin2: Have you tried a short program that just makes the motor move - do the lights operate as expected with it?

...R

Hi Robin2, Thanks, I have, I tried the example sketch for the stepper library and get the same results.

Robin2: Have you tried a short program that just makes the motor move - do the lights operate as expected with it?

...R

Hi Robin2, Thanks, I have, I tried the example sketch for the stepper library and get the same results.

mrtheduke: Thanks, I have, I tried the example sketch for the stepper library and get the same results.

I presume that means that the lights A and B stay on?

Does the motor move properly?

How do the lights behave if you get the motor to move very slowly?

...R

Yes, indeed, A+B remained on. Just checked when running at a speed of 1, and the lights flash in sequence (flash quite fast, but looks like A, B, C, D for the duration of the rotation), and then A+B remain illuminated as before. The motor turns as intended in both directions

I've amended the code to set the pins to low once the rotation has finished, and this prevents A+B from remaining illuminated. Feels like a bit of a botch though, would be good to figure out why they remain on without this.

mrtheduke: Yes, indeed, A+B remained on. Just checked when running at a speed of 1, and the lights flash in sequence (flash quite fast, but looks like A, B, C, D for the duration of the rotation), and then A+B remain illuminated as before.

This is still confusing. It now reads as if the lights flash in sequence when the motor is moving and the A + B lights stay on when the motor stops. Is that correct?

...R

Sounds entirely plausible if its running half-step mode, the sequence would be something like:

A A+B B B+C C C+D D D+A A A+B

and if it always stops at the same point in the sequence you'd always see the same LEDs lit at the end.

Since 2048 is a multiple of 8 it will always stop at the same point.