Mengendalikan Lengan Robot Joy Stick dengan Arduino Uno



 

List Program :

//Sertakan library Servo

#include <Servo.h>


Servo myservo1;

Servo myservo2;

Servo myservo3;

Servo myservo4;

//variabel untuk perhitungan sudut putar

int sudut1;

int sudut2;

int sudut3;

int sudut4;

void setup() {

  myservo1.attach(6);  // servo terhubung pin 6

  myservo2.attach(7);

  myservo3.attach(5);

  myservo4.attach(9);

}


void loop() {

  //membaca sinyal analog input di A0

  sudut1 = analogRead(A0);

  sudut2 = analogRead(A1);

  sudut3 = analogRead(A2);

  sudut4 = analogRead(A3);

  //konversi hasil analog (0-1023) menjadi hasil sudut (0-180)

  sudut1 = map(sudut1, 0, 1023, 0, 180);

  sudut2 = map(sudut2, 0, 1023, 0, 180);

  sudut3 = map(sudut3, 0, 1023, 0, 180);

  sudut4 = map(sudut4, 0, 1023, 0, 180);

  //set posisi sudut motor servo

  myservo1.write(sudut1);

  delay(15);

  myservo2.write(sudut2);

  delay(15);

  myservo3.write(sudut3);

  delay(15);

  myservo4.write(sudut4);

  delay(15);

}


Comments