Q about resistor ladder + analog pin

greets

I found a few schematics showing how to connect multiple buttons to an analog pin by using a resistor ladder, however one of the schematics is a bit confusing:

Isn't this circuit going to waste energy since the Vcc is connected to the ground (even if goes through a few resistors)?

the following layout makes much more sense to me:

Here R4 is a pull-down resistor and energy is only used while a button is pressed.

the next one is using the pull-up resistor on A5:

I'm thinking of using this last one (with 200 Ohm resistors instead of the 2K) , however I'm not sure if shorting an analog pin to ground is ok (when the right button is pressed)...?

1M will not waste much energy - with 5V at the analog pin,
5/1,000,000 = 5microamps.

last one, you have 30K to 60K internal pullup - in series with 200 to 1K external resistor will not make much voltage level difference.
Vout = 5V200/(200+20,000) = 0.049V
Vout = 5V
1,000/(1000+20,000) = 0.238V

Even smaller if the internal pullup is 50,000

"RRST Reset Pull-up Resistor 30 60 kohm"

Shorting a pin to Gnd is normal - using the internal pullup with switch to Gnd is normal operation.

CrossRoads:
1M will not waste much energy - with 5V at the analog pin,
5/1,000,000 = 5microamps.

You mean 5 microamps will be wasted from the A0 pin through the 1Mohm resistor to ground?

What about Vcc going through R1,R2,3,4,5 to ground? 5V / 5000 Ohm = 0.001 Amps i.e. 1 miliamp.


Here’s the way I wanted to do it:

That'd be fine too.
With the internal pullup Disconnected/Not enabled:
No switches closed: A5 = 0V.
S1 closed: A5 = 5V10000/(1x180+10000)
S2 closed: A5 = 5V
10000/(2x180+10000)
S3 closed: A5 = 5V10000/(3x180+10000)
S4 closed: A5 = 5V
10000/(4x180+10000)
S5 closed: A5 = 5V10000/(5x180+10000)
S6 closed: A5 = 5V
10000/(6x180+10000)

Closing multiple switches results in value of lowest switch being read.

What about this (no current when not pressed) :slight_smile:
As a bonus you may press several buttons at once in order to get various combinations… :wink:

CrossRoads:
That’d be fine too.
With the internal pullup Disconnected/Not enabled:

yep, I forgot to mention that it will be done with pull-down resistors.

S1 closed: A5 = 5V*10000/(1x180+10000)

Could you break down this formula?

btw. Does the arduino have some internal loads on analog pins and it measures the voltage drop across the specific load, i.e. what the anlaogRead does?

That’s a better way to get more combinations:
1, 1-2, 1-3, 1-4, 1-5, 1-6
2, 2-3, 2-4, 2-5, 2-6
3, 3-4, 3-5, 3-6
4, 4-5, 4-6
5, 5-6
6
1-2-3, 1-2-4, 1-2-5, 1-2-6
1-3-4, 1-3-5, 1-3-6
1-4-5, 1-4-6,
1-5-6,
1-2-3-4, 1-2-3-5, 1-2-3-6
1-3-4-5, 1-3-4-6
1-4-5-6
1-2-3-4-5, 1-2-3-4-6, 1-3-4-5-6
1-2-3-4-5-6
Then start with 2:
2-3, 2-4, 2-5, 2-6
2-3-4, 2-3-5, 2-3-6
2-4-5, 2-4-6, 2-5-6
2-3-4-5, 2-3-4-6
2-4-5-6
etc. I think the total combinations is 6! (6 factorial: 12345*6). Maybe there’s a /6 in there too. Been a while since I did that kind of math.

Vout = Vin*(equivalent resistance from switches closed in parallel)/(R15 + (equivalent resistance from switches closed in parallel) )
Vin = 3.3V or 5V,
This is where excel comes in handy, here’s the start of the calculations, sorted by equivalent resistance. As expected, more resistors in parallel = lower resistance.
analogRead is only going to return 0 to 1023, so some combinations may not come back as unique, depending on resistor tolerances & other assembly factors.

What do mean, break down the formula?
Vout = Vin * R2/(R1+R2). R2 is the resistor connected to Gnd, R1 is the resistor from Vin to Vout.

Analog input pins present very little (next to none) load to a source, that's why unconnected sources will read back as a voltage that varies with just a hand waving in their vicinity.