Arduino PS2 Joystick Tutorial:
A Versatile Input Device:
The 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.
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 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 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.
Assemble the PS2 Joystick Project:
Note that you use pull up resistor between the key switch and the digital input. Once you move
beyond experimentation, It is highly recommend some sort of software or hardware de-bounce for
this switch as well.
Load Your PS2 Tutorial Sketch:
// 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");
}
else{
Serial.println ("PRESSED");
}
delay (500);