No Motor Rotation - Stepper Motor (28BYJ-48) with ULN2003 Driver

I’ve been trying to work out this issue for over a week now. And I’m reasonably satisfied I’ve done a fair amount of research and trial and error. But the issue persists.

My setup is a Arduino Uno, a 28BYJ-48 stepper motor, a ULN2003 driver and a 5V 2A wall wart to power the stepper.

Below is the schematic I’m following.

Below is about the best photo I could get of the entire setup. The red and black wires coming in from the left are the leads of the wall wart (5V 2A).

A close up of the Arduino.

A close up of the ULN2003.

Below is my sketch. Its about as minimalistic as you can get.

#include <Stepper.h>                    //load library

#define STEPS 100                       //establish number of steps

Stepper stepper(STEPS, 8, 9, 10, 11);

void setup() {
  // put your setup code here, to run once:

stepper.setSpeed(30);                   //set speed of motor

}

void loop() {
  // put your main code here, to run repeatedly:

stepper.step(150);                      //tell stepper motor to step

}

Problem: When I load the sketch the motor either doesn’t show any life or only sits there and vibrates. All of the indicator LEDs one the ULN2003 light (and flash) aside from “D.”

Steps I’ve taken: I’ve tried two Arduino Uno’s, one Arduino Nano, and a Elegoo R3 but have not had any success. I’ve tried three different 28BYJ-48 stepper motors, two I already had and one i just bought to try and remedy the situation. And I’ve tried two different ULN2003 drivers, one I had for a while and one I just bought when I couldn’t figure out what was causing the issue. I disassemble and reassembled the wiring many times. I used my multimeter to check the voltage on the wall wart and its 5.043 vDC. And I’ve been through many code examples online. I’m running Arduino IDE 2.2.1 on a MAC Air.

Hopefully this is an easy fix but it certainly doesn't feel like it.

Thank you.

Tony

Try

Stepper stepper(STEPS, 8,10, 9, 11);

That is a good sign. You just need to find the right order to sequence the steps (or change the coil wires around, as suggested above).

This code doesn't use a library, and allows you to see which coils are activated at any one time (bits are "1" in the lookup table):

// This Arduino example demonstrates bidirectional operation of a
// 28BYJ-48, using a ULN2003 interface board to drive the stepper.
// The 28BYJ-48 motor is a 4-phase, 8-beat motor, geared down by
// a factor of 68. One bipolar winding is on motor pins 1 & 3 and
// the other on motor pins 2 & 4. The step angle is 5.625/64 and the
// operating Frequency is 100pps. Current draw is 92mA.
////////////////////////////////////////////////

//declare variables for the motor pins
int motorPin1 = 2;    // Blue   - 28BYJ48 pin 1
int motorPin2 = 3;    // Pink   - 28BYJ48 pin 2
int motorPin3 = 4;    // Yellow - 28BYJ48 pin 3
int motorPin4 = 6;    // Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)

int motorSpeed = 8;//variable to set stepper speed
int count = 0;          // count of steps made
int countsperrev = 150; // number of steps per full revolution
int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};

//////////////////////////////////////////////////////////////////////////////
void setup() {
  //declare the motor pins as outputs
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  Serial.begin(9600);
  Serial.println("stepper");
}

