Arduino 21 - Stepper Motor步进电机实验

步进电机是一种将电脉冲转化为角位移的执行机构。通俗一点讲:当步进驱动器接收到一个脉冲信号,它就驱动步进电机按设定的方向转动一个固定的角度(及步进角)。你可以通过控制脉冲个数来控制角位移量,从而达到准确定位的目的;同时你也可以通过控制脉冲频率来控制电机转动的速度和加速度,从而达到调速的目的。

下面这个就是本次实验使用的步进电机

使用步进电机前一定要仔细查看说明书,确认是四相还是两相,各个线怎样连接,本次实验使用的步进电机是四相的,不同颜色的线定义如下图:

减速步进电机

  • 直径:28mm
  • 电压:5V
  • 步进角度:5.625 x 1/64
  • 减速比:1/64
  • 5线4相:可以用普通uln2003芯片驱动,也可以接成2相使用

该步进电机空载耗电在50mA以下,带64倍减速器,输出力矩比较大,可以驱动重负载,极适合开发板使用。注意:此款步进电机带有64倍减速器,与不带减速器的步进电机相比,转速显得较慢,为方便观察,可在输出轴处粘上一片小纸板。

步进电机(五线四相)驱动板(UL2003)试验板

步进电机驱动板(UL2003)试验板

外形尺寸:31×35mm

硬件连接图如下

Source Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <Stepper.h>
const int stepsPerRevolution = 64;
// 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, 8,9,10,11);
const int aInPin=A0;
int val;
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(200);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
val=analogRead(aInPin);
val=map(val,0,1023,0,99);
Serial.println(val);
// step one revolution in two direction:
if(val>50){
Serial.println("clockwise");
//原library是整步,整步走的角度是半步走的角度的两倍,半步走的声音比较小,平稳些,启动时最好是半步的走比较稳定
//022中library修改为半步模式不成功???FUCK
//四拍运行时步距角为θ=360度/(revolution*4)(俗称整步),八拍运行时步距角为θ=360度/(revolution*8)(俗称半步)
myStepper.step(stepsPerRevolution/2);//
delay(500);
}
else{
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution/2);
delay(500);
}
}
Would you mind buy me a cup of coffee?