PS2 JOYSTICK

Description

  • Push button
  • One 10k resistor for each axis
  • Works with 5 volts
  • Standard male pins out

This joystick has two 10K potentiometers and a switch. It works with 5V and the breakout board has a 5 pin male header for easy connection.
Use it to mix your RGB LED color, program your robocar, move your gantry… the possibilities are endless.

Supply voltage +5 VDC
Outputs Two analog signals, one digital signal
Connections VCC, ground, X axis, Y axis and key

Easy to connect, with only five cables. You can pin the module on the breadboard and use the male to male jumper cables, or use the male to female jumper cables to connect the module directly to the Arduino-compatible board.

Supply voltage to the board connecting the +5v pin to the 5v power pin and the GND pin to the GND pin. For our example, connect VRy to analog 0 (A0) and VRx to analog 1 (A1). Connect SW to digital 2 (D2). Activate in your Arduino-compatible board the internal pull-up for D2.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*Rewieved by Dr. Mangus for MangoLabs
   
  Joystick example with serial monitor data visualisation
 
   This example code is in the public domain.
 
 based on a sketch by
  Stan
 */
int xPin = A1;
int yPin = A0;
int buttonPin = 2;
 
int xPosition = 0;
int yPosition = 0;
int buttonState = 0;
 
void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
   
  pinMode(xPin, INPUT);
  pinMode(yPin, INPUT);
 
  //activate pull-up resistor on the push-button pin
  pinMode(buttonPin, INPUT_PULLUP);
   
  // For versions prior to Arduino 1.0.1
  // pinMode(buttonPin, INPUT);
  // digitalWrite(buttonPin, HIGH);
   
}
 
void loop() {
  xPosition = analogRead(xPin);
  yPosition = analogRead(yPin);
  buttonState = digitalRead(buttonPin);
   
  Serial.print("X: ");
  Serial.print(xPosition);
  Serial.print(" | Y: ");
  Serial.print(yPosition);
  Serial.print(" | Button: ");
  Serial.println(buttonState);
 
  delay(100); // add some delay between reads
}
  1. In this example we are connecting:
    Arduino  Joystick
    A0     —  VRy
    A1      —  VRx
    D2     —  SW
    GND —  GND
    5V     —  +5V
  2. Download and install the Arduino environment from here or use the web editor.
  3. Download the sketch here and open, or open the Arduino environment and copy the code into a blank sketch.
  4. Connect your board to your computer with the included USB cable.
  5. Select your board in Tools / Board / Arduino Uno.
  6. Select your port in Tools / Port / COM# (Arduino Uno). This may be slightly different depending on your operating system.
  7. Upload by pressing the arrow in the circle to the upper left.
  8. To open the serial monitor, press the magnifying glass icon on the upper right.
  9. Set the baud rate to 9600 on the lower right.
  10. Move your joystick. You should see a text indicating the position of each axis and a message if you press on it.That’s it!