Thumb stick (joystick)
The two-axis thumb stick module, KY-023 style: two potentiometers and a push switch under one cap.
Each axis is a real 10 k potentiometer with its wiper on VRX or VRY, so the axis
is a genuine voltage divider across whatever is on VCC and GND, so a module on a
3.3 V board reads 0 to 3.3 V with no special case anywhere. SW shorts to ground
when the stick is pressed straight down.
Pins
| Pin | What it does |
|---|---|
VCC |
Supply for both potentiometer tracks. |
GND |
The other end of both tracks. |
VRX |
The X-axis wiper. |
VRY |
The Y-axis wiper. |
SW |
Shorts to ground when pressed; open the rest of the time. |
Properties
None.
While it runs
Drag the black cap on the canvas and both axes move; let go and it springs back to the middle, the way the real module does. Click or hold the cap (or press the board) to push the stick straight down.
What the model gets right
The wiper's source impedance is the two halves of the track in parallel (zero at
the ends, 2.5 k at center for a 10 k pot), so an ADC input with a real load on it
sees the module's actual impedance, not an idealized voltage. Both the Uno's
ten-bit ADC and the ESP32-C3's twelve-bit ADC1 can read it, and mokxi_joystick.h
in the firmware library hides the difference between 0–1023 and 0–4095.
What it does not model
No mechanical detent or spring rate beyond the springback itself, and no wear on the tracks.
The center is exact and silent. A real KY-023 does not spring back to the same count twice. It lands somewhere near the middle with a few counts of slop, and its wiper adds noise on top, which is why every thumb-stick sketch has a dead band in it. Here the release is exactly 512 of 1023 on both axes, every time, with no noise and no drift, so a sketch that would need a dead band on the bench works without one. The two tracks are perfectly linear and perfectly matched, where real ones are neither.
The track is an ideal divider: no wiper contact resistance, no end resistance, no
scratchiness as it moves, and SW does not bounce even though the switch under a real
one is a tactile dome.
Common mistakes
Forgetting SW needs INPUT_PULLUP. The switch has no pull-up of its own on the
real module, exactly as modeled here, so a sketch that reads it as a plain input
sees Floating instead of a clean high.
See it in action
OLED pong, ESP32-C3 thumb stick and Joystick bar graph all use the stick as the input. Open them at /templates, and see the parts games are made of for the fuller story.