Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home Arduino & Microcontrollers

Arduino Joystick Module: Build a 2-Axis Input Controller

Arduino Joystick Module: Build a 2-Axis Input Controller

March 11, 2026 /Posted byJayesh Jain / 0

The Arduino joystick module tutorial is one of the most popular starting points for makers who want to build interactive projects. Whether you’re designing a DIY robot controller, a first-person game interface, or a motorised camera gimbal, understanding how to read a 2-axis joystick with Arduino opens a world of possibilities. The joystick module is cheap, easy to wire, and uses familiar analog input principles — making it perfect for beginners and intermediate makers alike. In this complete guide, we’ll cover how the module works, how to wire it to your Arduino, read its values, and build three practical projects.

Table of Contents

  • How the Joystick Module Works
  • Components You’ll Need
  • Wiring the Joystick to Arduino
  • Basic Arduino Code: Reading X, Y, and Button
  • Calibration and Dead Zone Handling
  • Three Practical Projects
  • Troubleshooting Common Issues
  • Frequently Asked Questions
  • Conclusion

How the Joystick Module Works

The standard Arduino joystick module — also called the KY-023 or PS2 joystick module — is essentially two potentiometers mounted at 90 degrees to each other, combined with a push-button switch. When you move the stick left or right, you change the resistance on the X-axis potentiometer. Push it forward or backward and the Y-axis potentiometer changes. Press the stick down like a PS2 controller button and the built-in switch closes.

Each potentiometer is a simple voltage divider. With 5V applied across the ends and the Arduino reading the wiper (middle pin), moving the stick produces a voltage between 0V (one extreme) and 5V (other extreme). The center resting position gives approximately 2.5V, or a 10-bit ADC reading of about 512 out of 1023. This clean, linear response is what makes the joystick so easy to work with in code.

The push button (SW pin) is connected to GND through the switch. The module’s VRx and VRy pins output analog voltages corresponding to the stick position. Most modules run on 3.3V or 5V logic, making them compatible with both 3.3V (Nano 33, ESP32) and 5V (Uno, Mega) Arduino boards.

Recommended: Arduino Uno R3 Beginners Kit — The complete starter kit includes an Arduino Uno and all the jumper wires, breadboard, and components you need to follow this joystick tutorial from start to finish.

Components You’ll Need

To follow this tutorial, gather the following components:

  • Arduino Uno or Nano (any Arduino with analog pins works)
  • Joystick module (KY-023) — available at most Indian electronics stores
  • Jumper wires — at least 5 (male-to-female for connecting to module pins)
  • Breadboard — for clean wiring (optional but recommended)
  • USB cable — for uploading code and serial monitoring
  • Optional: OLED or TFT display — to visualise joystick position

Total component cost for this project, assuming you already have an Arduino: approximately ₹50–₹80 for the joystick module. The entire project with a beginner kit costs under ₹700.

Wiring the Joystick to Arduino

The joystick module typically has 5 pins. Here is the standard wiring for an Arduino Uno:

Joystick Pin Arduino Pin Description
GND GND Ground
+5V 5V Power supply
VRx A0 X-axis analog output
VRy A1 Y-axis analog output
SW D2 Push button (active LOW)

Connect with jumper wires. If your joystick module doesn’t have a 5V pin (some run on 3.3V only), use the 3.3V pin on Arduino instead. For breadboard-less wiring, female-to-male jumper wires connect directly from Arduino’s header pins to the module.

Important note for 3.3V boards (Nano 33, RP2040): Use the 3.3V supply pin, not 5V. The analog input range will be 0–3.3V instead of 0–5V, but analogRead() will still return 0–1023 because the ADC reference is automatically matched to the supply voltage.

Basic Arduino Code: Reading X, Y, and Button

Here is the fundamental code to read all three joystick inputs and print them to the Serial Monitor:

// Arduino Joystick Module Basic Reading
// Zbotic.in Tutorial

const int xPin = A0;    // X-axis potentiometer
const int yPin = A1;    // Y-axis potentiometer
const int swPin = 2;    // Push button switch

void setup() {
  Serial.begin(9600);
  pinMode(swPin, INPUT_PULLUP); // SW is active LOW
  Serial.println("Joystick Module Ready");
}

