Goals
#include <Servo.h>
Servo myservoA; // create servo object to control a servo
Servo myservoB;
int leftright = A0;
int updown = A1;
void setup()
{
myservoA.attach(3); // attaches the servo on pin 3 to the servo object
pinMode(leftright, INPUT);
myservoB.attach(5);
pinMode(updown, INPUT);
}
void loop()
{
//Read a value - convert from 0..1023 to 10..170 degrees- and send to servo
int v0 = analogRead(leftright);
int s0 = map(v0,300,600,10,170);
myservoA.write(s0);
//again for the second joystick & servo - go 90 to 170 degrees - we don't want hit the table
int v1 = analogRead(updown);
int s1 = map(v1,0,1023,90,170);
myservoB.write(s1);
}
The power wire is typically red, and should be connected to the 5V pin on the Arduino board.
The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board.
The signal pin is typically yellow, orange or white and should be connected to a digital pin on the Arduino board.
GND: Ground
+5V: Power
VRx: x-axis manipulation
VRy: y-axis manipulation
SW: switch (will not be using this pin)
https://www.arduino.cc/en/Reference/Include
https://www.arduino.cc/en/Reference/Servo
https://www.arduino.cc/en/Reference/Int
https://www.arduino.cc/en/Reference/Void
https://www.arduino.cc/en/Reference/Setup
https://www.arduino.cc/en/Reference/ServoAttach
https://www.arduino.cc/en/Reference/PinMode
INPUT https://www.arduino.cc/en/Reference/Constants
https://www.arduino.cc/en/Reference/Loop
https://www.arduino.cc/en/Reference/AnalogRead
![]() |