motor drive simple
motor drive simple
หลักการทำงาน
arduinoส่งไปยังL293D แล้วก็ไปสั่งให้มอเตอร์ทำงาน
Code
const int motorPin1 = 5; Pin 14 of L293
const int motorPin2 = 6; Pin 10 of L293
const int motorPin2 = 6; Pin 10 of L293
const int motorPin3 = 10; Pin 7 of L293
const int motorPin4 = 9; Pin 2 of L293
const int motorPin4 = 9; Pin 2 of L293
This will run only one time.
void setup(){
Set pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
Motor Control - Motor A motorPin1,motorpin2 & Motor B motorpin3,motorpin4
void setup(){
Set pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
Motor Control - Motor A motorPin1,motorpin2 & Motor B motorpin3,motorpin4
This code will turn Motor A clockwise for 2 sec.
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(2000);
This code will turn Motor A counter-clockwise for 2 sec.
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(2000);
This code will turn Motor B clockwise for 2 sec.
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(2000);
This code will turn Motor B counter-clockwise for 2 sec.
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(2000);
And this code will stop motors
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
}
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(2000);
This code will turn Motor A counter-clockwise for 2 sec.
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(2000);
This code will turn Motor B clockwise for 2 sec.
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(2000);
This code will turn Motor B counter-clockwise for 2 sec.
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(2000);
And this code will stop motors
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
}
void loop(){
}
ความคิดเห็น
แสดงความคิดเห็น