JOYSTICK TO ARDUINO

Joystick Control Using Arduino Uno — 5-Wire Setup | MakeMindz
🕹️ Intermediate Project

Joystick Control
Using Arduino Uno

Interface a joystick module with Arduino in just 5 wires. Read X-axis, Y-axis, and push-button values live — perfect for robots, RC cars, and game controllers.

5-Wire Setup Arduino UNO Analog + Digital I/O Serial Monitor Output ⏱ 20 min
📌 What you'll build A joystick that reports X/Y coordinates (0–1023) and a button state to the Serial Monitor in real-time. This is the foundation for controlling robots, drones, servo arms, and game menus with Arduino.
01

Joystick Pin Connections (5 Wires)

Joystick Pin Arduino Function
VRX A0 X-axis analog input (0–1023)
VRY A1 Y-axis analog input (0–1023)
SW Pin 2 Push button — LOW when pressed
+5V 5V Power supply
GND GND Ground reference
02

Circuit Diagram

joystick_circuit.json
Joystick → Arduino Uno — Circuit Diagram ARDUINO UNO 5V GND A0 A1 D2 ATmega328P 16 MHz USB PWR JOYSTICK MODULE SW KY-023 VRX VRY SW +5V GND Serial Monitor (9600) X: 512 | Y: 510 X: 0 | Y: 512 X: 512 | Y: 1023 Button: Pressed Button: Released ────────────── A0 (X-axis) A1 (Y-axis) D2 (Button SW) Serial Wire Legend VRX → A0 (X-axis) VRY → A1 (Y-axis) SW → D2 (Button) +5V → 5V Power GND → GND ✓ Only 5 wires needed!
Complete wiring uses 5 connections: VRX→A0, VRY→A1, SW→D2, +5V→5V, GND→GND
03

Step-by-Step Wiring

VRX

X-Axis Output

Reads horizontal joystick movement as analog voltage

Joystick VRX Arduino A0
VRY

Y-Axis Output

Reads vertical joystick movement as analog voltage

Joystick VRY Arduino A1
SW

Push Button

Active LOW — goes to GND when joystick is pressed down. Requires INPUT_PULLUP in code.

Joystick SW Arduino Digital Pin 2
+5V

Power Supply

Powers both internal potentiometers inside the module

Joystick +5V Arduino 5V
GND

Ground

Common ground for stable voltage reference

Joystick GND Arduino GND
⚠️ Important: INPUT_PULLUP The SW pin needs pinMode(swPin, INPUT_PULLUP) in your setup. This activates Arduino's internal pull-up resistor so the button reads HIGH normally and LOW when pressed. Without it, the pin floats and gives random values.
04

How the Joystick Works

Inside the module are two potentiometers (one per axis). Moving the stick changes resistance → changes voltage → Arduino reads it as 0–1023.

Center (resting)
~512
Joystick not touched
Full Left / Down
≈ 0
X → left; Y → down
Full Right / Up
≈ 1023
X → right; Y → up
Button Press (SW)
LOW
Pressed → 0V → LOW

Joystick Direction → Value Map

↑ UP
Y → 1023
← LEFT
X → 0
CENTER
X,Y ≈ 512
RIGHT →
X → 1023
↓ DOWN
Y → 0
05

Arduino Code

joystick_control.ino
// ── Joystick Control | MakeMindz.com ──────────────
// Reads X-axis, Y-axis, and push button from KY-023
// joystick module. Outputs live data via Serial Monitor.

// ── Pin Definitions ──────────────────────────────
const int xPin  = A0;  // VRX → Horizontal (X) axis
const int yPin  = A1;  // VRY → Vertical   (Y) axis
const int swPin = 2;   // SW  → Push button (active LOW)

// ── Setup ────────────────────────────────────────
void setup() {
  Serial.begin(9600);
  pinMode(swPin, INPUT_PULLUP);  // Internal pull-up → HIGH by default
  Serial.println("Joystick Ready — Move to see values!");
}

// ── Main Loop ────────────────────────────────────
void loop() {
  int xValue     = analogRead(xPin);    // 0 (left) → 1023 (right)
  int yValue     = analogRead(yPin);    // 0 (down) → 1023 (up)
  int buttonState = digitalRead(swPin); // LOW = pressed, HIGH = released

  // Print formatted data to Serial Monitor
  Serial.print("X: ");
  Serial.print(xValue);
  Serial.print(" | Y: ");
  Serial.print(yValue);
  Serial.print(" | Button: ");
  Serial.println(buttonState == LOW ? "Pressed" : "Released");

  delay(200);  // Read every 200ms
}
📟 What you'll see in Serial Monitor Open Arduino IDE → Tools → Serial Monitor → set to 9600 baud. You'll see live output like:
X: 512 | Y: 512 | Button: Released
X: 12 | Y: 1020 | Button: Pressed
06

Download the Code

⬇ Download joystick_control.ino

Get the complete, commented Arduino sketch from Google Drive

Download Code (.ino)
07

How to Test Your Circuit

1

Wire the module

Connect all 5 pins following the wiring table above. Double-check VRX→A0, VRY→A1, SW→D2.

2

Upload the code

Open Arduino IDE, paste or open the .ino file, select Board: Arduino UNO and your COM port, then click Upload.

3

Open Serial Monitor

Go to Tools → Serial Monitor and set baud rate to 9600. You should immediately see X/Y readings around 512.

4

Move the joystick

Push left/right — watch the X value drop to ~0 or rise to ~1023. Push up/down to see Y values change.

5

Press the joystick down

Press the stick like a button — Serial Monitor should print "Button: Pressed". Release to see "Released".

08

Applications

🤖
Robot Direction Control
🚗
RC Car Controller
🎮
Game Controller
⚙️
Servo Motor Control
🚁
Drone Prototype
📋
Menu Navigation
🦾
Robotic Arm
🔧
CNC Control
📚

What You Learn

📊 Analog input reading (0–1023) 🔘 Digital input detection 🔩 Potentiometer principles 📡 Serial communication 🔌 INPUT_PULLUP resistors 🎛 Interactive control systems
🚀 Level Up Once you can read the joystick, try using the X/Y values to control a servo motor (map 0–1023 to 0°–180°), drive an L293D motor driver, or display position on an LCD screen!

More Arduino Projects

Beginner

Intermediate

Advanced

Comments

try for free