The joystick module connects to Arduino Uno using 5 wires: VRX to pin A0 for horizontal movement, VRY to pin A1 for vertical movement, SW to pin 2 for the button, plus 5V and GND for power. The joystick contains two potentiometers that output analog voltage (0-5V) based on position, which Arduino reads as values from 0 to 1023, with center position around 512. Moving left/right changes the X value, moving up/down changes the Y value, and pressing down activates the button switch. The Arduino code uses analogRead() for the X/Y axes and digitalRead() for the button to detect joystick movements and create interactive applications like games or remote controls.
Joystick to Arduino Connection:
5 Pins to Connect:
VRX → Arduino A0 (X-axis analog input, reads 0-1023)
VRY → Arduino A1 (Y-axis analog input, reads 0-1023)
SW → Arduino Pin 2 (Button, pressed = LOW, released = HIGH)
+5V → Arduino 5V (Power supply)
GND → Arduino GND (Ground)
How it Works:
VRX & VRY: Potentiometers inside the joystick change resistance as you move it, creating different voltage levels (0-5V) that Arduino reads as values 0-1023
SW: Internal button that connects to ground when pressed
Center position: Usually around 512 for both X and Y
Movement: Left/Right changes X value, Up/Down changes Y value
That's all you need! Just 5 wires and you're ready to read joystick movements!
CLICK BELOW LINK TO DOWNLOAD THE CODE