Thumb stick
Two axes and a push switch. Drag the cap to move it.
- 5 pins
- In 15 projects
- In 3 lessons
The Thumb stick in brief
What it is, and where it sits on the bench.
The KY-023 joystick module is two 10k potentiometers and a push switch under one thumb cap. Each pot sits across the supply with its wiper on VRX or VRY, so the axes are voltages read with analogRead: A0 and A1 on an Arduino Uno, giving 0 to 1023, or two ADC1 pins on an ESP32, giving 0 to 4095. Power it from 3.3 volts on an ESP32, or a stick pushed to one end puts 5 volts on an ADC pin. SW shorts to ground when the stick is pressed down and has no pull-up of its own, so it needs INPUT_PULLUP; reading it as a plain input is the usual mistake. Mokxi models each axis as a real divider across whatever VCC and GND hold, with a source impedance of zero at the ends and 2.5k at center. Drag the cap to move it and it springs back to exactly 512 of 1023. Real sticks never return to the same count, so they need a dead band this model does not, and SW never bounces here.
- Family
- Inputs
- Pins
- 5
A circuit built around it, running and explained: the Joystick simulator.
5 pins
Named as the editor names them, so a wire lands where you expect it.
How to use the KY-023 joystick with an Arduino
VCC to 5 V, GND to GND, VRX to A0, VRY to A1 and SW to a digital pin with INPUT_PULLUP, pin 12 here. analogRead() on each axis gives 0 to 1023, with the stick at rest near the middle. The bar graph example maps the X reading onto eight LEDs, and pressing the stick swaps it to the Y axis.
The mokxi_joystick.h driver wraps the three reads: x() and y() give the raw axes, dx() and dy() measure from where the stick rested at begin() with a dead zone, and clicked() reports a press once. The rest point is read rather than assumed because a real stick never springs back to exactly 512, so a sketch that steers from dx() and dy() does not creep.
On an ESP32-C3, power the stick from 3.3 V and read the axes on ADC1 pins, 0 to 4095; the ESP32-C3 thumb stick example uses GPIO 0 and 1 with SW on GPIO 3.
#include "mokxi_joystick.h"
Joystick stick(A0, A1, 12);
void setup() {
stick.begin();
}
void loop() {
int raw = stick.x(); // 0..1023
if (stick.clicked()) {
// the stick was pressed
}
}What is true about the Thumb stick, here
In its help article’s own words: what the simulation gets right, and where it stops.
Modeled
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 to 1023 and 0 to 4095.
Not modeled
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.
From Thumb stick (joystick), in full.
See the Thumb stick in a project
15 built-in projects use it. Each opens in the editor, already wired.
Where it turns up in a lesson
3 lessons place it in their own circuits.
The boards it is shown on
Each of these 3 boards has a built-in project with the Thumb stick in it.
The Thumb stick on each board
The pins, the voltage and the code change from board to board. Each page has that board’s wiring and a circuit you can run.
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the Thumb stick
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.