void loop() {
  int xVal = analogRead(xPin);   // 0 to 1023
  int yVal = analogRead(yPin);   // 0 to 1023
  int swVal = digitalRead(swPin); // LOW when pressed

  Serial.print("X: ");
  Serial.print(xVal);
  Serial.print(" | Y: ");
  Serial.print(yVal);
  Serial.print(" | Button: ");
  Serial.println(swVal == LOW ? "PRESSED" : "not pressed");

  delay(100); // Update 10 times per second
}

Upload this code, open the Serial Monitor at 9600 baud, and move the joystick. You’ll see X and Y values change from roughly 0 to 1023. The centre position should read approximately 512 on both axes. Press the stick down and the button line changes to “PRESSED”.

Calibration and Dead Zone Handling

Real joystick modules are not perfectly centred. The resting position might read 480–540 on both axes due to manufacturing tolerances. When using joystick input to control a motor or robot, this tiny off-centre value causes unwanted drift. The solution is a dead zone: a range around the centre where you treat the input as zero.

// Map joystick with dead zone
// Returns -100 to +100, with dead zone at centre
int mapWithDeadZone(int rawVal, int centre, int deadZone) {
  int diff = rawVal - centre;
  if (abs(diff) < deadZone) return 0;
  if (diff > 0) {
    return map(diff - deadZone, 0, centre - deadZone, 0, 100);
  } else {
    return map(diff + deadZone, -(centre - deadZone), 0, -100, 0);
  }
}

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

void loop() {
  int x = mapWithDeadZone(analogRead(A0), 512, 30);
  int y = mapWithDeadZone(analogRead(A1), 512, 30);
  Serial.print("X: "); Serial.print(x);
  Serial.print(" | Y: "); Serial.println(y);
  delay(50);
}

The deadZone parameter (30 in the example) covers the typical variation range. Adjust based on your specific module — read the resting value, then set the dead zone to ±20–40 around it. For precision applications, add a calibration routine that reads the centre value at startup.

Three Practical Projects

Project 1: Servo Gimbal Controller

Use the joystick X axis to pan a servo and Y axis to tilt a second servo. Map the joystick’s 0–1023 range to the servo’s 0–180 degree range using Arduino’s map() function. Add the dead zone code above to prevent jitter when the stick is at rest. This is the foundation of a camera stabiliser, robotic arm, or laser pointer mount.

#include <Servo.h>
Servo panServo, tiltServo;

void setup() {
  panServo.attach(9);
  tiltServo.attach(10);
  pinMode(2, INPUT_PULLUP);
}

void loop() {
  int panAngle = map(analogRead(A0), 0, 1023, 0, 180);
  int tiltAngle = map(analogRead(A1), 0, 1023, 0, 180);
  panServo.write(panAngle);
  tiltServo.write(tiltAngle);
  delay(15);
}

Project 2: 2WD Robot Motor Controller

Map joystick X/Y to left and right motor speeds for differential drive control. Push Y forward to drive ahead, pull back to reverse, push X left/right to turn. Use the L298N motor driver (widely available in India) between the Arduino and motors. The joystick button can serve as an emergency stop.

Project 3: USB Game Controller (HID)

Using an Arduino Leonardo or Micro (which support USB HID natively), you can make the joystick appear as a real game controller to your PC. The Arduino joystick library from Matthew Heironimus makes this straightforward. This project is excellent for understanding USB protocol basics and is a crowd-pleaser for demo days.

Recommended: Arduino Leonardo without Headers — For the USB HID game controller project, you need the Arduino Leonardo. It has native USB and can appear as a keyboard, mouse, or joystick to your computer — the Uno cannot do this.
Recommended: 2.4″ Touch Screen TFT Display Shield for Arduino — Combine this with your joystick to create a visual joystick tester or a simple game. The TFT lets you render a cursor that moves with the joystick position in real time.

Troubleshooting Common Issues

Joystick reads only 0 or 1023, nothing in between

Check your wiring. The VRx or VRy pin may be floating (not connected) or connected to GND/VCC instead of the analog pin. A floating analog pin reads random values; a pin tied to GND reads 0 and tied to 5V reads 1023. Recheck your jumper wire connections at both the Arduino and module ends.

