slim joystick/The stick/03. Two pots in one stick
The stick · 03 of 11

Two pots in one stick

Under the cap are two potentiometers, one per axis. Each is a carbon track from 3V3 to GND with a wiper the stick drags along it, so X and Y are voltages: near half of 3V3 when let go, towards one end or the other as it tilts. Near half, not exactly half, and which way is up 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 3V3 and the other on GND, and the wiper sits at whatever share of 3V3 its position is: a quarter of the way up, a quarter of 3.3 V. That is a voltage divider you can move.

The stick holds two of them, turned a quarter of a turn apart. Tilt it along one axis and the X wiper slides; along the other and Y does; tilt it towards a corner and both move. The supplier's drawing calls it a carbon-film joystick: the tracks are carbon.

Two pots in one stick
Your board
Tilt along X0 %
Tilt along Y0 %
X reads
327
Y reads
346
Top on Uno
675 of 1023
Let go, each wiper rests near half of 3V3, about 1.60 V and 1.69 V here. Near half, not on it, and not the same for both: every stick rests a little differently. On an Uno that reads about 327 and 346.

Both tracks share the board's 3V3 and GND, and each wiper goes straight to the header, X to X and Y to Y. Nothing else is in the way, so the reading is the wiper's share of 3V3 and nothing more.

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 few tens of millivolts 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.

That settles how a sketch should treat it. 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 way is up

The drawing gives the tilt, about 16° each way, and says nothing about which direction raises the voltage. That depends on how the stick is turned on the board and on how you hold the board. Rather than trust a diagram, the first read prints both axes: push the stick towards the header and watch which number moves, and which way.

What an Uno sees

With the header's 3V3 on 3V3, the wipers can only swing between 0 and 3.3 V. An ESP32, an ESP32-S3 and a Pico measure against about 3.3 V, so the stick uses their whole scale. An Uno measures against 5 V, so the same swing is 0 to about 675 of 1023, with the centre near 338. That is still hundreds of steps from one end to the other, far finer than a thumb.

When it does not work

Let go, it does not read exactly half.

It never will. Each wiper comes to rest near the middle of its track, but 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.

My Uno never reads above about 675.

That is correct with 3V3 on the header. An Uno's analogRead measures against 5 V, and the stick can only swing between 0 and 3.3 V, which is 0 to about 675 of 1023. Plenty of steps for a thumb; the handbook's sketches work in millivolts, so the number means the same on every board.

Pushing forward makes the number go down.

Which way each axis rises depends on how the stick sits on the board and how you hold it. Nothing is wrong. Print both axes, push the stick each way, and flip the sign in your sketch where it disagrees with you.

The very end of the travel reads the same on my ESP32.

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.

Where this goes next

The click, the resistor that holds it LOW, and why the pin is INPUT.

The key under the stick

Edit this page — content/books/slim-joystick/two-pots-in-one-stick.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Slim 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.

Browse Modules and blocks on the forum