Kali ini kita akan simulasi robot yang bisa menghindari tabrakan!!!
tonton sampai habis! gak lama kok ilmunyaa

Nama : Muhammad Maulana Yusuf
NIM : 1197070051

Untuk coding silahkan cek pinned comment yaa
thanks for watch

, https://i.ytimg.com/vi/-glZ1s8acUI/hqdefault.jpg

source

1 Comment

  1. kodingan arduino :

    const int pingPin = A1;
    const int echoPin = A0;

    int kiriA = 13;
    int kiriB = 12;
    int kananA = 9;
    int kananB = 8;
    int en1 = 11;
    int en2 = 10;

    void setup()
    {
    Serial.begin(9600);
    pinMode(kiriA,OUTPUT);
    pinMode(kiriB,OUTPUT);
    pinMode(kananA,OUTPUT);
    pinMode(kananB,OUTPUT);
    pinMode(en1,OUTPUT);
    pinMode(en2,OUTPUT);
    }

    void loop()
    {
    long duration,cm;

    pinMode(pingPin, OUTPUT);
    digitalWrite(pingPin, LOW);
    delayMicroseconds(2);
    digitalWrite(pingPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(pingPin, LOW);

    pinMode(echoPin, INPUT);
    duration = pulseIn(echoPin, HIGH);

    cm = microsecondsToCentimeters(duration);

    Serial.print(cm);
    Serial.print("cm");
    Serial.println();
    delay(100);
    analogWrite(en1,255);
    analogWrite(en2,255);

    if (cm <=50){
    digitalWrite(kiriA,HIGH);
    digitalWrite(kiriB,LOW);
    digitalWrite(kananA,HIGH);
    digitalWrite(kananB,LOW);
    Serial.println ("robot belok kiri");
    }
    else
    {
    digitalWrite(kiriA,LOW);
    digitalWrite(kiriB,HIGH);
    digitalWrite(kananA,LOW);
    digitalWrite(kananB,HIGH);
    Serial.println ("maju");
    }
    }
    long microsecondsToCentimeters(long microseconds)
    {
    return microseconds /29 /2;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *