{"id":910,"date":"2021-10-03T00:31:09","date_gmt":"2021-10-02T19:01:09","guid":{"rendered":"https:\/\/botuniverse.in\/?p=910"},"modified":"2022-01-04T07:59:15","modified_gmt":"2022-01-04T02:29:15","slug":"how-to-use-a-ps4-joystick-with-arduino","status":"publish","type":"post","link":"https:\/\/botuniverse.in\/index.php\/2021\/10\/03\/how-to-use-a-ps4-joystick-with-arduino\/","title":{"rendered":"How to use a PS4 joystick"},"content":{"rendered":"\n<h2>Basic Info about the PS4 Joystick<\/h2>\n\n\n\n<p>The PS4 joystick module is a very vital component in making Arduino systems. For this tutorial, we will be using <a href=\"https:\/\/botuniverse.in\/index.php\/product\/ps2-joystick-module\/\">Botuniverse Joystick<\/a>.<\/p>\n\n\n\n<p>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. <\/p>\n\n\n\n<p>First we will make the basic circuit as follows;-<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"603\" src=\"https:\/\/botuniverse.in\/wp-content\/uploads\/2021\/10\/Joystick-With-Arduino-1024x603.png\" alt=\"Coding Scheme of Arduino Uno R3 with A PS4 Joystick Module. \" class=\"wp-image-917\" title=\"Coding Scheme for PS4 Joystick Module and Arduino Uno R3\"\/><\/figure>\n\n\n\n<h2>Connecting the PS4 Joystick Module to Arduino Uno<\/h2>\n\n\n\n<ol><li>Connect GND Pin of the joystick to GND pin of the Arduino                                                      <\/li><li> Connect +5V Pin of the joystick to 5V pin of the Arduino                                                                       <\/li><li>Connect VRx Pin of the joystick to A0 pin of the Arduino                                                       <\/li><li>Connect VRy Pin of the joystick to A1 pin of the Arduino                                                           <\/li><li>Connect SW Pin of the joystick to pin 2 of the Arduino<\/li><\/ol>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>We will first interface the X &amp; Y position of the joystick using the code below. When you upload this code and view the serial monitor, you should see the X &amp; Y positions of the joystick.<\/p>\n\n\n\n<h2>Code for accessing the values of the PS4 Joystick Module in Arduino to print the values in the Serial Monitor<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/botuniverse.in\n\/\/ PS4 Joystick with Arduino Uno\n#define posX A0 \/\/defines the pin(A0) from where we will get the position on the X-axis.\n#define posY A1 \/\/defines the pin(A1) from where we will get the position on the Y-axis.\nvoid setup() {\n  Serial.begin(9600); \/\/Starts the serial monitor from where we can read the X and Y positions from the joystick\n}\n\nvoid loop() {\n  xValue = analogRead(posX); \/\/Reads the X position from the respective pin\n  yValue = analogRead(posY); \/\/Reads the Y position from the respective pin\n\n  Serial.print(\"The x position is \" +xValue); \/\/Prints the X position\n  Serial.print(\"\\t \\t\"); \/\/ Gives a gap between printing the X position and the Y position on the serial port \n  Serial.println(\"The y position is \"yValue); \/\/Prints the Y position on the serial port from the Arduino\n}<\/code><\/pre>\n\n\n\n<p>If you have any queries or suggestions feel free to comment them below or write to us at ideas@botuniverse.in<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[34],"tags":[36,59,60,50,52,63,37,61,64,53,58,65,49,57,51,43,56,54],"_links":{"self":[{"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/posts\/910"}],"collection":[{"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/comments?post=910"}],"version-history":[{"count":7,"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/posts\/910\/revisions"}],"predecessor-version":[{"id":956,"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/posts\/910\/revisions\/956"}],"wp:attachment":[{"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/media?parent=910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/categories?post=910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/tags?post=910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}