4DVolt

Analog joystick: pinout and how to wire it to Arduino

The joystick module has two potentiometers (X and Y axes) and a push button on the stick. See the pinout, how to read the axes on Arduino and test the values in the simulator.

Analog joystick module with 5 pins
Joystick module

Specifications

Axes
2 analog (X and Y) + button
Supply
3.3 V to 5 V
Potentiometers
2 × 10 kΩ
Arduino Uno reading
0 to 1023 (center ≈ 512)
ESP32 reading
0 to 4095 (center ≈ 2048)
Button (SW)
connects to GND when pressed

Pinout

Names vary between makers (VRx/VRy, HORZ/VERT, X/Y), but the function is the same. Check the silkscreen of your module.

Joystick module (5 pins)

1 GND Ground
2 +5V / VCC Power supply
3 VRx / HORZ Horizontal axis analog output
4 VRy / VERT Vertical axis analog output
5 SW / SEL Button: pulled to GND when the stick is pressed

Joystick simulator

Move the axes and press the button to see what the microcontroller reads.

analogRead (Uno)
X · Y
Pin voltage
V · V
digitalRead(SW)

Each axis is a voltage divider: at the extremes the output goes to 0 V or 5 V, and at center it sits near 2.5 V, which gives ≈ 512 on the 0 to 1023 scale.

How to wire it

Connect GND to ground and +5V to the board 5 V (use 3.3 V on an ESP32). Connect VRx to an analog input, for example A0, and VRy to another, for example A1.

The SW button has no resistor on the module. Connect it to a digital pin set as INPUT_PULLUP: the pin reads HIGH when released and LOW when the stick is pressed.

Each axis is a potentiometer between VCC and GND. At center the reading is near half scale (≈ 512 on the Uno), but it is never exactly the same on every module: set a dead zone of about 30 to 50 counts.

On the ESP32 use ADC1 pins (GPIO 32 to 39). ADC2 pins do not work while Wi-Fi is on.

Example code (Arduino)

Sketch that reads both axes and the button and prints the result to the serial monitor.

#define PIN_X  A0
#define PIN_Y  A1
#define PIN_SW 2

void setup() {
  Serial.begin(9600);
  pinMode(PIN_SW, INPUT_PULLUP);
}

void loop() {
  int x = analogRead(PIN_X);   // 0 to 1023
  int y = analogRead(PIN_Y);
  bool pressed = digitalRead(PIN_SW) == LOW;

  Serial.print("X: ");
  Serial.print(x);
  Serial.print("  Y: ");
  Serial.print(y);
  Serial.print("  Button: ");
  Serial.println(pressed ? "pressed" : "released");
  delay(100);
}

Common mistakes

  • Wiring the SW button without INPUT_PULLUP: the pin floats and the button seems to trigger by itself.
  • Expecting exactly 512 at center: use a dead zone or the robot/cursor drifts on its own.
  • Powering the module at 5 V and wiring its outputs to an ESP32: the axes reach 5 V, above the 3.3 V pin limit. Power it at 3.3 V.
  • Using ESP32 ADC2 pins with Wi-Fi on: the reading is always zero.
  • Swapping X and Y: the cursor or motor moves on the wrong axis.

Always check the manufacturer's datasheet for your exact model: pin order can vary between modules.

Frequently asked questions

How does an analog joystick work?

It has two 10 kΩ potentiometers, one per axis. Each wiper moves as you tilt the stick and the output voltage varies from 0 V to VCC. The microcontroller turns that voltage into a number with analogRead().

What values does each axis give?

On the Arduino Uno they range from 0 to 1023 with center near 512. On the ESP32 they range from 0 to 4095 with center near 2048.

Does the joystick have a button?

Yes. Pressing the stick connects the SW contact to GND. Use INPUT_PULLUP on the digital pin and read LOW as "pressed".

Can I use the joystick with an ESP32?

Yes. Power it at 3.3 V, use ADC1 pins and remember the scale is 0 to 4095.

Other components