Arduino Servo Dual Mode Control - Pan/Tilt With Joystick

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/


Be the First to Share

    Recommendations

    • Battery Powered Contest

      Battery Powered Contest
    • Plywood Challenge

      Plywood Challenge
    • Plastic Contest

      Plastic Contest

    10 Discussions

    0
    vjpena
    vjpena

    5 years ago

    can u send me the code and the schematic??

    thanks

    0
    ZubinS3
    ZubinS3

    Reply 5 years ago

    can you send me the code

    0
    GianL
    GianL

    5 years ago on Introduction

    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

    1
    KevCarrico
    KevCarrico

    7 years ago on Introduction

    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
    }

    0
    pheakcalled.jiji
    pheakcalled.jiji

    Reply 6 years ago on Introduction

    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,

    0
    KevCarrico
    KevCarrico

    7 years ago on Introduction

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

    joystick_001.jpg
    0
    trandazzo2
    trandazzo2

    7 years ago on Introduction

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

    0
    aaronXtreme
    aaronXtreme

    7 years ago on Introduction

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

    0
    s_carroll17
    s_carroll17

    7 years ago on Introduction

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