Monday, October 23, 2023

FYP control Motor Driver merah

 



masukan coding motor control pulak

int motor1Pin1 = 8; 
int motor1Pin2 = 9; 
int enable1Pin = 14;

int motor1Pin3 = 10; 
int motor1Pin4 = 11; 
int enable2Pin = 15;
void setup() {
  // put your setup code here, to run once:
Serial.begin (9600);
  
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(enable1Pin, OUTPUT);

  pinMode(motor1Pin3, OUTPUT);
  pinMode(motor1Pin4, OUTPUT);
  pinMode(enable2Pin, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
{ // motor stop
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW); 
  digitalWrite(motor1Pin3, LOW);
  digitalWrite(motor1Pin4, LOW);
  delay(2000);
}


{ // gerak ke depan
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH); 
  digitalWrite(motor1Pin3, LOW);
  digitalWrite(motor1Pin4, HIGH); 
  delay(5000);

{  // motor stop
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW); 
  digitalWrite(motor1Pin3, LOW);
  digitalWrite(motor1Pin4, LOW);
  delay(2000);
}

{ // gerak ke belakang
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW); 
  digitalWrite(motor1Pin3, HIGH);
  digitalWrite(motor1Pin4, LOW); 
  delay(5000);
{  // motor stop
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW); 
  digitalWrite(motor1Pin3, LOW);
  digitalWrite(motor1Pin4, LOW);
  delay(2000);
}
{ // gerak ke kanan
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH); 
  digitalWrite(motor1Pin3, HIGH);
  digitalWrite(motor1Pin4, LOW); 
  delay(5000);
{  // motor stop
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW); 
  digitalWrite(motor1Pin3, LOW);
  digitalWrite(motor1Pin4, LOW);
  delay(2000);
}
{ // gerak ke kiri
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW); 
  digitalWrite(motor1Pin3, LOW);
  digitalWrite(motor1Pin4, HIGH); 
  delay(5000);

}

// untuk simpana senpai Damia'




No comments:

Post a Comment