slim joystick/Six buttons on one wire/05. A ladder of resistors
Six buttons on one wire · 05 of 11

A ladder of resistors

Six buttons, one pin. R8 holds BTNS at 0 V, and five more 10 kΩ resistors run in a chain from BTNS with a button at each step. A button k steps up the chain lifts BTNS to 3V3 / (1 + k): all of it, a half, a third, a quarter, a fifth or a sixth. Each share is one button.

One pin, six voltages

Six buttons would normally take six digital pins. This board uses one analog pin instead, and gives every button its own voltage on it. The parts that do it are the six 10 kΩ resistors along the top edge.

A ladder of resistors
Press
BTNS
1.10 V
Share of 3V3
1/3
Current
110 µA
U5, the bottom of the diamond, joins the point 2 resistors up the chain to 3V3. Now 3 resistors of 10 kΩ stand between 3V3 and GND, and BTNS sits at R8's share: one part in 3, 1.10 V. Every button gives a different share, which is how one pin tells six apart.

R8 runs from BTNS to GND. It holds BTNS at 0 V when nothing is pressed.

From BTNS a chain runs through R9, R10, R11, R12 and R13, and each button joins one point of the chain to 3V3. U11 joins BTNS itself. U10 joins the point after R9, U5 the point after R10, and so on up to U6, after R13. Call the number of resistors between a button and BTNS its k: U11 is 0, U10 1, U5 2, U7 3, U8 4, U6 5.

One part in 1 + k

Press a button and current flows from 3V3, through the button, down k resistors of the chain and through R8 to GND. That is 1 + k equal resistors in a row, and BTNS sits above only one of them, R8. So BTNS gets one part in 1 + k of 3V3:

ButtonWherekBTNSat 3.3 V
U11red, left0all of 3V33.30 V
U10red, right1a half1.65 V
U5diamond, bottom2a third1.10 V
U7diamond, left3a quarter0.83 V
U8diamond, top4a fifth0.66 V
U6diamond, right5a sixth0.55 V
none00 V

The resistors past the pressed button carry nothing: their far end is open, so no current can flow through them, and they change nothing. The figure greys them out.

Why every resistor is the same

Because all six are 10 kΩ, the levels come out as simple fractions of the supply, whatever the supply is. That makes the arithmetic easy, and it keeps the levels as far apart as a chain like this allows at the top. At the bottom they crowd together: a fifth and a sixth are only 0.11 V apart. Telling them apart is how a sketch copes with that.

The current is small. Pressed, U11 puts 3.3 V across R8 alone, 0.33 mA; U6 puts it across all six, 55 µA. Nothing pressed, the ladder draws nothing.

When it does not work

BTNS reads 0 whatever I press.

Either BTNS is not on the pin the sketch reads, or 3V3 is missing: with no supply there is nothing for a button to lift BTNS towards. Press U11, the left red button. It joins BTNS straight to 3V3, so it should read the top of the range.

U11 reads full scale and the rest read nothing.

BTNS is on a digital pin, or the sketch uses digitalRead. U11 gives all of 3V3, which reads HIGH; U10 gives half, which may read either way; the others give less and read LOW. Move BTNS to an analog pin and use analogRead.

How much current do the buttons draw?

Only while one is pressed, and never more than 3.3 V across 10 kΩ, 0.33 mA, for U11. U6, at the far end of the chain, draws a sixth of that. Nothing pressed, the ladder draws nothing at all.

Where this goes next

The six levels on each board, and the lines a sketch draws between them.

Telling them apart

Edit this page — content/books/slim-joystick/a-ladder-of-resistors.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