Arduino + 2 Servos + Thumbstick (joystick)




About: Evo 8, Honda K, B Engines Mods
In my other 2 Arduino tutorials I have help new users to play tones and making 2 servos move with a mouse.
This time I will help you move the same 2 servos with a thumbstick.
And again I have surf the internet to see If there are tutorials that clear to understand specially for
the beginner Arduino user and, I have not found one.
To move 2 servos with the thumbstick is way easier and painless than using the mouse. And the reason for this is that some times the processing software does not work correct or there is a conflict between the arduino software and the processing software.
For all the connections I will use the bread board.

Dont forget to vote for me on the Arduino challenge!!!
Enjoy and have fun!!!! ;)

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Materials

Hardware: (bought @ Radioshack)

Arduino Board (I am using the UNO REV 3 version)
2 Parallax servos
Parallax Thumbstick (joystick)
Small Bread Board
Solderless Breadboard Jumper Wire
Something to see the 2 servos movement ( I am using a broken Web Cam and some legos not shown, for this tutorial)

Step 2: Connecting the Servos

I will start with the 2 servos. (I am using the bread board to make all connections easy)
You can use the picture for more information.

Servo Up/Down                   Arduino                                       Servo Right/Left                     Arduino

Red Cable------------------------ 5V                                              Red Cable------------------------ 5V
Black Cable---------------------- GND                                         Black Cable---------------------- GND
Yellow or White Cable--------- PWM (4)                                Yellow or White Cable--------- PWM (10)

Step 3: Connecting the Thumbstick (joystick)

The follwing connection will confuse you a little, just follow the picture.
Again using a bread board will make things easier.

1. The thumbstick has one U/R+ and one L/R+ this two connections will provide power to the joystick. Connect them to the Arduino 5V connection.
2.  Also the joystick has two L/R connections and two U/D connections it is important that you connect both of them to the respective arduino pin.
3.  Do the same to both GND connections on the joystick.

Thumbstick                     Arduino

L/R+  ----------------------     5V
U/D+ ----------------------     5V
GND  GND ---------------    GND
U/D U/D ------------------     Analog 4
L/R L/R -------------------    Analog 3

NOTE: Always double check the connections!!!

Step 4: The Code

Not much to explain... just copy and paste the following code to the arduino software.
Always test (compile) the code before uploading it to the Arduino Board.
When you upload the code to the arduino the servos should not move until you use the joystick.


#include <Servo.h>

const int servo1 = 3;       // first servo
const int servo2 = 10;       // second servo
const int joyH = 3;        // L/R Parallax Thumbstick
const int joyV = 4;        // U/D Parallax Thumbstick

int servoVal;           // variable to read the value from the analog pin

Servo myservo1;  // create servo object to control a servo
Servo myservo2;  // create servo object to control a servo

