Translate

Kendali Motor Stepper Driver DM542 ARDUINO

Kendali Motor Stepper Driver DM542 ARDUINO


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengendalikan arah putaran motor stepper dengan menggunakan driver DM542. untuk mikrokontroler yang dipakai yaitu Arduino Nano. untuk lebih jelasnya berikut adalah koding dan skemanya. 



1. Skema









2. Program Arduino IDE

int stepPin1 = 2;
int dirPin1 = 3;
int enblPin1 = 4;

int stepPin2 = 5;
int dirPin2 = 6;
int enblPin2 = 7;

int switch1;
int switch2;
int switch3;
int switch4;
int x;

void setup() {

Serial.begin(9600);

pinMode (A0, INPUT_PULLUP);
pinMode (8, INPUT_PULLUP);
pinMode (9, INPUT_PULLUP);
pinMode (10, INPUT_PULLUP);
  
pinMode (stepPin1, OUTPUT);
pinMode (dirPin1, OUTPUT);
pinMode (enblPin1, OUTPUT);
digitalWrite(enblPin1, HIGH);

pinMode (stepPin2, OUTPUT);
pinMode (dirPin2, OUTPUT);
pinMode (enblPin2, OUTPUT);
digitalWrite(enblPin2, HIGH);
}

void loop() {

switch1 = digitalRead(A0);
switch2 = digitalRead(8);
switch3 = digitalRead(9);
switch4 = digitalRead(10);

Serial.print(switch1);
Serial.print("/");
Serial.print(switch2);
Serial.print("/");
Serial.print(switch3);
Serial.print("/");
Serial.println(switch4);

if((switch1 == 1)&&(switch2 == 1)&&(switch3 == 1)&&(switch4 == 1)){
//stop  
digitalWrite(enblPin1, LOW);
digitalWrite(enblPin2, LOW);

digitalWrite(stepPin1, LOW);
delayMicroseconds(700);
digitalWrite(stepPin1, LOW);
delayMicroseconds(700);

digitalWrite(stepPin2, LOW);
delayMicroseconds(700);
digitalWrite(stepPin2, LOW);
delayMicroseconds(700);
}

if((switch1 == 0)&&(switch2 == 1)&&(switch3 == 1)&&(switch4 == 1)){
//motor1 CW  
digitalWrite(enblPin1, HIGH);
digitalWrite(dirPin1, HIGH);
for(x = 0; x < 400; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(700);
digitalWrite(stepPin1, LOW);
delayMicroseconds(700);
}
}

if((switch1 == 1)&&(switch2 == 0)&&(switch3 == 1)&&(switch4 == 1)){
//motor1 CCW  
digitalWrite(enblPin1, HIGH);
digitalWrite(dirPin1, LOW);
for(x = 0; x < 400; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(700);
digitalWrite(stepPin1, LOW);
delayMicroseconds(700);
}
}

if((switch1 == 1)&&(switch2 == 1)&&(switch3 == 0)&&(switch4 == 1)){
//motor2 CW  
digitalWrite(enblPin2, HIGH);
digitalWrite(dirPin2, LOW);
for(x = 0; x < 400; x++)
{
digitalWrite(stepPin2, HIGH);
delayMicroseconds(700);
digitalWrite(stepPin2, LOW);
delayMicroseconds(700);
}

}

if((switch1 == 1)&&(switch2 == 1)&&(switch3 == 1)&&(switch4 == 0)){
//motor2 CCW  
digitalWrite(enblPin2, HIGH);
digitalWrite(dirPin2, HIGH);
for(x = 0; x < 400; x++)
{
digitalWrite(stepPin2, HIGH);
delayMicroseconds(700);
digitalWrite(stepPin2, LOW);
delayMicroseconds(700);
}
}

}


3. VIDEO HASILNYA



No comments:

Post a Comment