JOYSTICK TO ARDUINO

 

Joystick Control Using Arduino Uno

Learn how to interface a joystick module with Arduino Uno and read its X-axis, Y-axis, and push-button values. This simple 5-wire connection project is perfect for beginners in robotics, game controls, and remote control systems.


Joystick to Arduino Connection (5 Wires Only)

The joystick module has 5 pins:

Joystick PinArduino ConnectionFunction
VRXA0X-axis analog input (0–1023)
VRYA1Y-axis analog input (0–1023)
SWPin 2Push button (LOW when pressed)
+5V5VPower supply
GNDGNDGround

That’s it — just five wires!


How the Joystick Works

Inside the joystick module:

  • It contains two potentiometers

  • Each potentiometer outputs a voltage between 0V to 5V

  • Arduino converts this voltage into digital values from 0 to 1023


 Axis Behavior

  • Center Position: Around 512

  • Move Left: X value decreases (toward 0)

  • Move Right: X value increases (toward 1023)

  • Move Up: Y value increases

  • Move Down: Y value decreases


 Button (SW Pin)

  • When pressed → LOW

  • When released → HIGH

  • Works like a normal push button (internally connected to ground when pressed)


 Arduino Code Example

const int xPin = A0;
const int yPin = A1;
const int swPin = 2;

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

void loop() {
int xValue = analogRead(xPin);
int yValue = analogRead(yPin);
int buttonState = digitalRead(swPin);

Serial.print("X: ");
Serial.print(xValue);
Serial.print(" | Y: ");
Serial.print(yValue);
Serial.print(" | Button: ");
Serial.println(buttonState == LOW ? "Pressed" : "Released");

delay(200);
}

What This Code Does

  • analogRead(A0) → Reads horizontal movement

  • analogRead(A1) → Reads vertical movement

  • digitalRead(2) → Detects button press

  • Serial Monitor displays live joystick data


Applications of Joystick with Arduino

✅ Robot direction control
✅ RC car controller
✅ Game controller
✅ Servo motor control
✅ Drone prototype control
✅ Menu navigation system
✅ CNC or robotic arm control


Educational Benefits

Students learn:

  • Analog input reading

  • Digital input detection

  • Understanding potentiometers

  • Serial communication

  • Basic interactive control systems

This is one of the most important beginner projects in robotics and embedded systems.

Comments