2022年7月9日 星期六

電動烤串機---步進馬達

 #include <Stepper.h>
/*
28BYJ-48 步進馬達     
    28:步進馬達的有效最大外徑是 28 毫米
    B:表示是步進馬達
    Y:表示是永磁式
    J:表示是減速型(減速比1:64)
    48:表示四相八拍
28BYJ-48 步進馬達的規格如下:
    單極兩種規格:DC 5V 及 12V
    直徑:28mm
    齒輪減速比(變速箱):1/64
    定子極數:上(8+8)、下(8+8)
    轉子極數:16
    步距角度:360 / 64 x 1/64 = 0.087890625(半步模式)
    中心抽頭(紅線)與輸入引腳之間的直流電阻:21Ω
    輸出軸步數/轉 = (8x4x2) x 64 = 4096(半步模式)
    最大速度 = 15~20 rpm
半步的減速比為 64:1 表示內部馬達轉動 64 圈,外部的軸才轉動 1 圈,可以算出內部馬達轉動一圈,外部軸心轉動角度為 360º / 64 = 5.625º。
若將 5.625º 乘以減速比得到輸出的解析度為:每步旋轉 5.625 x 1/64 = 0.087890625 度。由此算出若要讓外軸轉動一圈,內部馬達需要行走 360 / 0.087890625 = 4096 步。

[ULN2003驅動板]
旋轉步進馬達通常稱為驅動,可以是波浪驅動、全步驅動、半步驅動驅動三種之一:
1.全步波浪驅動(Wave Drive)時序為:D->C->B->A ,轉一圈需要四步,一次僅驅動一個線圈工作,較少的消耗。
2.全步驅動(Full-Step Drive)時序為:AB->BC ->CD ->DA ,轉一圈需要四步,一次激勵兩個線圈,在最大扭矩下,更高的電流換來的是更高的扭矩。
3.半步驅動(Half-Step Drive)時序為:A->AB->B ->BC ->C ->CD ->D ->DA ,轉一圈需要八步,可使用半步驅動以獲得更精確的運動。
*/
// change this to the number of steps on your motor
#define STEPS 100
#define STEPS2 100
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, D5, D6, D7, D8);
Stepper stepper2(STEPS2, D1, D2, D3, D4);
// the previous reading from the analog input
int previous = 0;
int previous2 = 0;
void setup() {
  // set the speed of the motor to 30 RPMs
  stepper.setSpeed(30);
  stepper2.setSpeed(30);
}

void loop() {
  // get the sensor value
  int val = analogRead(0);
  int val2 = analogRead(0);
  // move a number of steps equal to the change in the
  // sensor reading
  stepper.step(val - previous);
  stepper2.step(val2 - previous2);
  // remember the previous value of the sensor
  previous = val;
  previous2 = val2;
}

沒有留言:

張貼留言