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.
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:
| Button | Where | k | BTNS | at 3.3 V |
|---|---|---|---|---|
| U11 | red, left | 0 | all of 3V3 | 3.30 V |
| U10 | red, right | 1 | a half | 1.65 V |
| U5 | diamond, bottom | 2 | a third | 1.10 V |
| U7 | diamond, left | 3 | a quarter | 0.83 V |
| U8 | diamond, top | 4 | a fifth | 0.66 V |
| U6 | diamond, right | 5 | a sixth | 0.55 V |
| none | 0 | 0 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
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.
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.
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.
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
Questions about this product
See what other owners have asked, and read their solutions.
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.