Oleh : pandu
Kategori : Kreatifitas

Hai Semuanya,

Kali Ini saya akan mengajari membuat robot obstacle avoiding atau robot penghindar rintangan,

Oke sebelum itu kita harus mempersiapkan bahan-bahannya terlebih dahulu
  1. Arduino Board
  2. L298N H-bridge
  3. HC SR04 Sensor
  4. SG90 Servo 
  5. DC Motor Wheel
  6. Chassis
  7. HC SR04 Bracket
  8. Front Wheel
  9. Breadboard 
  10. Female to Female Jumper
  11. Male to Male Jumper
  12. 9V Battery 
  13. Battery Clip 
  14. Power Cable
Oke Lanjut Dengan Pemasangan Kabel


Oke selanjutnya program robotnya dengan ARDUINO IDE
Download Softwarenya Dilink ini http://www.filehorse.com/download-arduino/

Oke Kalau Sudah Instal softwarenya
sebelum itu Download Ping Librarynya Disinih https://goo.gl/Qe6XU6

Habis Itu Program Robot nya, Saya Akan Membagikan Script Pemrogramannya Sebagai Berikut

#include           //Servo motor library.
#include         //Ultrasonic sensor

//Kontrol Pin L298N
const int LeftMotorForward = 7;
const int LeftMotorBackward = 6;
const int RightMotorForward = 4;
const int RightMotorBackward = 5;

//sensor pins
#define trig_pin A1 //analog input 1
#define echo_pin A2 //analog input 2

#define maximum_distance 200
boolean goesForward = false;
int distance = 100;

NewPing sonar(trig_pin, echo_pin, maximum_distance); 
Servo servo_motor; 


void setup(){

  pinMode(RightMotorForward, OUTPUT);
  pinMode(LeftMotorForward, OUTPUT);
  pinMode(LeftMotorBackward, OUTPUT);
  pinMode(RightMotorBackward, OUTPUT);
  
  servo_motor.attach(10); //our servo pin

  servo_motor.write(115);
  delay(2000);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
}

void loop(){

  int distanceRight = 0;
  int distanceLeft = 0;
  delay(50);

  if (distance <= 20){
    moveStop();
    delay(300);
    moveBackward();
    delay(400);
    moveStop();
    delay(300);
    distanceRight = lookRight();
    delay(300);
    distanceLeft = lookLeft();
    delay(300);

    if (distance >= distanceLeft){
      turnRight();
      moveStop();
    }
    else{
      turnLeft();
      moveStop();
    }
  }
  else{
    moveForward(); 
  }
    distance = readPing();
}

int lookRight(){  
  servo_motor.write(50);
  delay(500);
  int distance = readPing();
  delay(100);
  servo_motor.write(115);
  return distance;
}

int lookLeft(){
  servo_motor.write(170);
  delay(500);
  int distance = readPing();
  delay(100);
  servo_motor.write(115);
  return distance;
  delay(100);
}

int readPing(){
  delay(70);
  int cm = sonar.ping_cm();
  if (cm==0){
    cm=250;
  }
  return cm;
}

void moveStop(){
  
  digitalWrite(RightMotorForward, LOW);
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorBackward, LOW);
  digitalWrite(LeftMotorBackward, LOW);
}

void moveForward(){

  if(!goesForward){

    goesForward=true;
    
    digitalWrite(LeftMotorForward, HIGH);
    digitalWrite(RightMotorForward, HIGH);
  
    digitalWrite(LeftMotorBackward, LOW);
    digitalWrite(RightMotorBackward, LOW); 
  }
}

void moveBackward(){

  goesForward=false;

  digitalWrite(LeftMotorBackward, HIGH);
  digitalWrite(RightMotorBackward, HIGH);
  
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorForward, LOW);
  
}

void turnRight(){

  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorBackward, HIGH);
  
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(RightMotorForward, LOW);
  
  delay(500);
  
  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorForward, HIGH);
  
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(RightMotorBackward, LOW);
 
  
  
}

void turnLeft(){

  digitalWrite(LeftMotorBackward, HIGH);
  digitalWrite(RightMotorForward, HIGH);
  
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorBackward, LOW);

  delay(500);
  
  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorForward, HIGH);
  
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(RightMotorBackward, LOW);
}
Selesai Dan Jalankan Robotnya

Sekian,
Semoga bisa dipahami dan bermanfaat bagi teman-teman,
Jika ada pertanyaan bisa komentar

Terima Kasih

SHARE!

pandu

"Anak muda yang suka bikin suatu yang menarik,pengurus ekskul robotika53 , hobynya baca buku"

Follow


3 Mading


AYO TINGKATKAN LITERASI INDONESIA

Kategori : Kreatifitas

Cara Membuat Robot Obstacle Avoiding

Kategori : Kreatifitas

Cara Membuat Mobilan Dari Bahan Bekas

Kategori : Kreatifitas