一.系统概述
使用ESP8266作为主控,驱动是ULN2003A,驱动五线四相步进电机。
(1)五相步进电机工程图
(2)驱动电路原理图
二.代码部分
#define D1 5
#define D2 4
#define D3 0
#define D4 2
#define DSD 5
void setup() {
// put your setup code here, to run once:
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
pinMode(0,OUTPUT);
pinMode(2,OUTPUT);
pinMode(14,INPUT_PULLUP);
pinMode(12,INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(14)!=1)
{
clockward90();
}
if(digitalRead(12)!=1)
{
cclockward90();
}
}
void clockward90(){
for(int i=1;i<=128;i++)
{
delay(DSD);
phaseA();
delay(DSD);
phaseAB();
delay(DSD);
phaseB();
delay(DSD);
phaseBC();
delay(DSD);
phaseC();
delay(DSD);
phaseCD();
delay(DSD);
phaseD();
delay(DSD);
phaseDA();
}
phaseZero();
}
void cclockward90(){
for(int i=1;i<=128;i++)
{
delay(DSD);
phaseDA();
delay(DSD);
phaseD();
delay(DSD);
phaseCD();
delay(DSD);
phaseC();
delay(DSD);
phaseBC();
delay(DSD);
phaseB();
delay(DSD);
phaseAB();
delay(DSD);
phaseA();
}
phaseZero();
}
void phaseA(){
digitalWrite(5,HIGH);
digitalWrite(4,LOW);
digitalWrite(0,LOW);
digitalWrite(2,LOW);
}
void phaseB(){
digitalWrite(5,LOW);
digitalWrite(4,HIGH);
digitalWrite(0,LOW);
digitalWrite(2,LOW);
}
void phaseC(){
digitalWrite(5,LOW);
digitalWrite(4,LOW);
digitalWrite(0,HIGH);
digitalWrite(2,LOW);
}
void phaseD(){
digitalWrite(5,LOW);
digitalWrite(4,LOW);
digitalWrite(0,LOW);
digitalWrite(2,HIGH);
}
void phaseAB(){
digitalWrite(5,HIGH);
digitalWrite(4,HIGH);
digitalWrite(0,LOW);
digitalWrite(2,LOW);
}
void phaseBC(){
digitalWrite(5,LOW);
digitalWrite(4,HIGH);
digitalWrite(0,HIGH);
digitalWrite(2,LOW);
}
void phaseCD(){
digitalWrite(5,LOW);
digitalWrite(4,LOW);
digitalWrite(0,HIGH);
digitalWrite(2,HIGH);
}
void phaseDA(){
digitalWrite(5,HIGH);
digitalWrite(4,LOW);
digitalWrite(0,LOW);
digitalWrite(2,HIGH);
}
void phaseZero(){
digitalWrite(5,LOW);
digitalWrite(4,LOW);
digitalWrite(0,LOW);
digitalWrite(2,LOW);
}
三.工作情况
实验情况:工作稳定,满足需要。电机很便宜,工作也很稳定。就是转的有点慢。文章来源:https://www.toymoban.com/news/detail-558666.html
每次按下按钮,步进电机顺时针/逆时针旋转90°,接下来步进电机的所有输入INT引脚打高,步进电机内部线圈此时不通过电流,来减小步进电机在待机状态下的发热。文章来源地址https://www.toymoban.com/news/detail-558666.html
到了这里,关于ESP8266驱动五线四相步进电机的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!