Codey OnlineArduino & ESP32 component library › Joystick module
Joystick module
Input & buttons

Joystick module

This joystick module provides two analog position outputs for the X and Y axes, plus a digital pushbutton switch on SW. It is typically connected to power and ground, with VRX and VRY read by analog inputs and SW read as a digital input.

Width: 41.2 mm

Pinout — Joystick module

Pin Signal Description
GND ground Ground reference for the joystick module and pushbutton circuit
VCC power Power supply input for the joystick potentiometers, typically 5V or 3.3V
VRX analog Analog X-axis output from the joystick potentiometer
VRY analog Analog Y-axis output from the joystick potentiometer
SW digital Digital pushbutton output from pressing the joystick, commonly active-low

Example wiring diagram — Joystick module

From To Wire
board:GND x1:GND black
board:5V x1:VCC red
board:A0 x1:VRX green
board:A1 x1:VRY blue
board:D2 x1:SW yellow

Example Arduino code — Joystick module

This example was written and compile-checked for the arduino-uno. Codey Online adapts it to any other supported board for you.

// Joystick module example for Arduino Uno
// Reads X/Y analog positions and the built-in pushbutton switch.

const int PIN_VRX = A0;
const int PIN_VRY = A1;
const int PIN_SW  = 2;

void setup() {
  pinMode(PIN_SW, INPUT_PULLUP); // SW is commonly active-low
  Serial.begin(9600);
  while (!Serial) {
    ;
  }
  Serial.println("Joystick module demo started");
  Serial.println("Format: X=<0-1023> Y=<0-1023> SW=<PRESSED/RELEASED>");
}

void loop() {
  int xValue = analogRead(PIN_VRX);
  int yValue = analogRead(PIN_VRY);
  bool pressed = (digitalRead(PIN_SW) == LOW);

  Serial.print("X=");
  Serial.print(xValue);
  Serial.print("  Y=");
  Serial.print(yValue);
  Serial.print("  SW=");
  Serial.println(pressed ? "PRESSED" : "RELEASED");

  delay(200);
}

Related components

12V DC power supply

12V DC power supply

5V DC

5V DC

Drukknop

Drukknop

HX711 Load Cell Amplifier

HX711 Load Cell Amplifier

Build your Arduino or ESP32 project with AI

Describe what you want to build. Codey Online writes the code, draws the wiring diagram, compiles it and flashes your board straight from the browser.

Start for free