1.Arduino uno
2.Joystick
3.Servo*2
4.M to F Jumper wire
5.M to M Jumper wire
6.Half breadboard
CIRCUIT
joystick vcc-arduino +5v
joystick gnd-arduino gnd
joystick x-arduino pinA0
joystick y-arduino pinA1
servo +5v-arduino=5v
servo gnd- arduino gnd
servo sig pin -arduino pin 2,3
CODE
#include <Servo.h>
Servo myservo;
Servo myservo1;
int x = A0;
int y = A1;
void setup() {
// put your setup code here, to run once:
myservo.attach(2);
myservo1.attach(3);
pinMode(x,INPUT);
pinMode(y,INPUT);
pinMode(3,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int xval = analogRead(A0);
int yval = analogRead(A1);
myservo.write(xval);
myservo1.write(yval);
}
Comments
Post a Comment