Coding Arduino Robot Arms / Lengan Sederhana. Coding Dasar : #include Servo servo1; //Motor servo yang digunakan Servo servo2; Servo servo3; Servo servo4; Servo servo5; int pos = 0; void setup() { servo1.attach(6); //angka 6 merupakan Pin yang ditancapkan pada Arduino dst.. servo2.attach(7); servo3.attach(8); servo4.attach(9); servo5.attach(10); } void loop() { for (pos = 45; pos <= 80; pos += 1) { // goes from 45 degrees to 80 degrees // in steps of 1 degree servo2.write(pos); // tell servo to go to position in variable 'pos' delay(10); // waits 10ms for the servo to reach the position } delay(1000); for (pos = 90; pos <= 140; pos += 1) { // goes from 90 degrees to 140 degrees // in steps of 1 degree servo1.write(pos); // tell servo to go to position in variable 'pos' delay(10); // waits 10ms for the servo to reach the position } delay(1000); for (pos = 90; pos >= 45; pos -= 1) { // goes from 90 degrees to 45 degrees // in steps of 1 degree servo2.write(pos); // tell servo to go to position in variable 'pos' delay(10); // waits 10ms for the servo to reach the position } delay(1000); for (pos = 90; pos <= 140; pos += 1) { // goes from 90 degrees to 140 degrees // in steps of 1 degree servo3.write(pos); // tell servo to go to position in variable 'pos' delay(10); // waits 10ms for the servo to reach the position } delay(1000); for (pos = 180; pos >= 0; pos -= 1) { //membuka capit // in steps of 1 degree servo5.write(pos); delay(10); } delay(1000); for (pos = 90; pos >= 30; pos -= 1) { // in steps of 1 degree servo4.write(pos); delay(10); } delay(1000); for (pos = 0; pos <= 180; pos += 1) { //menutup capit // in steps of 1 degree servo5.write(pos); delay(10); } delay(1000); //Aksi Robot Untuk mengambil Benda /keadaan lengan turun } Versi Pendek : #include Servo servo1; //inisiasi servo yang digunakan. Servo servo2; Servo servo3; Servo servo4; Servo servo5; int pos = 0; void setuo(){ servo1.attach(6); //Letak Pin dipasang pada pin 6, dst.. servo2.attach(7); servo3.attach(8); servo4.attach(9); servo5.attach(10); } void loop(){ for (pos = 90; pos >=45; post -=1) //Posisi awal 90 derajat menuju ke posisi 45 derajat , dengan dikurangkan per 1 dearajat. { servo2.write(pos); //gerakkan servo 2 lengan delay(10); }delay(1000); for (pos = 90; pos >=45; post -=1) { servo1.write(pos); //gerakkan servo 1 lengan delay(10); }delay(1000); //coding sama dari servo 3-4 //isi coding 3 & 4 for (pos = 180; pos >=0; post -=1) //untuk membuka capit { servo5.write(pos); //gerakkan servo 5 membuka delay(10); }delay(1000); for (pos = 0; pos >=180; post +=1) //untuk menutup capit { servo5.write(pos); //gerakkan servo 5 menutup delay(10); }delay(1000); } Semoga Bermanfaat.
No comments:
Post a Comment