five-direction joystick/The board/01. One wire, five directions
The board · 01 of 10

One wire, five directions

Four tilts and a press, and one wire to your board. The TK94's switch joins SIGNAL to a different point of a chain of resistors for each push, so every push is its own voltage and one analog pin tells all five apart. It is not five digital switches, whatever the page before this one said.

Five pushes, five voltages

Five pushes, one wire
Push
Your board
SIGNAL
2.22 V
Of VCC
44.4 %
analogRead on Uno
455
Down joins SIGNAL to a point part-way down a chain of resistors: 2.22 V, 455 counts on the Uno. Every push has its own level, so one analog pin tells all five apart.

The cap sits on a five-way navigation switch: tilt it up, down, left or right, or press it straight down. Each of the five closes its own contact, and every contact runs from the same pin, SIGNAL, to a different point of a chain of five 10 kΩ resistors between VCC and GND.

So each push gives SIGNAL its own voltage. With VCC at 3.3 V:

PushSIGNALOf VCC
Nothing0 V0
Up0.37 Va ninth
Press0.60 Vtwo elevenths
Left0.90 Vthree elevenths
Down1.47 Vfour ninths
Right3.30 Vall of it

One analog pin reads which: one pin of your board does the work of five digital ones.

Held the way its words read

The names in this book are for the block held with its header on the left. That is the way "lonely binary" and "ANALOG" on its front read across, and the way the maker's own sketch named the pushes. Mounted another way, the voltages stay with the contacts and the names turn with the block.

What the page before this said

The page this handbook replaces called the TK94 "five separate momentary switches", read with "a plain digitalRead" on "five digital lines", with pull-ups fitted. There is one output, no pull-up, and a digital read sees right as HIGH and the other four as LOW. Further down it said the reading rests near 512; it rests at 0.

The trade is the one the old page described for the wrong board. There is no centre to calibrate and no dead zone, because the steps are the switch's own, but there is no in-between either: a push is on or off. For a stick that reports how far it is tilted, see the TK23 or the TK21.

When it does not work

digitalRead gives HIGH for right and LOW for everything else.

That is what a digital pin makes of it. Up, the press, left and down are all under a volt or two, which a digital input calls LOW; only right, which is all of VCC, reads HIGH. SIGNAL goes to an analog pin and is read with analogRead.

It reads 0 with nothing pressed. Is the joystick broken?

No, 0 is the resting reading. A thumb stick rests in the middle of its range, but this block does not: with nothing pressed, a 10 kΩ resistor holds SIGNAL at GND. Push any way and the number jumps to that push's level.

Which way is up?

Hold the block with the header on the left, so the words on its front read across. That way up is a ninth of VCC and right is all of it, which is also how the maker's own sketch named them. Turn the block and every name turns with it.

Where this goes next

The switch, six resistors and a capacitor, and what each one does.

What is on it →

Edit this page — content/books/five-direction-joystick/one-wire-five-directions.mdx

Community

Questions about this product

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

Ask a question ↗

Five-Direction 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 →