Arduino Servo Dual Mode Control - Pan/Tilt With Joystick

33,458

56

10

Posted

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

Components:
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:
http://arduino-info.wikispaces.com/Brick-Potentiometer-Joystick
http://www.trossenrobotics.com/store/p/6340-Electronic-Brick-Playstation2-Analog-Joystick.aspx
http://www.arduino.cc/en/Tutorial/JoyStick

For more projects, visit http://retardokiddo.blogspot.com/


Share

    Recommendations

    • Microcontroller Contest

      Microcontroller Contest
    • Spotless Contest

      Spotless Contest
    • Science of Cooking

      Science of Cooking
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    10 Comments

    can u send me the code and the schematic??

    thanks

    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);
      panServo.attach(servoPanPin);
      tiltServo.attach(servoTiltPin);
    }


    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

      panServo.write(servoPanPosition);
      tiltServo.write(servoTiltPosition);

      delay(50);
        // adjustable for overall speed
    }

    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:

    joystick_001.jpg

    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!!!!