//////////////////////////////////////////////////////////////////////////////
void loop(){
  while (count < countsperrev ) {
    clockwise();
    count++;
  }
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 1 to 4
//delay "motorSpeed" between each pin setting (to determine speed)
void anticlockwise()
{
  for(int i = 0; i < 8; i++)
  {
    setOutput(i);
    delay(motorSpeed);
  }
}

void clockwise()
{
  for(int i = 7; i >= 0; i--)
  {
    setOutput(i);
    delay(motorSpeed);
  }
}

void setOutput(int out)
{
  digitalWrite(motorPin1, bitRead(lookup[out], 0));
  digitalWrite(motorPin2, bitRead(lookup[out], 1));
  digitalWrite(motorPin3, bitRead(lookup[out], 2));
  digitalWrite(motorPin4, bitRead(lookup[out], 3));
}

1 Like

Changing the ordering of the pins did allow the stepper motor to turn but only in one direction (changing the 512 to a negative number had no effect. The motor just vibrated as before). Also, steps per revolution were set at 2048, and the number of steps to take was set at 512 (a quarter of a full rotation I guess) but the motor kept spinning, seemingly indefinitely.

The code:

#include <Stepper.h>                    //load library

#define stepsPerRevolution 2048                     //establish number of steps

Stepper stepper(stepsPerRevolution, 8, 10, 9, 11);

void setup() {
  // put your setup code here, to run once:

stepper.setSpeed(5);                   //set speed of motor

// pinMode(8, OUTPUT);   //leaving this code in or commenting it out had no effect
// pinMode(9, OUTPUT);   //leaving this code in or commenting it out had no effect
// pinMode(10, OUTPUT);  //leaving this code in or commenting it out had no effect
// pinMode(11, OUTPUT);  //leaving this code in or commenting it out had no effect

}

void loop() {
  // put your main code here, to run repeatedly:

stepper.step(512);                      //tell stepper motor to step
delay(2);

}

Any additional thoughts are welcome.

Best,

Tony

The code you posted allows the stepper to turn for about 1/4 revolution before the ULN2003 goes dark and the motor is idle (no movement, no vibration).

It just odd that you have out of the box components, with a simple wiring schematic and two available libraries (that I know of) to simplify coding and I'm still struggling. I've written, and modified, at least a dozen sketches as well as all of the hardware substitutions and its still not working.

Thank you for contributing.

Best,

Tony

Did you really only change the pinorder in the sketch, or did you also change the wiring?
I tested your second sketch ( with the swapped pin order) and it worked fine on my test HW. With the wiring as in your fist pictures; 8,9,10,11 -> In1,In2,In3,In4.
The stepper moves in both directions ( according to the steps being a positive or negative number ).

Change the number of commanded steps (here set to 150) to be anything you like. The variable is misnamed.

int countsperrev = 150; // number of steps per full revolution

You should also try the routine to rotate counterclockwise (anticlockwise) instead of clockwise.

Those motors are sold with various wiring colors, so trial and error is often required to get the wiring correct.

28BYJ-48 using UNL2003 and power supply module. I attempted to complete a pretty standard tutorial to power the 28BYJ-48 module as a newbie and definitely NOT an electronics person. Ran into all the problems I see here and elsewhere - won't turn; partial turn; no reverse movement etc. These are the points I found or discovered to make it work just fine - non-technical:

  1. For sure any 9v battery with any kit is likely no good. Supplying my own helped BUT
  2. Even the ones I had in stock which read 9v on a multimeter were not enough.
  3. A brand NEW 9v batter helped a lot but even it soon started to lose voltage after experimenting with stepper sketches.
    4 The biggest one of all: My tutorial used Arduino pins 8,9,10,11 BUT in the sketch I missed this:
    Note the sequence. ":Stepper myStepper(stepsPerRevolution,8,10,9,11)". It is NOT 8,9,10,11. Once I changed this everything worked great.
  4. I found at least 2 120AV 9vDC chargers in my house - one for a cordless screwdriver, that should supply lots of power and have the proper jack for the included power supply module.
    I will be trying these instead of going through expensive 9v dry cells.
    Brewster
1 Like

Thank you, brewsterblock.

Quick question: in this setup, what is powering the Arduino Uno board? I only see a ground connection going into the board.

@bupedroni this is the schematic how to connect everything while the arduino is connected to the PC. the arduino is powered by the USB and you need to connect the GND of both the arduino and the motor driver. or he probably forgot to add red line in the schematic from the positive end of the power supply to the VIN pin of the arduino...

I've had absolutely no luck with the vanilla Arduino or AccelStepper stepper libraries, but your code worked perfectly for me (and helped me understand how everything is supposed to work.) Thanks @jremington - my project was at a dead end without you.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.