Dual-Axis XY Analog Joystick & Center-Deadzone Gimbal
Read proportional 2D thumbstick coordinates (VRx/VRy) plus integrated push switch to steer servos, games, and rovers.
Master proportional human-robot teleoperation with the KY-023 dual-axis analog joystick module. Sample two orthogonal 10kΩ potentiometers on A0 and A1, apply center deadzone filtering around (512, 512), normalize output to -100%..+100%, and detect shaft clicks on D2.
Key Learning Objectives & Robotics Concepts
By building and programming this project, you will master the following core engineering skills:
Power Architecture & Voltage Staging
5V / 3.3V Regulated PowerPowered directly from Arduino Uno 5V and GND (<1.5mA across the two 10kΩ potentiometers). Centering springs hold VRx and VRy near 2.5V (~512 ADC) when released. Two 10kΩ potentiometers draw only 1mA total from 5V; always enable INPUT_PULLUP on SW (D2) since module switch pulls to GND.
Bill of Materials (BOM) & Hardware Components
| Component | Specifications & Alternative | Qty | Approx Cost |
|---|---|---|---|
| Arduino Uno R3 | ATmega328P @ 16MHz | 1 | $8.00 |
| KY-023 Dual-Axis Analog Joystick | 2× 10kΩ gimbal pots + tactile center button | 1 | $1.80 |
| 5× Male-to-Female Jumper Wires | VCC, GND, VRx, VRy, SW leads | 5 | $0.50 |
Electrical & System Architecture
Connect Joystick +5V to 5V, GND to GND, VRx to A0, VRy to A1, and SW (push button) to D2 (configured as INPUT_PULLUP).
Autonomous Behavior & Finite State Machine (FSM)
Deterministic Arduino loop handling KY-023 Dual-Axis XY Thumbstick Module acquisition, filtering, and real-time output updates.
Step-by-Step Physical Assembly & Wiring Tutorial
Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.
Inspect KY-023 5-Pin Header & Gimbal Cap
Snap the black thumb cap onto the joystick post and inspect the 5 labeled pins.
- Verify header labels: GND, +5V, VRx, VRy, SW.
- Press straight down on the thumb cap to hear the tactile click of the SW button.
- Release the stick before powering on so auto-centering captures true neutral.
Wire VRx→A0, VRy→A1 & SW→D2
Connect all five joystick leads directly to the Arduino Uno.
- Wire +5V → Arduino 5V and GND → Arduino GND.
- Wire VRx → A0, VRy → A1, and SW → D2.
- Verify SW pin is configured as INPUT_PULLUP in software.
Verify Full-Deflection Endpoints
Run the raw diagnostic to check X/Y extremes (0 to 1023) and click response.
- Upload the diagnostic snippet and open Serial Monitor.
- Push stick full Left/Right and Up/Down to confirm clean 0↔1023 swings.
- Press straight down on the stick and verify SW drops to 0.
Upload Normalized Deadzone Vector Firmware
Flash the calibrated teleoperation controller producing clean -100..+100 axes.
- Upload the production sketch below without touching the stick during boot.
- Confirm resting output reads cleanly: X=0%, Y=0% (CENTER).
- Move stick in circles and watch smooth percentage vectors and 8-way directions stream live.
Test Diagonal & Click Combinations
Confirm diagonal moves report combined X/Y percentages and center click registers reliably.
- Hold stick at North-East diagonal and observe both X and Y positive.
- Click the shaft button while centered and while tilted.
- Release stick and verify instant return to exact 0%.
Subsystem Benchtop Verification Scripts
Test each hardware subsystem independently before deploying the full autonomous firmware.
1Bench Diagnostic: KY-023 Dual-Axis XY Thumbstick Module Hardware Check
Subsystem DiagnosticMinimal standalone sketch to verify pin wiring and signal response for KY-023 Dual-Axis XY Thumbstick Module before running the full project firmware.
// Diagnostic: Raw Dual-Axis Joystick Monitor
void setup() { pinMode(2, INPUT_PULLUP); Serial.begin(115200); }
void loop() {
Serial.print("X:"); Serial.print(analogRead(A0));
Serial.print(" Y:"); Serial.print(analogRead(A1));
Serial.print(" SW:"); Serial.println(digitalRead(2) == LOW ? "CLICK" : "UP");
delay(150);
}Complete Production Firmware
Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.
/**
* Project 26: KY-023 Dual-Axis Analog Joystick with Deadzone Normalization
* Board: Arduino Uno R3 | Pins: A0 (VRx), A1 (VRy), D2 (SW)
*/
const uint8_t PIN_VRX = A0;
const uint8_t PIN_VRY = A1;
const uint8_t PIN_SW = 2;
const int DEADZONE_ADC = 35;
int centerX = 512, centerY = 512;
int normalizeAxis(int raw, int center) {
int diff = raw - center;
if (abs(diff) <= DEADZONE_ADC) return 0;
if (diff > 0) return constrain(map(diff, DEADZONE_ADC, 1023 - center, 1, 100), 0, 100);
return constrain(map(diff, -DEADZONE_ADC, -center, -1, -100), -100, 0);
}
void setup() {
Serial.begin(115200);
pinMode(PIN_SW, INPUT_PULLUP);
delay(150);
centerX = analogRead(PIN_VRX);
centerY = analogRead(PIN_VRY);
Serial.print(F("Joystick Calibrated Center=("));
Serial.print(centerX); Serial.print(','); Serial.print(centerY); Serial.println(')');
}
void loop() {
int xPct = normalizeAxis(analogRead(PIN_VRX), centerX);
int yPct = -normalizeAxis(analogRead(PIN_VRY), centerY); // Up = Positive
bool pressed = (digitalRead(PIN_SW) == LOW);
Serial.print(F("X: ")); Serial.print(xPct);
Serial.print(F("% | Y: ")); Serial.print(yPct);
Serial.print(F("% | Btn: ")); Serial.print(pressed ? F("PRESSED") : F("UP"));
Serial.print(F(" | Dir: "));
if (xPct == 0 && yPct == 0) Serial.println(F("CENTER"));
else if (abs(yPct) >= abs(xPct)) Serial.println(yPct > 0 ? F("UP") : F("DOWN"));
else Serial.println(xPct > 0 ? F("RIGHT") : F("LEFT"));
delay(120);
}Firmware Architecture Explanation:
- Auto-captures mechanical spring rest points (centerX, centerY) during setup().
- Applies a ±35 ADC deadzone and smoothly rescales remaining travel into -100..+100%.
- Inverts Y so pushing "up" yields intuitive positive values for games and servos.
Operational Verification & Pin State Matrix
Input Signal vs. System Output Truth Table:
| Input / State | Pin / Signal | Detected Condition | Expected Output |
|---|---|---|---|
| Stick Centered | A0≈512, A1≈512 | Within Deadzone | X=0%, Y=0% (CENTER) |
| Full Right | A0≈1023 | Max X Deflection | X=+100% (RIGHT) |
| Shaft Clicked | D2 = LOW | Button Active | Btn: PRESSED |
Engineering Troubleshooting Matrix
| Problem | Likely Cause | Diagnostic Check | Engineering Solution |
|---|---|---|---|
| Resting X or Y drifts at ±4% even untouched | Loose gimbal spring exceeding 35 ADC deadzone | Observe raw center wobble | Increase DEADZONE_ADC from 35 to 50. |
| SW always reads PRESSED or floats randomly | Missing INPUT_PULLUP on D2 | Verify pinMode(PIN_SW, INPUT_PULLUP) | Enable internal pull-up resistor on D2. |
| Up/Down feels inverted | Module held rotated 180° relative to code sign | Push up and check Y sign | Remove the minus sign before normalizeAxis on Y. |
Engineering Challenges & Upgrades
Take your build to the next level with these progressive engineering upgrades:
Map X and Y directly to two SG90 servos (Project 8) for a miniature camera gimbal.
Light North, South, East, West LEDs with PWM brightness proportional to stick tilt.
Render a live moving crosshair cursor on Project 4 SSD1306 OLED.