Arduino + Stepper Motor(28BYJ-48) + Motor Driver(ULN2003AN)

Introduction: Arduino + Stepper Motor(28BYJ-48) + Motor Driver(ULN2003AN)

In this instructable we are going to make this stepper motor work using Arduino.

Step 1: Connect SM to MD

Connect the stepper motor to the motor drivers.

Step 2: Create Some Jumper-to-DuPont Wires.

Solder them together, make sure they are not too short.

Step 3: Connect Ground (left) & Power (right).

Orient them so they fit snuggly.

Step 4: Connect Them to Arduino

5V & Ground.

Step 5: Make Some More Jumper-to-DuPont Wires!

Or just use a female to male dupont wire? But I didn't had any.

Step 6: Connect Them to the Motor Driver, in No Specific Order.

Step 7: Connect Them to Arduino.

IN1 - IN4 on the drivers should be connected to Arduino pins 9 to 12 in order.

IN1 - 9

IN2 - 10

etc.

Step 8: Flash the Arduino (Explained in Comments)

#define STEPPER_PIN_1 9
#define STEPPER_PIN_2 10 #define STEPPER_PIN_3 11 #define STEPPER_PIN_4 12
int step_number = 0; //current step out of 4
void setup() {
  pinMode(STEPPER_PIN_1, OUTPUT);
  pinMode(STEPPER_PIN_2, OUTPUT);
  pinMode(STEPPER_PIN_3, OUTPUT);
  pinMode(STEPPER_PIN_4, OUTPUT);
}
void loop() {
  OneStep(false); //false means the motor will go counter clockwise.
  delay(2); //every 2ms the motor will make a step, 2ms is max speed for this motor.
}
void OneStep(bool dir) {
  if (dir) { //if going clockwise
    switch (step_number) {
      case 0:
        digitalWrite(STEPPER_PIN_1, HIGH);
        digitalWrite(STEPPER_PIN_2, LOW);
        digitalWrite(STEPPER_PIN_3, LOW);
        digitalWrite(STEPPER_PIN_4, LOW);
        break;
      case 1:
        digitalWrite(STEPPER_PIN_1, LOW);
        digitalWrite(STEPPER_PIN_2, HIGH);
        digitalWrite(STEPPER_PIN_3, LOW);
        digitalWrite(STEPPER_PIN_4, LOW);
        break;
      case 2:
        digitalWrite(STEPPER_PIN_1, LOW);
        digitalWrite(STEPPER_PIN_2, LOW);
        digitalWrite(STEPPER_PIN_3, HIGH);
        digitalWrite(STEPPER_PIN_4, LOW);
        break;
      case 3:
        digitalWrite(STEPPER_PIN_1, LOW);
        digitalWrite(STEPPER_PIN_2, LOW);
        digitalWrite(STEPPER_PIN_3, LOW);
        digitalWrite(STEPPER_PIN_4, HIGH);
        break;
    }
  } else { //go anti clockwise
    switch (step_number) {
      case 0:
        digitalWrite(STEPPER_PIN_1, LOW);
        digitalWrite(STEPPER_PIN_2, LOW);
        digitalWrite(STEPPER_PIN_3, LOW);
        digitalWrite(STEPPER_PIN_4, HIGH);
        break;
      case 1:
        digitalWrite(STEPPER_PIN_1, LOW);
        digitalWrite(STEPPER_PIN_2, LOW);
        digitalWrite(STEPPER_PIN_3, HIGH);
        digitalWrite(STEPPER_PIN_4, LOW);
        break;
      case 2:
        digitalWrite(STEPPER_PIN_1, LOW);
        digitalWrite(STEPPER_PIN_2, HIGH);
        digitalWrite(STEPPER_PIN_3, LOW);
        digitalWrite(STEPPER_PIN_4, LOW);
        break;
      case 3:
        digitalWrite(STEPPER_PIN_1, HIGH);
        digitalWrite(STEPPER_PIN_2, LOW);
        digitalWrite(STEPPER_PIN_3, LOW);
        digitalWrite(STEPPER_PIN_4, LOW);
    }
  }
  step_number++;
  
  if (step_number > 3) {
    step_number = 0;
  }
}

Be the First to Share

    Recommendations

    • Puzzles Speed Challenge

      Puzzles Speed Challenge
    • "Can't Touch This" Family Contest

      "Can't Touch This" Family Contest
    • CNC Contest 2020

      CNC Contest 2020

    2 Discussions

    0
    themikmik28
    themikmik28

    8 months ago

    Riddled with errors in code and never actually showed us the motor spinning? and Dont hook up DC step motor directly to your out PINS, great way to burn up your arduino, instead use the power PINS with external source to drive the motor, if you don't use his code.

    0
    audreyobscura
    audreyobscura

    1 year ago

    Cool! What do you plan to drive with this motor?