ESP8266驱动五线四相步进电机

一.系统概述
使用作为主控 , 驱动是 , 驱动五线四相步进电机 。
(1)五相步进电机工程图

ESP8266驱动五线四相步进电机

文章插图
(2)驱动电路原理图
二.代码部分
#define D1 5#define D2 4#define D3 0#define D4 2#define DSD 5void 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);}
ESP8266驱动五线四相步进电机

文章插图
三.工作情况
实验情况:工作稳定,满足需要 。电机很便宜,工作也很稳定 。就是转的有点慢 。
【ESP8266驱动五线四相步进电机】每次按下按钮,步进电机顺时针/逆时针旋转90°,接下来步进电机的所有输入INT引脚打高 , 步进电机内部线圈此时不通过电流,来减小步进电机在待机状态下的发热 。