Translate

Membuat Robot Line Follower / Line Tracer Menggunakan Arduino

Membuat Robot Line Tracer / Line Follower Menggunakan Arduino


          Pada sore ini saya akan menjelaskan mengenai bagaimana membuat sebuah robot line follower atau line tracer atau bisa disebut juga robot pengikut garis dengan menggunakan Arduino. robot ini adalah contoh saja bukan robot yang didesain untuk lomba sehingga kecepatannya robot ini standart dan tidak terlalu cepat gerakkannya. robot ini juga tidak menggunakan PID sehingga terasa patahan saat beloknya, jika ingin smooth saat belok gunakanlah PID control. untuk lebih jelasnya berikut adalah skema dan programnya.



a. Arduino UNO





b. Sensor Garis 






c. Driver Motor L298 





d. Motor DC + Gearbox






e. Program Arduino IDE

int mtrkanan1 = 4;
int mtrkanan2 = 5;
int mtrkiri1 = 6;
int mtrkiri2 = 7;

int kecmtr1 = 9;
int kecmtr2 = 10;

int batas = 150;
int kecepatan = 200;

int a;
int b;
int c;
int d;
int e;
int f;

void setup() {
  Serial.begin(9600);
 
  pinMode(mtrkanan1,OUTPUT);
  pinMode(mtrkanan2,OUTPUT);
  pinMode(mtrkiri1,OUTPUT);
  pinMode(mtrkiri2,OUTPUT);
  pinMode(kecmtr1,OUTPUT);
  pinMode(kecmtr2,OUTPUT);
}


void loop() {

  int sensorValue0 = analogRead(A0);
  int sensorValue1 = analogRead(A1);
  int sensorValue2 = analogRead(A2);
  int sensorValue3 = analogRead(A3);
  int sensorValue4 = analogRead(A4);
  int sensorValue5 = analogRead(A5);

/* 
  Serial.print(sensorValue0);
  Serial.print(" ");
  Serial.print(sensorValue1);
  Serial.print(" ");
  Serial.print(sensorValue2);
  Serial.print(" ");
  Serial.print(sensorValue3);
  Serial.print(" ");
  Serial.print(sensorValue4);
  Serial.print(" ");
  Serial.println(sensorValue5);
*/

if(sensorValue0 > batas){
a = 1;
}
if(sensorValue0 < batas){
a = 0;
}

if(sensorValue1 > batas){
b = 1;
}
if(sensorValue1 < batas){
b = 0;
}

if(sensorValue2 > batas){
c = 1;
}
if(sensorValue2 < batas){
c = 0;
}

if(sensorValue3 > batas){
d = 1;
}
if(sensorValue3 < batas){
d = 0;
}

if(sensorValue4 > batas){
e = 1;
}
if(sensorValue4 < batas){
e = 0;
}

if(sensorValue5 > batas){
f = 1;
}
if(sensorValue5 < batas){
f = 0;
}
 
//mundur 
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 1)&&(e == 1)&&(f == 1)){
  analogWrite(kecmtr1,kecepatan);
  digitalWrite(mtrkanan1,HIGH);
  digitalWrite(mtrkanan2,LOW);
 
  analogWrite(kecmtr2,kecepatan);
  digitalWrite(mtrkiri1,HIGH);
  digitalWrite(mtrkiri2,LOW);

}


//maju 
if((a == 1)&&(b == 1)&&(c == 0)&&(d == 1)&&(e == 1)&&(f == 1)){
  analogWrite(kecmtr1,kecepatan);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,HIGH);
 
  analogWrite(kecmtr2,kecepatan);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,HIGH);

}


//maju 
if((a == 1)&&(b == 1)&&(c == 0)&&(d == 0)&&(e == 1)&&(f == 1)){
  analogWrite(kecmtr1,kecepatan);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,HIGH);
 
  analogWrite(kecmtr2,kecepatan);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,HIGH);

}


//maju 
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 0)&&(e == 1)&&(f == 1)){
  analogWrite(kecmtr1,kecepatan);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,HIGH);
 
  analogWrite(kecmtr2,kecepatan);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,HIGH);

}


//kiri 
if((a == 0)&&(b == 1)&&(c == 1)&&(d == 1)&&(e == 1)&&(f == 1)){
  analogWrite(kecmtr1,0);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,LOW);
 
  analogWrite(kecmtr2,kecepatan);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,HIGH);

}


//kiri 
if((a == 1)&&(b == 0)&&(c == 1)&&(d == 1)&&(e == 1)&&(f == 1)){
  analogWrite(kecmtr1,0);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,LOW);
 
  analogWrite(kecmtr2,kecepatan);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,HIGH);

}


//kiri 
if((a == 0)&&(b == 0)&&(c == 1)&&(d == 1)&&(e == 1)&&(f == 1)){
  analogWrite(kecmtr1,0);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,LOW);
 
  analogWrite(kecmtr2,kecepatan);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,HIGH);

}

//kiri 
if((a == 1)&&(b == 0)&&(c == 0)&&(d == 1)&&(e == 1)&&(f == 1)){
  analogWrite(kecmtr1,0);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,LOW);
 
  analogWrite(kecmtr2,kecepatan);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,HIGH);

}
 
 
//kiri 
if((a == 0)&&(b == 0)&&(c == 0)&&(d == 1)&&(e == 1)&&(f == 1)){
  analogWrite(kecmtr1,0);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,LOW);
 
  analogWrite(kecmtr2,kecepatan);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,HIGH);




//kanan
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 1)&&(e == 1)&&(f == 0)){
  analogWrite(kecmtr1,kecepatan);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,HIGH);
 
  analogWrite(kecmtr2,0);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,LOW);

}

//kanan
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 1)&&(e == 0)&&(f == 1)){
  analogWrite(kecmtr1,kecepatan);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,HIGH);
 
  analogWrite(kecmtr2,0);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,LOW);

}

//kanan
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 1)&&(e == 0)&&(f == 0)){
  analogWrite(kecmtr1,kecepatan);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,HIGH);
 
  analogWrite(kecmtr2,0);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,LOW);

}
 
//kanan
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 0)&&(e == 0)&&(f == 1)){
  analogWrite(kecmtr1,kecepatan);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,HIGH);
 
  analogWrite(kecmtr2,0);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,LOW);


  

//kanan
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 0)&&(e == 0)&&(f == 0)){
  analogWrite(kecmtr1,kecepatan);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,HIGH);
 
  analogWrite(kecmtr2,0);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,LOW);

}   

/* 
  Serial.print(a);
  Serial.print(" ");
  Serial.print(b);
  Serial.print(" ");
  Serial.print(c);
  Serial.print(" ");
  Serial.print(d);
  Serial.print(" ");
  Serial.print(e);
  Serial.print(" ");
  Serial.println(f);
*/

delay(10);
        
}






f. VIDEO HASILNYA











No comments:

Post a Comment