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/


Comments

author
vjpena (author)2015-01-13

can u send me the code and the schematic??

thanks

author
ZubinS3 (author)vjpena2015-10-17

can you send me the code

author
Pastor Carl (author)2015-06-26

author
GianL (author)2015-01-09

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

author
KevCarrico (author)2012-12-16

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
}

author

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,

author
KevCarrico (author)2013-06-22

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

joystick_001.jpg
author
trandazzo2 (author)2013-04-26

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

author
aaronXtreme (author)2013-02-09

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

author
s_carroll17 (author)2012-12-04

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