How to use a PS4 joystick
>
>
How to use a PS4 joystick

Basic Info about the PS4 Joystick

The PS4 joystick module is a very vital component in making Arduino systems. For this tutorial, we will be using Botuniverse Joystick.

The PS4 joystick is similar to two potentiometers joined together. One in the x-axis for the vertical movement and one in the y-axis for horizontal movement. It also has a press button which can be pressed and detected by the Arduino.

First we will make the basic circuit as follows;-

Coding Scheme of Arduino Uno R3 with A PS4 Joystick Module.

Connecting the PS4 Joystick Module to Arduino Uno

  1. Connect GND Pin of the joystick to GND pin of the Arduino
  2. Connect +5V Pin of the joystick to 5V pin of the Arduino
  3. Connect VRx Pin of the joystick to A0 pin of the Arduino
  4. Connect VRy Pin of the joystick to A1 pin of the Arduino
  5. Connect SW Pin of the joystick to pin 2 of the Arduino

The Ground pin is the negative terminal. The +5V pin is the positive. The VRx pin and VRy pin will communicate the position of the joystick with respect to the x-axis and y-axis respectively. The SW Pin will communicate the state of the button present in the PS4 joystick.

We will first interface the X & Y position of the joystick using the code below. When you upload this code and view the serial monitor, you should see the X & Y positions of the joystick.

Code for accessing the values of the PS4 Joystick Module in Arduino to print the values in the Serial Monitor

//botuniverse.in
// PS4 Joystick with Arduino Uno
#define posX A0 //defines the pin(A0) from where we will get the position on the X-axis.
#define posY A1 //defines the pin(A1) from where we will get the position on the Y-axis.
void setup() {
  Serial.begin(9600); //Starts the serial monitor from where we can read the X and Y positions from the joystick
}

void loop() {
  xValue = analogRead(posX); //Reads the X position from the respective pin
  yValue = analogRead(posY); //Reads the Y position from the respective pin

  Serial.print("The x position is " +xValue); //Prints the X position
  Serial.print("\t \t"); // Gives a gap between printing the X position and the Y position on the serial port 
  Serial.println("The y position is "yValue); //Prints the Y position on the serial port from the Arduino
}

If you have any queries or suggestions feel free to comment them below or write to us at ideas@botuniverse.in

Comments

  • If someone has any questions or wants to add anything to the PS4 Joystick with Arduino Guide Post please feel free to post it in the comments section. We are looking forward to your suggestions regarding the PS4 Joystick.

    admin

Leave a Reply

Start typing and press Enter to search

Shopping Cart

No products in the cart.