Button always reads PRESSED regardless of state

You likely forgot pinMode(swPin, INPUT_PULLUP). Without the internal pull-up resistor enabled, the SW pin floats and reads LOW (pressed) even when not pressed. The INPUT_PULLUP mode enables a ~20kΩ pull-up resistor internally, so the pin reads HIGH at rest and LOW when the button connects it to GND.

Joystick drifts when not touched

Implement the dead zone code described in the calibration section. A dead zone of ±30 to ±50 counts around the centre position eliminates resting drift for most modules. If drift persists beyond that range, your potentiometer may be worn — replace the module.

Values jump randomly or are noisy

Add a small capacitor (100nF) between the VRx/VRy pins and GND on a breadboard, close to the module. This filters high-frequency noise. In code, average multiple readings: take 5 analogRead() samples and use the average value for smoother output.

Recommended: Multifunction Shield for Arduino Uno/Leonardo — Expand your joystick projects with this shield that adds 4 buttons, a buzzer, LED display, and potentiometers — great for building a complete mini control panel alongside your joystick module.

Frequently Asked Questions

Can I use two joystick modules with one Arduino Uno?

Yes. The Arduino Uno has 6 analog inputs (A0–A5). Two joystick modules use 4 analog pins (X1, Y1, X2, Y2) and 2 digital pins for the buttons. This fits within the Uno’s pin count. Use analog pins A0–A3 and digital pins D2 and D3 for the two buttons. The Arduino Mega 2560 offers 16 analog inputs if you need more channels.

What is the difference between KY-023 and PS2 joystick module?

They are functionally identical — same potentiometer layout, same 5-pin interface. “KY-023” is the sensor kit designation used by Chinese component kits, while “PS2 joystick” refers to the PlayStation 2 thumbstick mechanism used inside. Both work identically with the code in this tutorial.

Can I use a joystick with ESP32 or Raspberry Pi Pico?

Yes. The joystick outputs standard analog voltage, readable by any microcontroller with an ADC. Use the 3.3V supply for 3.3V-logic boards. For Raspberry Pi (not Pico), you’ll need an external ADC like the MCP3008 since standard Raspberry Pi lacks onboard ADC pins.

How do I make the joystick control a drone or RC car?

Combine the joystick with an NRF24L01 or HC-12 radio module for wireless control. Map joystick values to motor speed or servo angles on the receiver side. This is a popular project in Indian maker communities — search for “Arduino RC car NRF24L01” for complete tutorials.

Does the joystick module work at 3.3V?

Yes. Most KY-023 modules work from 3.3V to 5V. At 3.3V, the potentiometer output spans 0–3.3V. As long as your Arduino’s analog reference is also 3.3V (or you use analogReference(EXTERNAL) correctly), readings will be accurate. Most 3.3V-native boards handle this automatically.

Conclusion

The Arduino joystick module is one of the most satisfying beginner components because the feedback is immediate and physical. Within minutes of wiring and uploading your first sketch, you’ll see values change in real time as you move the stick — a tangible connection between hardware and software that rarely gets old. Start with the basic serial monitor example, add dead zone calibration, then pick one of the three projects to make something practical. The skills you build here — analog reading, mapping values, handling buttons — are foundational for nearly every interactive Arduino project you’ll build in the future.

Ready to build? Find all your Arduino boards, sensors, and accessories at Zbotic.in Arduino category — fast delivery across India.

Tags: 2-axis controller, analog input, Arduino, game controller, joystick module, tutorial
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
Arduino Nicla Sense ME: Enviro...
blog arduino nicla sense me environmental sensing at the edge 594769
blog arduino seven segment display driver max7219 for digits 594772
Arduino Seven-Segment Display ...

Related posts

Svg%3E
Read more

Arduino Batch Programming: Flash Multiple Boards Quickly

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Based Radar System with Ultrasonic Sensor

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Automatic Plant Monitor: Sunlight, Moisture, Temperature

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Lie Detector: GSR Sensor Polygraph Project

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Metal Detector: Build a Treasure Finder

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now