Arduino Servo Dual Mode Control - Pan/Tilt With Joystick


Introduction: Arduino Servo Dual Mode Control - Pan/Tilt With Joystick

1x Arduino Duemilanovue
2x 3.7V Lithium polymer batteries in parallel
2x HiTEC HS-485 servos
1x Playstation 2 style analog joystick
1x yellow LED

Create with the following references:

For more projects, visit



    • Creative Misuse Contest

      Creative Misuse Contest
    • Oil Contest

      Oil Contest
    • Water Contest

      Water Contest

    10 Discussions


    3 years ago

    can u send me the code and the schematic??


    1 reply

    can you send me the code

    Hi, i wish to thank you for the good work you did. I am a newbie and i am trying to understand if may it be possible to make the servo back to the starting position ( x=0 y=0) with the pression of the joystick button.

    Thanks in advance for your help

    having not found it myself, here's some simple i code i wrote for the "move & stay" control... and it includes acceleration as well. not perfect, but it will get you started.


    #include <Servo.h>

    Servo panServo;      
    Servo tiltServo;      

    int servoPanPosition = 90;
    int servoTiltPosition = 90;
    int joystickPanPin = A0;
    int joystickTiltPin = A1;
    int joystickPanSpeed = 0;
    int joystickTiltSpeed = 0;
    int servoPanPin = 9;
    int servoTiltPin = 10;

    void setup()
      pinMode(servoPanPin, OUTPUT);
      pinMode(servoTiltPin, OUTPUT);

    void loop()
      joystickPanSpeed = (analogRead(joystickPanPin) - 512) / 50;
        // -512 to provide equal +/- numbers
      joystickTiltSpeed = (analogRead(joystickTiltPin) - 512) / -50;
        // negative 50 to reverse direction

      servoPanPosition = constrain((servoPanPosition + joystickPanSpeed), 1, 180);
      servoTiltPosition = constrain((servoTiltPosition + joystickTiltSpeed), 1, 180);
        // constarin function to not exceed servo limits


        // adjustable for overall speed

    1 reply

    Thanks a lot. Your code works very flawlessly. I found others trying to do the same thing but they look too complicated and lengthy the code. Your way is short, easy to understand and can easily implemented to use with 3+ joysticks to control 6 servos. Have a nice day,

    here's a simple way to connect a joystick (which is just 2 potentiometers) to the arduino... made in fritzing:


    I second that motion...why put up a video and not list out how you connected it.

    can you post a picture showing how the servos and joystick
    hook up with the arduino. thanks!

    could you upload the sketch? i cant figure out how to get the servos to maintain the last position when the joystick returns to center. this has kicked my butt like no other. THANKS and great build!!!!