BYJ48-StepperMotor_ULN2003Driver

Stepper Motor + ULN2003 Driver Module 구입하기>>

28BYJ-48 – 5V Stepper Motor Spec

  • Rated voltage : 5VDC
  • Number of Phase 4
  • Speed Variation Ratio 1/64
  • Stride Angle 5.625° /64
  • Frequency 100Hz
  • DC resistance 50Ω±7%(25℃)
  • Idle In-traction Frequency > 600Hz
  • Idle Out-traction Frequency > 1000Hz
  • In-traction Torque >34.3mN.m(120Hz)
  • Self-positioning Torque >34.3mN.m
  • Friction torque 600-1200 gf.cm
  • Pull in torque 300 gf.cm
  • Insulation grade A

Stepper Motor Driver Module

ULN2003-StepperMotorDriverModule

Stepper Motor Switching Sequence

StepperMotor-SwitchingSequence

Arduino — ULN2003 Driver — Stepper Motor Connection

ULN2003-StepperMotor-Circuit

Calculate the steps of the stepper motor

This Motor has a Gear ratio of 64 , and Stride Angle 5.625°, so this motor has a 4096 Steps .

 steps = Number of steps in One Revolution x Gear ratio   .

 steps= (360°/5.625°) x 64 "Gear ratio" = 64 x 64 =4096 

BYJ48 Stepper motor Connect

  ULN2003 --- Arduino Uno
  ========   ============== 
  IN1 >> D8
  IN2 >> D9
  IN3 >> D10
  IN4 >> D11
  VCC ... 5V Prefer to use external 5V Source
  Gnd

  ULN2003 --- ESP-12F(WeMos D1 mini)
  ========   =======================
  IN1 >> GPIO 14 (D5)
  IN2 >> GPIO 12 (D6)
  IN3 >> GPIO 13 (D7)
  IN4 >> GPIO 15 (D8)
  VCC(+) >> ... 5V Prefer to use external 5V Source
  Gnd(-) >> GND (G)

ESP8266-BYJ48-StepperMotor_ULN2003Driver

ESP8266 Arduino Sketch

ESP8266_BYJ48_Stepper_Motor.ino

/*
  BYJ48 Stepper motor  Connect :
  ULN2003 --- Arduino Uno
  ========   ============== 
  IN1 >> D8
  IN2 >> D9
  IN3 >> D10
  IN4 >> D11
  VCC ... 5V Prefer to use external 5V Source
  Gnd

  ULN2003 --- ESP-12F(WeMos D1 mini)
  ========   =======================
  IN1 >> GPIO 14 (D5)
  IN2 >> GPIO 12 (D6)
  IN3 >> GPIO 13 (D7)
  IN4 >> GPIO 15 (D8)
  VCC(+) >> ... 5V Prefer to use external 5V Source
  Gnd(-) >> GND (G)

*/

// Arduino UNO Pins:
//#define IN1 8
//#define IN2 9
//#define IN3 10
//#define IN4 11

// ESP-12F(WeMos D1 mini)
#define IN1 14 //GPIO 14
#define IN2 12 //GPIO 12
#define IN3 13 //GPIO 13
#define IN4 15 //GPIO 15

const int NBSTEPS = 4095;
const int STEPTIME = 900;
int Step = 0;
boolean Clockwise = true;

int arrayDefault[4] = {LOW, LOW, LOW, LOW};

int stepsMatrix[8][4] = {
  {LOW, LOW, LOW, HIGH},
  {LOW, LOW, HIGH, HIGH},
  {LOW, LOW, HIGH, LOW},
  {LOW, HIGH, HIGH, LOW},
  {LOW, HIGH, LOW, LOW},
  {HIGH, HIGH, LOW, LOW},
  {HIGH, LOW, LOW, LOW},
  {HIGH, LOW, LOW, HIGH},
};

unsigned long lastTime = 0L;
unsigned long time = 0L;

void writeStep(int outArray[4]);
void stepper();
void setDirection();

void setup() {
  //Arduino UNO
  //Serial.begin(9600);

  //ESP8266 
  Serial.begin(115200);
  Serial.println("Starting...");
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
}

void loop() {
  unsigned long currentMicros;
  int stepsLeft = NBSTEPS;
  time = 0;
  lastTime = micros();
  while (stepsLeft > 0) {
    currentMicros = micros();
    if (currentMicros - lastTime >= STEPTIME) {
      stepper();
      time += micros() - lastTime;
      lastTime = micros();
      stepsLeft--;
    }
    delay(1);
  }
  Serial.println(time);
  Serial.println("Wait...!");
  delay(2000);
  Clockwise = !Clockwise;
  stepsLeft = NBSTEPS;
}

void writeStep(int outArray[4]) {
  digitalWrite(IN1, outArray[0]);
  digitalWrite(IN2, outArray[1]);
  digitalWrite(IN3, outArray[2]);
  digitalWrite(IN4, outArray[3]);
}

void stepper() {
  if ((Step >= 0) && (Step < 8)) {
    writeStep(stepsMatrix[Step]);
  } else {
    writeStep(arrayDefault);
  }
  setDirection();
}

void setDirection() {
  (Clockwise == true) ? (Step++) : (Step--);

  if (Step > 7) {
    Step = 0;
  } else if (Step < 0) {
    Step = 7;
  }
}

Leave a Reply