attiny wired to pot input, but what if i use "pinMode(ButtonPin, INPUT_PULLUP)"

i was testing attiny85 without issue, i used pb4 for a button input and use it as "INPUT_PULLUP" that's ok. then i used pb3 connected to 10k pot and use with PotValue=analogRead(PotPin); that's ok to!

now my intention is put that button in parallel with that pot, both connected to same input and use analogRead(PotPin) for both: use the button to control a menu and then use pot to set a value. (there no many input in attiny)

my question:

  • although complicated i think it can work, what do you think?
  • but what will happened if after all wired... i use the "pinMode(ButtonPin, INPUT_PULLUP); ". could i risk to burn that input???

best regards, pescadito

The danger is that if you have to the pot turned all the way in one direction such that you have a 0 Ohm resistance between the +5v line and the input, if you push the button you would short the power supply.

What you can do is use only two pins of the potentiometer - the wiper to the pin, and one of the other terminals to ground. Then have a 10k resistor from the pin to VCC. That way you won't short the supply and you don't need to use INPUT_PULLUP.
However, if you have the pot turned all the way in this situation, the pin will be connected directly to ground - meaning that you would never be able to register the button press as it would be indistinguishable from the pot.

This leads to a third circuit which would allow you to use both. I have attached a schematic.
Basically, if you do analogRead() you will get a number between 636 and 988 depending on where you turn the pot. If the button is pressed, analogRead() will return 0.
If you do digitalRead() when the button is pressed you will get LOW. If you do digitalRead() when the button is not pressed, you will get HIGH - because the potentiometer will never take the voltage at the pin below 3V which is the threshold for a logic 1.


Something I've used before is a state machine, where you store the current state (in your case menu location) in the onboard EEPROM and use the reset on the ATTiny85 as your switch pin. In this case the each time the ATTiny restarts it will need to know where it was in the menu earlier, so it can act on the reset as a button press. Just have your pot on the other input therefore as before.

I published a trivial example in this post where the reset was used as the sole control for a bathroom shower timer. Hopefully that example will illustrate what I mean, and this helps.

Cheers ! Geoff

thank tom and strykeroz for your usefull tips!!!