본문 바로가기
EmbeddedSystem/Arduino

[Arduino] Stepper motor - 28BYJ-48

by TSpoons 2024. 10. 9.

사용한 HW

아두이노 우노 R3
모터 드라이버(motor driver) : ULN2003
스텝 모터(Stepper motor) : 28BYJ-48
USB cable B (AM-BM)
 

스텝 모터(28BJY-48)

 
1. unipolar 5 wire 방식

 
 
2. Half step sequence
전력이 더 많이 소모 되지만, 더 작은 분해능으로 부드럽게 작동한다.

https://www.globalspec.com/reference/8273/348308/3-8-4-stepper-motors

 
3. 스텝 각도 (Stride Angle): 5.625도/64 (1회전 당 64스텝, 기어비로 인해 4096스텝 필요)
 

// 핀 번호 정의
const int IN1 = 8;
const int IN2 = 9;
const int IN3 = 10;
const int IN4 = 11;

// 스텝 시퀀스를 배열로 정의 (8단계 시퀀스)
const int stepSequence[8][4] = {
  {HIGH, LOW,  LOW,  LOW},
  {HIGH, HIGH, LOW,  LOW},
  {LOW,  HIGH, LOW,  LOW},
  {LOW,  HIGH, HIGH, LOW},
  {LOW,  LOW,  HIGH, LOW},
  {LOW,  LOW,  HIGH, HIGH},
  {LOW,  LOW,  LOW,  HIGH},
  {HIGH, LOW,  LOW,  HIGH}
};

void setup() {
  // 핀들을 출력으로 설정
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
}

void loop() {
  // 64번 반복하는 외부 루프
  for (int j = 0; j < 64; j++) {
    // 8단계 스텝을 반복
    for (int i = 0; i < 8; i++) {
      // 각 핀에 stepSequence의 값을 적용
      digitalWrite(IN1, stepSequence[i][0]);
      digitalWrite(IN2, stepSequence[i][1]);
      digitalWrite(IN3, stepSequence[i][2]);
      digitalWrite(IN4, stepSequence[i][3]);
      delay(1); // 딜레이 1ms
    }
  }
}

 
 

 

 * Stepper library 이용

 

#include <Stepper.h>

#define IN1 8
#define IN2 10
#define IN3 9
#define IN4 11



// 스테퍼 모터의 단계 수 (28BYJ-48 모터는 2048 스텝으로 360도 회전)
const int stepsPerRevolution = 2048; 

Stepper myStepper(stepsPerRevolution, IN1,IN2,IN3,IN4); 

void setup() {
  // 모터 속도 설정 (RPM, 분당 회전수)
  myStepper.setSpeed(15);  
  Serial.begin(9600);
  Serial.println("28BYJ-48 Stepper Motor Test");
}

void loop() {
  // 시계 방향으로 1바퀴 회전
  Serial.println("Clockwise Rotation");
  myStepper.step(stepsPerRevolution);  
  delay(500);

  // 반시계 방향으로 1바퀴 회전
  Serial.println("Counterclockwise Rotation");
  myStepper.step(-stepsPerRevolution); 
  delay(500);
}

 


 
참조:
https://coeleveld.com/arduino-stepper/
https://blog.naver.com/darknisia/221652111026