Joystick Module
Joystick Module
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.
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
void setup ()
{
pinMode (KEYin, INPUT);
Serial.begin (9600);
}
void loop ()
{
int xVal, yVal, buttonVal;
Serial.print("X = ");
Serial.println (xVal, DEC);
Serial.print("Button is ");
if (buttonVal == HIGH){
Serial.println ("not pressed");
}
else{
Serial.println ("PRESSED");
}
delay (500);