How to connect and use an Analog Joystick with an Arduino

In this article, you will learn how to connect and use an Analog Joystick with an Arduino.

This joystick module maybe the best choice for your controller of DIY project. It has two analog input pins to control X, Y axis and also has button input, someone may call it Z axis, but it only input digital signal with 0 or 1.

Components Required

Arduino Uno    [ Amazon / Gearbest / Banggood ]

Joystick module [ Gearbest / Amazon / Banggood ]

Jumper wires x5  [ Amazon / Gearbest / Banggood ]

*Please note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Joystick Module Pin Diagram

joystick module pin diagram


Step 1: Build the circuit

Joystick Module                                 Arduino Uno
SW ————————————– D2
VRx ————————————- A0
VRy ————————————- A1
+5V ————————————- 5V
GND ———————————— GND

Step 2: Download the code

Step 3: Upload the code to your Arduino Uno (any Arduino board)

Now, push the rocker and the coordinates of X and Y axes displayed on Serial Monitor will change accordingly, press the button, and the coordinate of Z=0 will also be displayed.

Interfacing Joystick Module with Arduino

Joystick Module with Arduino Circuit Diagram

arduino joystick circuit

Arduino Code for Joystick Module

/* For more projects and tutorials visit
// Arduino pin numbers
int SW = 2; // digital pin connected to switch output
// A0-> X ; A1-> Y;
void setup() {
  pinMode(SW, INPUT);
  digitalWrite(SW, HIGH);
void loop() {
  Serial.print("Switch:  ");
  Serial.print("X-axis: ");
  Serial.print("Y-axis: ");

If you have any queries, please comment below. We will reach you soon.

Leave a Reply