Translate

Membuat Robot Line Tracer atau Robot Line Follower Menggunakan ARDUINO

Membuat Robot Line Tracer atau Robot Line Follower Menggunakan ARDUINO


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah robot dengan menggunakan Arduino sebagai kontrollernya. robot ini menggunakan sensor photodioda dan driver motor yang digunakan adalah modul drver L298. untuk lebih jelasnya berikut adalah daftar komponen dan programnya.




a. Arduino Uno




b. Driver Motor L298




c. Sensor Photodioda dan LED 




d. Motor DC dan Roda






e. Program Arduino IDE

#include <Wire.h>

int a,b,c,d,e,f,g,h ;
int aa = A3;
int bb = A4;
int cc = A5;

int a1 = 950;
int b1 = 850;
int c1 = 850;
int d1 = 900;
int e1 = 860;
int f1 = 850;
int g1 = 860;
int h1 = 750;

int kecepatan = 155;

void setup(){
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(aa,OUTPUT);
pinMode(bb,OUTPUT);
pinMode(cc,OUTPUT);
pinMode(11,OUTPUT);
digitalWrite(11,LOW);
Serial.begin (9600);
}


void loop(){
digitalWrite(aa,LOW);
digitalWrite(bb,LOW);
digitalWrite(cc,LOW);
a = analogRead(A0);

digitalWrite(aa,LOW);
digitalWrite(bb,LOW);
digitalWrite(cc,HIGH);
b = analogRead(A0);

digitalWrite(aa,LOW);
digitalWrite(bb,HIGH);
digitalWrite(cc,LOW);
c = analogRead(A0);

digitalWrite(aa,LOW);
digitalWrite(bb,HIGH);
digitalWrite(cc,HIGH);
d = analogRead(A0);

digitalWrite(aa,HIGH);
digitalWrite(bb,LOW);
digitalWrite(cc,LOW);
e = analogRead(A0);

digitalWrite(aa,HIGH);
digitalWrite(bb,LOW);
digitalWrite(cc,HIGH);
f = analogRead(A0);

digitalWrite(aa,HIGH);
digitalWrite(bb,HIGH);
digitalWrite(cc,LOW);
g = analogRead(A0);

digitalWrite(aa,HIGH);
digitalWrite(bb,HIGH);
digitalWrite(cc,HIGH);
h = analogRead(A0);

Serial.print (a);
Serial.print (" ");
Serial.print (" ");
Serial.print (b);
Serial.print (" ");
Serial.print (" ");
Serial.print (c);
Serial.print (" ");
Serial.print (" ");
Serial.print (d);
Serial.print (" ");
Serial.print (" ");
Serial.print (e);
Serial.print (" ");
Serial.print (" ");
Serial.print (f);
Serial.print (" ");
Serial.print (" ");
Serial.print (g);
Serial.print (" ");
Serial.print (" ");
Serial.println (h);


if ((a > a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}

if ((a < a1)&&(b > b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}

if ((a < a1)&&(b < b1)&&(c > c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}

if ((a < a1)&&(b < b1)&&(c < c1)&&(d > d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan); 
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e > e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f > f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g > g1)&&(h < h1)) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h > h1)) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan); 
}
if ((a > a1)&&(b > b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b > b1)&&(c > c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c > c1)&&(d > d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d > d1)&&(e > e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e > e1)&&(f > f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f > f1)&& (g > g1)&&(h < h1)) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g > g1)&&(h > h1)) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a > a1)&&(b < b1)&&(c < c1)&&(d > d1)&&(e > e1)&&(f > f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a > a1)&&(b > b1)&&(c > c1)&&(d > d1)&&(e > e1)&&(f > f1)&& (g > g1)&&(h > h1)) {
  digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
analogWrite(10,kecepatan);
}
if ((a > a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f > f1)&& (g > g1)&&(h > h1)) {
  digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
analogWrite(10,kecepatan);
delay(5000);
}
}





f. VIDEO HASILNYA









No comments:

Post a Comment