top of page

Analog Joystick Interfacing with Arduino UNO.

What is an Analog Joystick ?

Analog joystick produces two voltages; one corresponding to position with respect to X-axis and another corresponding to the position with respect to Y-axis. The voltages produced depend on the position of the

joystick. The Analog Joystick is similar to two potentiometers connected together, one for the vertical movement (Y-axis) and other for the horizontal movement (X-axis). The joystick also comes with a Select switch. It can be very handy for retro gaming, robot control or RC cars.




Material Required:


Material Quantity

Arduino Uno 1

Analog Joystick 1

Jumper cables 5


Pinout Diagram:

We need 5 connections to the joystick.

The connection are : SW( Switch), Y, X, Voltage and Ground.

“Y and X” are Analog and “Switch” is Digital. If you don’t need the switch then you can use only 4 pins.




Circuit Diagram:


This is circuit diagram of Analog Joystick module in Arduino. There five pins in analog Joystick Module VCC, GND, SW, X, and Y. X and Y are Analog pins and SW is digital. Key will be used when Joystick is pressed. Connect VCC of the module to +5v of Arduino and GND of the module to Arduino Ground. Now, connect X to Analog pin A0 and Y to Analog pin A1 of Arduino..




Tested Programming Code:




This is code for interfacing analog Joystick Module in Arduino. First initialized the pin numbers of Joystick Module. In setup, the Serial Monitor is started at 9600 Baud and initialized Joystick pins as input. In the loop, read the button state and stored in a variable. Print the values to the Serial Monitor.



const int joystick_x_pin = A2;

const int joystick_y_pin = A1;


void setup() {

Serial.begin(9600); /* Define baud rate for serial communication */


}

void loop() {

int x_adc_val, y_adc_val;

float x_volt, y_volt;

x_adc_val = analogRead(joystick_x_pin);


y_adc_val = analogRead(joystick_y_pin);


x_volt = ( ( x_adc_val * 5.0 ) / 1023 ); /*Convert digital value to voltage */

y_volt = ( ( y_adc_val * 5.0 ) / 1023 ); /*Convert digital value to voltage */

Serial.print("X_Voltage = ");


Serial.print(x_volt);

Serial.print("\t");

Serial.print("Y_Voltage = ");


Serial.println(y_volt);

delay(100);

}


Checking Values on Serial Monitor:


After Uploading The program Successfully into the Arduino Board , we Can Check the Values of X and Y Serial

Monitor The Image of the Serial monitor Is shown Below :




Precautions:

1. Double check the connections before powering on the circuit.

2. Don’t use loose jumper cables.

3. Check whether proper board is selected from Arduino IDE.

4. Ensure proper placement of sensor for correct working.

5. Connect the Wiper pin of potentiometer correctly.

6. Don’t lose hope if Joystick does not runs properly for the first time, try again.


Conclusion:


You can successfully display data on a the Serial Monitor of the Joystick in simplest way using Arduino. Many forms of data can be displayed on this display, whether it can be a data from sensor or anything else.

GET IN TOUCH

We'd love to hear from you

bottom of page