Pada kesempatan yang berbahagia kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah robot line follower atau line tracer tanpa PID dan metode, jadi robot in berjalan hanya menggunakan logika dari input sensor. robot ini menggunakan mikrokontroller Arduino dan sensor berupa photodioda dan led kuning. Fungsi dari robot ini seperti namanya yaitu mengikuti garis yang telah ditentukan arahnya dengan menggunakan 2 buah warna yang berbeda, biasanya warna putih dan hitam atau kuning dengan biru tua. untuk lebih jelasnya berikut adalah skema dan programnya.
a. Arduino UNO
b. Driver L298
c. Motor DC + Roda
d. Sensor Photodioda + Led
e. Program Arduino IDE
int dirkaa = 2;
int dirka = 4;
int pwmka = 10;
int dirkii = 8;
int dirki = 12;
int pwmki = 11;
int s1 = 3;
int s2 = 5;
int s3 = 6;
int s4 = 7;
int s5 = 9;
int x1 = 0;
int x2 = 0;
int x3 = 0;
int x4 = 0;
int x5 = 0;
int kec = 150;
void setup(){
Serial.begin(9600);
pinMode(s1,INPUT);
pinMode(s2,INPUT);
pinMode(s3,INPUT);
pinMode(s4,INPUT);
pinMode(s5,INPUT);
pinMode(dirkaa,OUTPUT);
pinMode(dirka,OUTPUT);
pinMode(dirkii,OUTPUT);
pinMode(dirki,OUTPUT);
pinMode(pwmka,OUTPUT);
pinMode(pwmki,OUTPUT);
}
void loop(){
x1 = digitalRead(s1);
x2 = digitalRead(s2);
x3 = digitalRead(s3);
x4 = digitalRead(s4);
x5 = digitalRead(s5);
Serial.print("s1=");
Serial.println(x1);
Serial.print("s2=");
Serial.println(x2);
Serial.print("s3=");
Serial.println(x3);
Serial.print("s4=");
Serial.println(x4);
Serial.print("s5=");
Serial.println(x5);
//000000
if((x1 == 0)&&(x2 == 0)&&(x3 == 0)&&(x4 == 0)&&(x5 == 0)){
Serial.println("none");
//mundur
digitalWrite(dirkaa,LOW);
digitalWrite(dirka,HIGH);
analogWrite(pwmka, kec);
digitalWrite(dirkii,LOW);
digitalWrite(dirki,HIGH);
analogWrite(pwmki, kec);
//10000
}else if((x1 == 1)&&(x2 == 0)&&(x3 == 0)&&(x4 == 0)&&(x5 == 0)){
Serial.println("kiri");
//kiri
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, 0);
//11000
}else if((x1 == 1)&&(x2 == 1)&&(x3 == 0)&&(x4 == 0)&&(x5 == 0)){
Serial.println("kiri");
//kiri
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, 0);
//11100
}else if((x1 == 1)&&(x2 == 1)&&(x3 == 1)&&(x4 == 0)&&(x5 == 0)){
Serial.println("kiri");
//kiri
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, 0);
//11110
}else if((x1 == 1)&&(x2 == 1)&&(x3 == 1)&&(x4 == 1)&&(x5 == 0)){
Serial.println("tengah");
//11111
}else if((x1 == 1)&&(x2 == 1)&&(x3 == 1)&&(x4 == 1)&&(x5 == 1)){
Serial.println("lurus");
//lurus
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//00100
}else if((x1 == 0)&&(x2 == 0)&&(x3 == 1)&&(x4 == 0)&&(x5 == 0)){
Serial.println("lurus");
//lurus
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//01100
}else if((x1 == 0)&&(x2 == 1)&&(x3 == 1)&&(x4 == 0)&&(x5 == 0)){
Serial.println("lurus");
//lurus
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//00110
}else if((x1 == 0)&&(x2 == 0)&&(x3 == 1)&&(x4 == 1)&&(x5 == 0)){
Serial.println("lurus");
//lurus
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//01110
}else if((x1 == 0)&&(x2 == 1)&&(x3 == 1)&&(x4 == 1)&&(x5 == 0)){
Serial.println("lurus");
//lurus
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//00001
}else if((x1 == 0)&&(x2 == 0)&&(x3 == 0)&&(x4 == 0)&&(x5 == 1)){
Serial.println("kanan");
//kanan
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, 0);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//00011
}else if((x1 == 0)&&(x2 == 0)&&(x3 == 0)&&(x4 == 1)&&(x5 == 1)){
Serial.println("kanan");
//kanan
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, 0);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//00111
}else if((x1 == 0)&&(x2 == 0)&&(x3 == 1)&&(x4 == 1)&&(x5 == 1)){
Serial.println("kanan");
//kanan
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, 0);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//01111
}else if((x1 == 0)&&(x2 == 1)&&(x3 == 1)&&(x4 == 1)&&(x5 == 1)){
Serial.println("lurus");
//kanan
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
}
}
int dirka = 4;
int pwmka = 10;
int dirkii = 8;
int dirki = 12;
int pwmki = 11;
int s1 = 3;
int s2 = 5;
int s3 = 6;
int s4 = 7;
int s5 = 9;
int x1 = 0;
int x2 = 0;
int x3 = 0;
int x4 = 0;
int x5 = 0;
int kec = 150;
void setup(){
Serial.begin(9600);
pinMode(s1,INPUT);
pinMode(s2,INPUT);
pinMode(s3,INPUT);
pinMode(s4,INPUT);
pinMode(s5,INPUT);
pinMode(dirkaa,OUTPUT);
pinMode(dirka,OUTPUT);
pinMode(dirkii,OUTPUT);
pinMode(dirki,OUTPUT);
pinMode(pwmka,OUTPUT);
pinMode(pwmki,OUTPUT);
}
void loop(){
x1 = digitalRead(s1);
x2 = digitalRead(s2);
x3 = digitalRead(s3);
x4 = digitalRead(s4);
x5 = digitalRead(s5);
Serial.print("s1=");
Serial.println(x1);
Serial.print("s2=");
Serial.println(x2);
Serial.print("s3=");
Serial.println(x3);
Serial.print("s4=");
Serial.println(x4);
Serial.print("s5=");
Serial.println(x5);
//000000
if((x1 == 0)&&(x2 == 0)&&(x3 == 0)&&(x4 == 0)&&(x5 == 0)){
Serial.println("none");
//mundur
digitalWrite(dirkaa,LOW);
digitalWrite(dirka,HIGH);
analogWrite(pwmka, kec);
digitalWrite(dirkii,LOW);
digitalWrite(dirki,HIGH);
analogWrite(pwmki, kec);
//10000
}else if((x1 == 1)&&(x2 == 0)&&(x3 == 0)&&(x4 == 0)&&(x5 == 0)){
Serial.println("kiri");
//kiri
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, 0);
//11000
}else if((x1 == 1)&&(x2 == 1)&&(x3 == 0)&&(x4 == 0)&&(x5 == 0)){
Serial.println("kiri");
//kiri
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, 0);
//11100
}else if((x1 == 1)&&(x2 == 1)&&(x3 == 1)&&(x4 == 0)&&(x5 == 0)){
Serial.println("kiri");
//kiri
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, 0);
//11110
}else if((x1 == 1)&&(x2 == 1)&&(x3 == 1)&&(x4 == 1)&&(x5 == 0)){
Serial.println("tengah");
//11111
}else if((x1 == 1)&&(x2 == 1)&&(x3 == 1)&&(x4 == 1)&&(x5 == 1)){
Serial.println("lurus");
//lurus
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//00100
}else if((x1 == 0)&&(x2 == 0)&&(x3 == 1)&&(x4 == 0)&&(x5 == 0)){
Serial.println("lurus");
//lurus
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//01100
}else if((x1 == 0)&&(x2 == 1)&&(x3 == 1)&&(x4 == 0)&&(x5 == 0)){
Serial.println("lurus");
//lurus
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//00110
}else if((x1 == 0)&&(x2 == 0)&&(x3 == 1)&&(x4 == 1)&&(x5 == 0)){
Serial.println("lurus");
//lurus
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//01110
}else if((x1 == 0)&&(x2 == 1)&&(x3 == 1)&&(x4 == 1)&&(x5 == 0)){
Serial.println("lurus");
//lurus
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//00001
}else if((x1 == 0)&&(x2 == 0)&&(x3 == 0)&&(x4 == 0)&&(x5 == 1)){
Serial.println("kanan");
//kanan
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, 0);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//00011
}else if((x1 == 0)&&(x2 == 0)&&(x3 == 0)&&(x4 == 1)&&(x5 == 1)){
Serial.println("kanan");
//kanan
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, 0);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//00111
}else if((x1 == 0)&&(x2 == 0)&&(x3 == 1)&&(x4 == 1)&&(x5 == 1)){
Serial.println("kanan");
//kanan
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, 0);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
//01111
}else if((x1 == 0)&&(x2 == 1)&&(x3 == 1)&&(x4 == 1)&&(x5 == 1)){
Serial.println("lurus");
//kanan
digitalWrite(dirkaa,HIGH);
digitalWrite(dirka,LOW);
analogWrite(pwmka, kec);
digitalWrite(dirkii,HIGH);
digitalWrite(dirki,LOW);
analogWrite(pwmki, kec);
}
}
f. Cara Menggunakan Robot
Cara menggunakan robot ini yaitu yang pertama adalah kalibrasi sensor terlebih dahulu dengan menentukan resistor yang tepat agar saat kondisi sensor terkena garis hitam, dia akan berlogika LOW atau tegangan dibawah 1 volt, kemudian saat terkena garis putih tegangan ada di atas 3 volt sampai 5 volt dc sehingga jika dibaca oleh pin I/O bisa berlogika high dan LOW atau 1 dan 0. setelah kalibrasi selesai robot siap digunakan dan dijalankan.
g. VIDEO HASILNYA
No comments:
Post a Comment