2019年3月7日 星期四

[Arduino]步進馬達實驗


好久沒來寫一下心得了

今天難得比較早下班,火速看一下別人的文章,

並且操作這個作業

以下為新北中山國中創客社群的文章來源為此

寫得很棒!!

28BYJ-48 步進馬達


1.外觀與尺寸
28BYJ-48 步進馬達有兩種規格 5V 與 12V ,尺寸大小都相同,但扭矩12V比5V稍大
通常可以由如下兩種驅動器ULN2003驅動(驅動器也同時支援5V與12V)

        

尺寸與規格表(尺寸可供3D列印設計時採用)


關於更詳細的測試請參閱   5V與12V的比較



3.內部齒輪比
(1) Adafruit gear train
(2)RioRand gear train
(3)一般版

       #1  teeth: 9     #2 In:32 Out:11     #3 In:22 Out:9       #4 In:27 Out:8              #5 In:24 

減速比 64:1       (輸入圈數:輸出圈數)    


由上可知,若馬達步進角 5.625度 再乘以減速比得到輸出的解析度:
每步旋轉 5.625 x 1/64 = 0.087890625 度
若要轉一圈,需要  360/0.087890625 = 4096步


4.線路布置
28BYJ-48 步進馬達屬於四相五線步進馬達,
四相代表四組線圈 五線代表接出五條線

5.驅動法方為三種,每一種各有其優點與缺點,詳述如下

(1)一相激磁(優點:省電 缺點:轉矩小、轉速慢)
一相激磁驅動法,一圈需要2048步

int t= 10;

void setup() {
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
}

void loop() {
digitalWrite(8,1);
digitalWrite(9,0);
digitalWrite(10,0);
digitalWrite(11,0);
delay(t);

digitalWrite(8,0);
digitalWrite(9,1);
digitalWrite(10,0);
digitalWrite(11,0);
delay(t);

digitalWrite(8,0);
digitalWrite(9,0);
digitalWrite(10,1);
digitalWrite(11,0);
delay(t);

digitalWrite(8,0);
digitalWrite(9,0);
digitalWrite(10,0);
digitalWrite(11,1);
delay(t);

}

這是我的作業阿~~~很弱




(2)二相激磁 (優點:轉矩大 缺點:轉速慢、耗電)
二相激磁驅動法,一圈需要2048步

int t= 5;

void setup() {
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
}

void loop() {
digitalWrite(8,1);
digitalWrite(9,1);
digitalWrite(10,0);
digitalWrite(11,0);
delay(t);

digitalWrite(8,0);
digitalWrite(9,1);
digitalWrite(10,1);
digitalWrite(11,0);
delay(t);

digitalWrite(8,0);
digitalWrite(9,0);
digitalWrite(10,1);
digitalWrite(11,1);
delay(t);

digitalWrite(8,1);
digitalWrite(9,0);
digitalWrite(10,0);
digitalWrite(11,1);
delay(t);

}

依然是弱弱的作業,我的t設定為10,轉速看不出來差別


或者是直接使用內建的函式庫
#include <Stepper.h>

const int stepsPerRevolution = 2048;  
// change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 4, 6, 7, 5);
/*
pin腳接法
IN1=4
IN2=6
IN3=7
IN4=5
*/

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(5);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
}


(3)一二相激磁(優點:精度提升2倍,可高轉速)

一二相激磁驅動法,一圈需要4096步

int t= 1;

void setup() {
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
}

void loop() {
digitalWrite(8,1);
digitalWrite(9,0);
digitalWrite(10,0);
digitalWrite(11,0);
delay(t);

digitalWrite(8,1);
digitalWrite(9,1);
digitalWrite(10,0);
digitalWrite(11,0);
delay(t);

digitalWrite(8,0);
digitalWrite(9,1);
digitalWrite(10,0);
digitalWrite(11,0);
delay(t);

digitalWrite(8,0);
digitalWrite(9,1);
digitalWrite(10,1);
digitalWrite(11,0);
delay(t);

digitalWrite(8,0);
digitalWrite(9,0);
digitalWrite(10,1);
digitalWrite(11,0);
delay(t);

digitalWrite(8,0);
digitalWrite(9,0);
digitalWrite(10,1);
digitalWrite(11,1);
delay(t);

digitalWrite(8,0);
digitalWrite(9,0);
digitalWrite(10,0);
digitalWrite(11,1);
delay(t);

digitalWrite(8,1);
digitalWrite(9,0);
digitalWrite(10,0);
digitalWrite(11,1);
delay(t);

}

弱弱作業來也




或者是

int t= 1000;
boolean a[]={1,1,0,0,0,0,0,1};
boolean b[]={0,1,1,1,0,0,0,0};
boolean c[]={0,0,0,1,1,1,0,0};
boolean d[]={0,0,0,0,0,1,1,1};

void setup() {
Serial.begin(115200);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
}

void loop() {

for(int i=0; i<8 ; i++){
digitalWrite(8,a[i]);
digitalWrite(9,b[i]);
digitalWrite(10,c[i]);
digitalWrite(11,d[i]);
delayMicroseconds(t);
Serial.println(i);

}

}

沒有留言:

張貼留言

[Sensor]MPU92/65

MPU92/65是很久以前買的感測器 基本上有加速度計、陀螺儀、電子羅盤、溫度計 以下是該電子商城的介紹 https://www.factoryforward.com/product/gy-87-mpu-9265-3-axis-9-dof-attitude-gyro-magnet...