Joypads –> Arduino

By , January 2, 2010 18:25

New Thumbstick

Do you have an old analog PS1 / 2 controller or a PC joypad? Or an used joystick with the old soundcard connector?

They work great as inputs for an Arduino! In fact, they are just two potentiometers, mounted on two axis.

When you open the case, you probably will find the potis mounted on a board, which includes all necessary connections. If you are lucky, you can use the existing cables on that board:

  • 2 outer pins of each poti are connected to + and – 5V
  • center pin changes voltage, depending on poti- resistance / position

Simply connect the power circuit to Arduino +/- voltage pins and the center pin to one analog input and analogRead() will read the values almost like a poti:

  • center position:  ~ 500
  • full down:  ~0
  • full up:  ~1023

The potis are often not so accurat, but you can easily implement some tolerance in software,

if the values are too much shaking

Code:

int potPinX = 1;
int potPinY = 2;

int valueX = 0;
int valueY = 0;

void setup() {
  Serial.begin(9600);          //  setup serial
}

void loop() {

  valueX = analogRead(potPinX);
  valueY = analogRead(potPinY);
  Serial.println(valueX);
  Serial.println(valueY);
}

.. and you have the X /Y axis values stored in variables.
+ output to serial console via USB for debugging.

Comments are closed

WordPress Open Source Blog System
SynOptX Lab Theme