0% found this document useful (0 votes)
4 views4 pages

Joystick Module

The Arduino PS2 joystick tutorial explains how to use a thumb-operated joystick as an input device, consisting of two potentiometers and a push button switch. It details the pin configuration for interfacing with an Arduino and provides a sample code to read the joystick's X and Y positions along with the button state. The tutorial emphasizes the importance of using pull-up resistors and suggests implementing software or hardware de-bounce for the button switch.

Uploaded by

mattgirvan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Joystick Module

The Arduino PS2 joystick tutorial explains how to use a thumb-operated joystick as an input device, consisting of two potentiometers and a push button switch. It details the pin configuration for interfacing with an Arduino and provides a sample code to read the joystick's X and Y positions along with the button state. The tutorial emphasizes the importance of using pull-up resistors and suggests implementing software or hardware de-bounce for the button switch.

Uploaded by

mattgirvan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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);

You might also like