void setup() {

  // Servo  
  myservo1.attach(servo1);  // attaches the servo
  myservo2.attach(servo2);  // attaches the servo

  // Inizialize Serial

void loop(){

    // Display Joystick values using the serial monitor

    // Read the horizontal joystick value  (value between 0 and 1023)
    servoVal = analogRead(joyH);          
    servoVal = map(servoVal, 0, 1023, 0, 180);     // scale it to use it with the servo (result  between 0 and 180)

    myservo2.write(servoVal);                         // sets the servo position according to the scaled value    

    // Read the horizontal joystick value  (value between 0 and 1023)
    servoVal = analogRead(joyV);           
    servoVal = map(servoVal, 0, 1023, 70, 180);     // scale it to use it with the servo (result between 70 and 180)

    myservo1.write(servoVal);                           // sets the servo position according to the scaled value

    delay(15);                                       // waits for the servo to get there


* Display joystick values
void outputJoystick(){

    Serial.print ("---"); 
    Serial.println ("----------------");

Step 5: Torubleshooting

1.  The servos won't move.
A.  Check the connections, remember in this tutorial we use PWM pins for the servos and the Analog pins for the joystick.
2.  When I upload the code to the board the servos, they start vibrating.
A. It means that either U/D+ or L/R+ are not properly connected. Double check your connections. You have to disconnect the usb from the     board to verify connections try to review the connections on step 3.
3. I double check the connections and the servos wont move.
A. Take out the joystick and reconnect it again in the bread board by pressing it down to make sure it is connected. Connections have to be tight from the joystick to the bread board.

Any other help or issues you have feel free to let me know and I will be glad to help all of you. ;)

Arduino Challenge

Participated in the
Arduino Challenge

10 People Made This Project!


  • CNC Contest

    CNC Contest
  • Make it Move

    Make it Move
  • Teacher Contest

    Teacher Contest

102 Discussions


Question 19 hours ago

This was really helpful, thanks! Everything works pretty great and now I'd like to refine the code a bit. The only trouble is that the action of these servos is pretty herky-jerky right now... does anyone have a suggestion to dampen the action? Seems like it takes a lot of movement and then jerks into position. Much less smoothly than a conventional RC receiver action.

Mark 42

Question 10 months ago

Can a 4 channel system using 2 joysticks be done on a single arduino module?


Question 11 months ago on Step 5

hello, Great project I have already ordered the 2 axis thumb switch, can't wait.

One question, is there a way to slow down how fast the servo moves? I want to hook this to an outdoor security camera to scan my whole property.


2 years ago

hi im trying to acheive the same thing using motors and l298n module/motor driver , this picture explains it , i rly hope someone can help me! its for my exo skeleton project

what i plan to do with exo.png

2 years ago

Works great! just tweaked the code a bit to average 5 inputs limit the noise

1 reply

Reply 2 years ago

Hi abilly I'd love to see your tweaked code it sounds like it would be a big improvement.


2 years ago

HI there i make control servo with laptop mouse video

do you wan't to see the video click the link


2 years ago

Great code. worked perfectly. I have modified it to use it on my project.

Thank you.

prafull porwal

2 years ago

sir when we release joystick camera comes into initial position but i want that when when we release joystick then it remain in his current position.


2 years ago

having trouble when compiling. tried tweaking code and still does not want to work.


2 years ago

is there a way to do this without the breadboard? meaning can i solder the connections or do i need to have a breadboard for this to work? im making a mask with moving eyebrows and im a bit of a noob with this stuff. would like to have the servos connected to the mask, both connected to the same up/down axis and have the arduino/battery attached to the back of the mask and have the wires run long enough to have the thumbstick be able to be used in your pocket, and essentially would like it to function with up=lifts the eyebrows, no action=centers eyebrows and down=lowers the eyebrows, any help would be greatly appreciated


2 years ago

Great tutorial, thank you!

Victor EmmanuelS

2 years ago

This is great!

I have an idea for the push-button to keep the position:

It can be used as to set "position lock" by acting as a switch when to read the analog input from the joystick. A click would allow read the analog input (activate the servo control), a second click would save the current analog values and keep it as such (disconnecting the joystick signal). Then clicking the button would reactivate servo control. :-)


2 years ago

how to develop an android app that works exactly like the thumbstick(joystick) in this project? can anybody help me? i want to do this projects but i will use a smartphone and bt module. any help will be appreciated :) tnx


3 years ago



3 years ago

hey guys i want a little help for my project...........
i want to control 4 servos with 2 joystick module,( with one joystick i want to control 2 servos from each axis)

i made the servo to rotate continuous by using some help from you tube

now i want that if i push the stick up than the servo start rotating and keep rotating until i release the pressure and when i release the pressure from stick the servo should stop immediately and when i push the stick down the servo start rotating in opposite direction (same for other axis with other servo ) , speed doesn't matter for me in this case i just want to use the stick as switches like when i push up it should start rotate clockwise and when i push down it start rotate counter clockwise,

can somebody please help me with the code and connection to the arduino.

thanks in advance.. :)


3 years ago

Is there a way for me to use a different joystick because I only have this one

2 replies
Arduino TechScienceG2

Reply 3 years ago

yes you can use this just connect 5v to arduino 5v and gnd to gnd and X to analog 1 and Y to analog 2 and leave sw

ScienceG2Arduino Tech

Reply 3 years ago

I already bought the parallax joystick but thanks for your help