Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah robot yang sedikit rumit bagi pemula dikarenakan banyaknya servo yang harus diakses yaitu sekitar 10 buah servo, robot ini terdapat 2 buah servo yang digunakan untuk kakinya, jadi 1 servo untuk angle kaki dan satu servo lagi untu sikunya. robot ini menggunakan arduino sebagai mikrokontrollernya dan kendali menggunakan handphone android, media pengiriman data menggunakan bluetooth HC-05. untuk batre yang digunakan adalah batre Li-Po 2200mAh. untuk lebih jelasnya berikut adalah program dan skemanya.
a. Arduino mega
b. Arduino Mega Sensor Shield
c. Motor Servo
d. Program Android
e. Program Arduino IDE
#include <Servo.h>
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
Servo myservo6;
Servo myservo7;
Servo myservo8;
Servo myservo9;
Servo myservo10;
int datain;
int x;
void setup(){
myservo1.write(70);
myservo2.write(70);
Serial.begin(9600);
Serial.setTimeout(5);
//perekat
myservo1.attach(36);
myservo2.attach(37);
//kaki1 angle
myservo3.attach(26);
//kakl1 siku
myservo4.attach(27);
//kaki2 angle
myservo5.attach(30);
//kakl2 siku
myservo6.attach(31);
//kaki3 angle
myservo7.attach(32);
//kakl3 siku
myservo8.attach(33);
//kaki4 angle
myservo9.attach(34);
//kakl4 siku
myservo10.attach(35);
rebah();
delay(3000);
bangun();
delay(5000);
myservo1.write(150);
myservo2.write(150);
delay(3000);
}
void loop(){
if(x == 1){
maju();
}
if(x == 2){
kiri();
}
if(x == 3){
kanan();
}
if(x == 4){
bangun();
}
if(x == 5){
mundur();
}
if(Serial.available()>0){
datain = Serial.parseInt();
if(datain == 111){
//maju();
x = 1;
}
if(datain == 222){
//kiri();
x = 2;
}
if(datain == 333){
//kanan();
x = 3;
}
if(datain == 444){
//stop();
x = 4;
}
if(datain == 555){
//mundur();
x = 5;
}
}
}
void rebah(){
//angle
myservo3.write(140);
myservo5.write(50);
myservo7.write(100);
myservo9.write(100);
//siku
myservo4.write(100);
myservo6.write(100);
myservo8.write(100);
myservo10.write(100);
}
void bangun(){
//angle
myservo3.write(140);
myservo5.write(50);
myservo7.write(100);
myservo9.write(100);
//siku
myservo4.write(160);
myservo6.write(20);
myservo8.write(20);
myservo10.write(160);
}
void maju(){
myservo1.write(70);
delay(500);
//kaki1 angle+siku
myservo3.write(140);
myservo4.write(130);
delay(500);
//kaki1 angle+siku
myservo3.write(100);
delay(500);
myservo4.write(160);
delay(500);
//kaki3 angle+siku
myservo7.write(100);
myservo8.write(50);
delay(500);
//kaki3 angle+siku
myservo7.write(130);
delay(500);
myservo8.write(20);
delay(500);
myservo1.write(175);
delay(500);
//============================
myservo2.write(70);
delay(500);
//kaki2 angle+siku
myservo5.write(50);
myservo6.write(50);
delay(500);
//angle kaki1+kaki3
myservo3.write(140);
myservo7.write(100);
delay(500);
//kaki2 angle+siku
myservo5.write(100);
delay(500);
myservo6.write(20);
delay(500);
//kaki4 angle+siku
myservo9.write(100);
myservo10.write(130);
delay(500);
//kaki4 angle+siku
myservo9.write(60);
delay(500);
myservo10.write(160);
delay(500);
myservo2.write(190);
delay(500);
//=======================
myservo5.write(50);
myservo9.write(100);
delay(500);
}
void mundur(){
myservo1.write(70);
delay(200);
//kaki1 angle+siku
myservo3.write(100);
myservo4.write(130);
delay(200);
//kaki1 angle+siku
myservo3.write(140);
delay(100);
myservo4.write(160);
delay(200);
//kaki3 angle+siku
myservo7.write(130);
myservo8.write(50);
delay(200);
//kaki3 angle+siku
myservo7.write(100);
delay(200);
myservo8.write(20);
delay(200);
myservo1.write(175);
delay(200);
//============================
myservo2.write(70);
delay(200);
//kaki2 angle+siku
myservo5.write(100);
myservo6.write(50);
delay(200);
//angle kaki1+kaki3
myservo3.write(100);
myservo7.write(130);
delay(200);
//kaki2 angle+siku
myservo5.write(50);
delay(200);
myservo6.write(20);
delay(200);
//kaki4 angle+siku
myservo9.write(60);
myservo10.write(130);
delay(200);
//kaki4 angle+siku
myservo9.write(100);
delay(100);
myservo10.write(160);
delay(200);
myservo2.write(190);
delay(200);
//=======================
myservo5.write(100);
myservo9.write(60);
delay(200);
}
void kanan(){
myservo1.write(70);
delay(200);
//kaki1 angle+siku
myservo3.write(140);
myservo4.write(130);
delay(200);
//kaki1 angle+siku
myservo3.write(100);
delay(100);
myservo4.write(160);
delay(200);
//kaki3 angle+siku
myservo7.write(130);
myservo8.write(50);
delay(200);
//kaki3 angle+siku
myservo7.write(100);
delay(200);
myservo8.write(20);
delay(200);
myservo1.write(175);
delay(200);
//============================
myservo2.write(70);
delay(200);
//kaki2 angle+siku
myservo5.write(100);
myservo6.write(50);
delay(200);
//angle kaki1+kaki3
myservo3.write(140);
myservo7.write(130);
delay(200);
//kaki2 angle+siku
myservo5.write(50);
delay(200);
myservo6.write(20);
delay(200);
//kaki4 angle+siku
myservo9.write(100);
myservo10.write(130);
delay(200);
//kaki4 angle+siku
myservo9.write(60);
delay(100);
myservo10.write(160);
delay(200);
myservo2.write(190);
delay(200);
//=======================
myservo5.write(100);
myservo9.write(100);
delay(200);
}
void kiri(){
myservo1.write(70);
delay(200);
//kaki1 angle+siku
myservo3.write(100);
myservo4.write(130);
delay(200);
//kaki1 angle+siku
myservo3.write(140);
delay(100);
myservo4.write(160);
delay(200);
//kaki3 angle+siku
myservo7.write(100);
myservo8.write(50);
delay(200);
//kaki3 angle+siku
myservo7.write(130);
delay(200);
myservo8.write(20);
delay(200);
myservo1.write(175);
delay(200);
//============================
myservo2.write(70);
delay(200);
//kaki2 angle+siku
myservo5.write(50);
myservo6.write(50);
delay(200);
//angle kaki1+kaki3
myservo3.write(100);
myservo7.write(100);
delay(200);
//kaki2 angle+siku
myservo5.write(100);
delay(200);
myservo6.write(20);
delay(200);
//kaki4 angle+siku
myservo9.write(60);
myservo10.write(130);
delay(200);
//kaki4 angle+siku
myservo9.write(100);
delay(100);
myservo10.write(160);
delay(200);
myservo2.write(190);
delay(200);
//=======================
myservo5.write(50);
myservo9.write(60);
delay(200);
}
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
Servo myservo6;
Servo myservo7;
Servo myservo8;
Servo myservo9;
Servo myservo10;
int datain;
int x;
void setup(){
myservo1.write(70);
myservo2.write(70);
Serial.begin(9600);
Serial.setTimeout(5);
//perekat
myservo1.attach(36);
myservo2.attach(37);
//kaki1 angle
myservo3.attach(26);
//kakl1 siku
myservo4.attach(27);
//kaki2 angle
myservo5.attach(30);
//kakl2 siku
myservo6.attach(31);
//kaki3 angle
myservo7.attach(32);
//kakl3 siku
myservo8.attach(33);
//kaki4 angle
myservo9.attach(34);
//kakl4 siku
myservo10.attach(35);
rebah();
delay(3000);
bangun();
delay(5000);
myservo1.write(150);
myservo2.write(150);
delay(3000);
}
void loop(){
if(x == 1){
maju();
}
if(x == 2){
kiri();
}
if(x == 3){
kanan();
}
if(x == 4){
bangun();
}
if(x == 5){
mundur();
}
if(Serial.available()>0){
datain = Serial.parseInt();
if(datain == 111){
//maju();
x = 1;
}
if(datain == 222){
//kiri();
x = 2;
}
if(datain == 333){
//kanan();
x = 3;
}
if(datain == 444){
//stop();
x = 4;
}
if(datain == 555){
//mundur();
x = 5;
}
}
}
void rebah(){
//angle
myservo3.write(140);
myservo5.write(50);
myservo7.write(100);
myservo9.write(100);
//siku
myservo4.write(100);
myservo6.write(100);
myservo8.write(100);
myservo10.write(100);
}
void bangun(){
//angle
myservo3.write(140);
myservo5.write(50);
myservo7.write(100);
myservo9.write(100);
//siku
myservo4.write(160);
myservo6.write(20);
myservo8.write(20);
myservo10.write(160);
}
void maju(){
myservo1.write(70);
delay(500);
//kaki1 angle+siku
myservo3.write(140);
myservo4.write(130);
delay(500);
//kaki1 angle+siku
myservo3.write(100);
delay(500);
myservo4.write(160);
delay(500);
//kaki3 angle+siku
myservo7.write(100);
myservo8.write(50);
delay(500);
//kaki3 angle+siku
myservo7.write(130);
delay(500);
myservo8.write(20);
delay(500);
myservo1.write(175);
delay(500);
//============================
myservo2.write(70);
delay(500);
//kaki2 angle+siku
myservo5.write(50);
myservo6.write(50);
delay(500);
//angle kaki1+kaki3
myservo3.write(140);
myservo7.write(100);
delay(500);
//kaki2 angle+siku
myservo5.write(100);
delay(500);
myservo6.write(20);
delay(500);
//kaki4 angle+siku
myservo9.write(100);
myservo10.write(130);
delay(500);
//kaki4 angle+siku
myservo9.write(60);
delay(500);
myservo10.write(160);
delay(500);
myservo2.write(190);
delay(500);
//=======================
myservo5.write(50);
myservo9.write(100);
delay(500);
}
void mundur(){
myservo1.write(70);
delay(200);
//kaki1 angle+siku
myservo3.write(100);
myservo4.write(130);
delay(200);
//kaki1 angle+siku
myservo3.write(140);
delay(100);
myservo4.write(160);
delay(200);
//kaki3 angle+siku
myservo7.write(130);
myservo8.write(50);
delay(200);
//kaki3 angle+siku
myservo7.write(100);
delay(200);
myservo8.write(20);
delay(200);
myservo1.write(175);
delay(200);
//============================
myservo2.write(70);
delay(200);
//kaki2 angle+siku
myservo5.write(100);
myservo6.write(50);
delay(200);
//angle kaki1+kaki3
myservo3.write(100);
myservo7.write(130);
delay(200);
//kaki2 angle+siku
myservo5.write(50);
delay(200);
myservo6.write(20);
delay(200);
//kaki4 angle+siku
myservo9.write(60);
myservo10.write(130);
delay(200);
//kaki4 angle+siku
myservo9.write(100);
delay(100);
myservo10.write(160);
delay(200);
myservo2.write(190);
delay(200);
//=======================
myservo5.write(100);
myservo9.write(60);
delay(200);
}
void kanan(){
myservo1.write(70);
delay(200);
//kaki1 angle+siku
myservo3.write(140);
myservo4.write(130);
delay(200);
//kaki1 angle+siku
myservo3.write(100);
delay(100);
myservo4.write(160);
delay(200);
//kaki3 angle+siku
myservo7.write(130);
myservo8.write(50);
delay(200);
//kaki3 angle+siku
myservo7.write(100);
delay(200);
myservo8.write(20);
delay(200);
myservo1.write(175);
delay(200);
//============================
myservo2.write(70);
delay(200);
//kaki2 angle+siku
myservo5.write(100);
myservo6.write(50);
delay(200);
//angle kaki1+kaki3
myservo3.write(140);
myservo7.write(130);
delay(200);
//kaki2 angle+siku
myservo5.write(50);
delay(200);
myservo6.write(20);
delay(200);
//kaki4 angle+siku
myservo9.write(100);
myservo10.write(130);
delay(200);
//kaki4 angle+siku
myservo9.write(60);
delay(100);
myservo10.write(160);
delay(200);
myservo2.write(190);
delay(200);
//=======================
myservo5.write(100);
myservo9.write(100);
delay(200);
}
void kiri(){
myservo1.write(70);
delay(200);
//kaki1 angle+siku
myservo3.write(100);
myservo4.write(130);
delay(200);
//kaki1 angle+siku
myservo3.write(140);
delay(100);
myservo4.write(160);
delay(200);
//kaki3 angle+siku
myservo7.write(100);
myservo8.write(50);
delay(200);
//kaki3 angle+siku
myservo7.write(130);
delay(200);
myservo8.write(20);
delay(200);
myservo1.write(175);
delay(200);
//============================
myservo2.write(70);
delay(200);
//kaki2 angle+siku
myservo5.write(50);
myservo6.write(50);
delay(200);
//angle kaki1+kaki3
myservo3.write(100);
myservo7.write(100);
delay(200);
//kaki2 angle+siku
myservo5.write(100);
delay(200);
myservo6.write(20);
delay(200);
//kaki4 angle+siku
myservo9.write(60);
myservo10.write(130);
delay(200);
//kaki4 angle+siku
myservo9.write(100);
delay(100);
myservo10.write(160);
delay(200);
myservo2.write(190);
delay(200);
//=======================
myservo5.write(50);
myservo9.write(60);
delay(200);
}
f. VIDEO HASILNYA
No comments:
Post a Comment