Arduino PS2 Joystick Tutorial: Keyes KY-023 Deek Robot

A Versatile Input Device

Arduino PS2 Joystick LogoThe PS2 style joystick is a thumb operated device, that when put to creative use, offers a convenient way of getting operator input.   Its fundamentally consists of two potentiometers and a push button switch.

The two potentiometers indicate which direction the potentiometer is being pushed.

The switch sends a low (or ground) when the joy stick knob is pressed.


Finding a PS2 Joystick

There are a few slightly different varieties offered, but that all operate pretty much the same.

eBay     Amazon     AliExpress    Bang Good

Arduino PS2 Joystick Pin Outs

This input device interfaces to your Arduino via five pins.   Three of which are inputs to your Arduino, while the remaining two supply voltage and ground.

Arduino PS2 Joystick Pin Outs

Arduino PS2 Joystick Schematic

As you can see in the schematic below,  full deflection of a potentiometer in either direction will provide ground or the supply voltage as an output.

Arduino PS2 Joystick Schematic

Arduino PS2 Joystick Output Orientation

In order to put this thumb control to use,  you are going to want to understand which direction is X and which direction is Y.  You will also need to decipher the direction it is being pushed in either the X or the Y direction.

In this tutorial we are using analog inputs to measure the joystick position.  The analog inputs provided indications that range between 0 and 1023.

The graphic below shows the X and Y directions and also gives an indication of how the outputs will respond when the joystick is pushed in various directions.  Keep in mind,  the graphic you see is based on my Deek-Robot model and may in fact differ a little with yours.   It that’s the case, experiment a little and draw your own sketch so that the orientations are clear.

Arduino PS2 Joystick Output OrientationArduino PS2 Joystick Tutorial

Assemble the PS2 Joystick Project

Note that I use a pull up resistor between the key switch and the digital input.   Once you move beyond experimentation, I highly recommend some sort of software or hardware debounce for this switch as well.


Arduino PS2 Joystick Tutorial Hook UpLoad Your PS2 Tutorial Sketch


// Henry's Bench
// Module KY023

int Xin= A0; // X Input Pin
int Yin = A1; // Y Input Pin
int KEYin = 3; // Push Button

void setup ()
  pinMode (KEYin, INPUT);
  Serial.begin (9600); 
void loop ()
  int xVal, yVal, buttonVal;
  xVal = analogRead (Xin);
  yVal = analogRead (Yin);
  buttonVal = digitalRead (KEYin);
  Serial.print("X = ");
  Serial.println (xVal, DEC);
  Serial.print ("Y = ");
  Serial.println (yVal, DEC);
  Serial.print("Button is ");
  if (buttonVal == HIGH){
    Serial.println ("not pressed");
    Serial.println ("PRESSED");
  delay (500);