Two pots in one stick
Under the cap are two potentiometers, one per axis. Each track runs from VCC to GND and the stick turns its wiper, so X and Y are voltages: near half of VCC when let go, towards one end or the other as it tilts. Near half, not exactly half, and which way is which is for the first sketch to find out.
A divider you tilt
A potentiometer is a strip of resistive material with a contact, the wiper, that slides along it. Put one end of the strip on VCC and the other on GND, and the wiper sits at whatever share of VCC its position is: a quarter of the way up, a quarter of VCC. That is a voltage divider you can move.
The stick holds two of them, a quarter of a turn apart, each driven by a yoke under the stick. Tilt along one axis and one wiper turns; tilt along the other and the other does; tilt towards a corner and both move.
Turn each pot with its slider and watch its wiper climb the track. Both
tracks share the board's VCC and GND, and each wiper goes straight to the
header, X to X and Y to Y, so the reading is the wiper's share of VCC and
nothing more. With VCC on your board's own logic voltage, the stick's travel
covers the whole of analogRead's scale.
Near the middle, not on it
Let go, a spring brings the stick back upright and each wiper stops near the middle of its track. Near: this stick rests a percent or two off half, the next one somewhere else, and X and Y differ. The figure's resting points are made up to show that, not measured.
So never assume the middle is 512 on an Uno or 2048 on an ESP32. Read the stick let go at start-up and call that the centre; a centre and a dead zone does it.
Which pot is which way
The two pots are wired identically, so the names X and Y are only which header pin each wiper reaches. Where they sit says more. The X pot is on the left side of the stick with its shaft pointing in at the middle, so it turns with the tilt along that side: towards and away from the header. The Y pot, along the bottom, turns with left and right. That is worked out from the supplier's drawing, not tried on a board, and which way each one rises is not on the drawing at all. The first read settles both in ten seconds.
What the drawing says
The drawing gives at least 60° of travel from one end to the other and marks both pots 103, the usual code for 10 kΩ; a photo of the part reads B103, and B usually means a linear track. None of that is a datasheet, so treat it as likely rather than promised. If they are 10 kΩ, the two tracks together draw about 0.7 mA from 3.3 V and 1 mA from 5 V, all the time.
The Slim Joystick has a smaller stick built the same way, with six buttons beside it. X, Y and the click go to the same pins of your board in both books, so a project can swap one block for the other without moving those three wires.
When it does not work
It never will. Each wiper comes to rest near the middle of its track, not on it, and X and Y rest in different places. That is why the sketches measure the centre at start-up instead of assuming 512 or 2048.
That is what the drawing suggests: the X potentiometer sits on the left side of the stick, and a pot on the side turns with the tilt towards and away from the header. The names are the pots', not directions. Swap them in your sketch if you want X to be left and right.
Which way each axis rises depends on how the stick sits on the board and how you hold the board. Nothing is wrong. Print both axes, push the stick each way, and flip the sign in your sketch where it disagrees with you.
At the ends the wiper reaches 0 V or 3.3 V, and an ESP32's ADC reads nothing below about 0.1 V and tops out near 3.1 V at the Arduino core's default setting. The last sliver of travel is clipped. A sketch that maps to per cent treats anything near the end as full.
Why VCC has to be your board's own logic voltage, and what each wrong choice costs.
VCC sets the top →Edit this page — content/books/dual-axis-joystick/two-pots-in-one-stick.mdx
Questions about this product
See what other owners have asked, and read their solutions.
Dual Axis Joystick
Loading discussions…
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.