Pada malam hari ini saya akan menjelaskan mengenai sebuah robot yang bisa dikendalikan menggunakan joystick PS2, jadi robot akan bergerak sesuai dengan tombol yang ditekan pada joystick, robot ini hanya bisa bergerak maju, belok kanan, belok kiri dan stop. untuk aplikasi robot ini yaitu bisa dikembangkan menjadi robot yang bisa melayani masyarakat atau sebagai pramusaji dll. untuk skema dan programnya seperti berikut.
a. Arduino Uno
b. Driver Motor L298
c. Motor DC + Gearbox
d. Joystick PS2
e. Program Arduino IDE
#include <Wire.h>
#include <PS2X_lib.h>
int mtrkanan1 = 4;
int mtrkanan2 = 5;
int mtrkiri1 = 6;
int mtrkiri2 = 7;
int kecmtr1 = 8;
int kecmtr2 = 9;
PS2X ps2x;
byte Type = 0;
byte vibrate = 0;
int RX=0,RY=0,LX=0,LY=0;
int x = 0;
void setup(){
Serial.begin(9600);
ps2x.config_gamepad(13,11,10,12, true, true);
Type = ps2x.readType();
pinMode(mtrkanan1,OUTPUT);
pinMode(mtrkanan2,OUTPUT);
pinMode(mtrkiri1,OUTPUT);
pinMode(mtrkiri2,OUTPUT);
pinMode(kecmtr1,OUTPUT);
pinMode(kecmtr2,OUTPUT);
if(Type==1){
}
}
void loop(){
ps2x.read_gamepad(false, vibrate);
if(ps2x.NewButtonState()){
if(ps2x.Button(PSB_GREEN)){
Serial.println("SEGITIGA");
x = 1;
}
if(ps2x.Button(PSB_BLUE)){
Serial.println("SILANG");
x = 2;
}
if(ps2x.Button(PSB_RED)){
Serial.println("BULAT");
x = 3;
}
if(ps2x.Button(PSB_PINK)){
Serial.println("KOTAK");
x = 4;
}
Serial.println(x);
if(x == 1){
analogWrite(kecmtr1,250);
digitalWrite(mtrkanan1,LOW);
digitalWrite(mtrkanan2,HIGH);
analogWrite(kecmtr2,250);
digitalWrite(mtrkiri1,HIGH);
digitalWrite(mtrkiri2,LOW);
}
if(x == 2){
analogWrite(kecmtr1,150);
digitalWrite(mtrkanan1,LOW);
digitalWrite(mtrkanan2,LOW);
analogWrite(kecmtr2,150);
digitalWrite(mtrkiri1,LOW);
digitalWrite(mtrkiri2,LOW);
}
if(x == 3){
analogWrite(kecmtr1,150);
digitalWrite(mtrkanan1,LOW);
digitalWrite(mtrkanan2,LOW);
analogWrite(kecmtr2,200);
digitalWrite(mtrkiri1,HIGH);
digitalWrite(mtrkiri2,LOW);
}
if(x == 4){
analogWrite(kecmtr1,200);
digitalWrite(mtrkanan1,LOW);
digitalWrite(mtrkanan2,HIGH);
analogWrite(kecmtr2,150);
digitalWrite(mtrkiri1,LOW);
digitalWrite(mtrkiri2,LOW);
}
}
}
#include <PS2X_lib.h>
int mtrkanan1 = 4;
int mtrkanan2 = 5;
int mtrkiri1 = 6;
int mtrkiri2 = 7;
int kecmtr1 = 8;
int kecmtr2 = 9;
PS2X ps2x;
byte Type = 0;
byte vibrate = 0;
int RX=0,RY=0,LX=0,LY=0;
int x = 0;
void setup(){
Serial.begin(9600);
ps2x.config_gamepad(13,11,10,12, true, true);
Type = ps2x.readType();
pinMode(mtrkanan1,OUTPUT);
pinMode(mtrkanan2,OUTPUT);
pinMode(mtrkiri1,OUTPUT);
pinMode(mtrkiri2,OUTPUT);
pinMode(kecmtr1,OUTPUT);
pinMode(kecmtr2,OUTPUT);
if(Type==1){
}
}
void loop(){
ps2x.read_gamepad(false, vibrate);
if(ps2x.NewButtonState()){
if(ps2x.Button(PSB_GREEN)){
Serial.println("SEGITIGA");
x = 1;
}
if(ps2x.Button(PSB_BLUE)){
Serial.println("SILANG");
x = 2;
}
if(ps2x.Button(PSB_RED)){
Serial.println("BULAT");
x = 3;
}
if(ps2x.Button(PSB_PINK)){
Serial.println("KOTAK");
x = 4;
}
Serial.println(x);
if(x == 1){
analogWrite(kecmtr1,250);
digitalWrite(mtrkanan1,LOW);
digitalWrite(mtrkanan2,HIGH);
analogWrite(kecmtr2,250);
digitalWrite(mtrkiri1,HIGH);
digitalWrite(mtrkiri2,LOW);
}
if(x == 2){
analogWrite(kecmtr1,150);
digitalWrite(mtrkanan1,LOW);
digitalWrite(mtrkanan2,LOW);
analogWrite(kecmtr2,150);
digitalWrite(mtrkiri1,LOW);
digitalWrite(mtrkiri2,LOW);
}
if(x == 3){
analogWrite(kecmtr1,150);
digitalWrite(mtrkanan1,LOW);
digitalWrite(mtrkanan2,LOW);
analogWrite(kecmtr2,200);
digitalWrite(mtrkiri1,HIGH);
digitalWrite(mtrkiri2,LOW);
}
if(x == 4){
analogWrite(kecmtr1,200);
digitalWrite(mtrkanan1,LOW);
digitalWrite(mtrkanan2,HIGH);
analogWrite(kecmtr2,150);
digitalWrite(mtrkiri1,LOW);
digitalWrite(mtrkiri2,LOW);
}
}
}
f. VIDEO HASILNYA
No comments:
Post a Comment