Go Down

Topic: Multiple pushbuttons and pulldown resistor (Read 2906 times) previous topic - next topic

SilentDirge

So I have three pushbuttons each with a +5v input, output to pin via resistor and a pulldown resistor to ground. They work great but I'm wondering if I wouldn't be able to just use 1 pulldown resistor to stop them from floating or if this would cause them to not function properly if they were pressed concurrently. If they were not meant to be pressed concurrently, is this a safe thing to do?

If this is a stupid question and this is not logical thinking is there some proper way to do this? 3 pushdowns with a shared pulldown?

James C4S

In cases like this, it is helpful to look at a schematic of what you are trying to do.



Notice that pin2, pin3, and pin4 are all effectively on the same piece of wire?  So when one of the buttons is pushed, they will ALL see 5V.  No, you can't use a "shared" pull-down resistor.

However, why not use the internal pull-up resistors instead?  Then you don't need any external components.  The only trade off is that the logic is inverted (unpushed buttons are HIGH and pushed buttons are LOW.)
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

SilentDirge

Ah, I see what you're getting at. By using the internal pullup resistor I can sidestep the external resistors. Would this have any implications for battery life, though, since I would now have to supply a constant 5v except for when the button connection is broken (open) and electrons diverted?

It seems like almost every Atmel chip has support for internal pull-ups so it's also future proof should I decide to switch chips. Great solution, thanks!

James C4S


Would this have any implications for battery life, though, since I would now have to supply a constant 5v except for when the button connection is broken (open) and electrons diverted?


In order for power to be burned you must have both Voltage AND current.  Holding a pin up with 5V (nearly) eliminates current from flowing just the same as when tied to ground.  So while you are applying a constant 5V, so little current is flowing that the Power is practically Zero.  (In the P = I * E you don't use 5V.  You use 5V-induced voltage which is practically zero.)

Incidentally, when using a pull-down the same reasoning applies.  Keep in mind that if current starts to flow there is a voltage, even a small one.  So you burn the same amount of power using a pull-up as a pull-down.

Virtually no current flows until the button is pressed.  Once it is pressed, the current is the same whether it is a pull-up or pull-down.

If you are worried about power consumption it is a very good practice to enable the Pull-Up resistors on ALL unused I/O pins.  Otherwise, floating pins can draw over 1mA of current.  Which, on a device that only consumes 20mA is pretty significant.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

CrossRoads

With the internal pullup, the swithes aren't connected also. All they share is ground, so you can press 1 and 2,3 see nothing.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

SilentDirge

Quote
If you are worried about power consumption it is a very good practice to enable the Pull-Up resistors on ALL unused I/O pins.  Otherwise, floating pins can draw over 1mA of current.  Which, on a device that only consumes 20mA is pretty significant.


Interesting, I had no idea! Very good to know.

One last question for you then; right now I'm using those buttons to trigger an interrupt on the arduino on any difference in the interrupt pin they are all connected to (H->L or L->H). Other than changing the pin to be an input (to avoid a short) would I even need to change anything else to maintain the interrupt functionality?

CrossRoads

No, just create the interrupt on a Low level instead of High.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Cue2

Quote
If you are worried about power consumption it is a very good practice to enable the Pull-Up resistors on ALL unused I/O pins.  Otherwise, floating pins can draw over 1mA of current.  Which, on a device that only consumes 20mA is pretty significant.


I know this is an old thread but can somebody please elaborate on this. Does this mean all unused pins should be grounded to lower power consumption? If so, would this also mean one has to be extremely careful not to set a pin as output inadvertently, otherwise you run the risk of an overcurrent on that pin?

CrossRoads

Better option is to set unused pins to input with internal pullup resistor enabled.
This stops any floating or oscillating, and pins can be pulled high/low by outside forces and not hurt anything.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

AMPS-N


Is there  any other technique of doing this.If we are doing this way the resistor might degrade on variation in temperature. If we using analog read pin to read data .The value may not same at  start and in actual field.
let me know other technique




In cases like this, it is helpful to look at a schematic of what you are trying to do.



Notice that pin2, pin3, and pin4 are all effectively on the same piece of wire?  So when one of the buttons is pushed, they will ALL see 5V.  No, you can't use a "shared" pull-down resistor.

However, why not use the internal pull-up resistors instead?  Then you don't need any external components.  The only trade off is that the logic is inverted (unpushed buttons are HIGH and pushed buttons are LOW.)

AMPS

pwillard

No this is about Digital I/O.  We are not measuring a voltage so the ACTUAL value of the resistor is not critical.  The pin is looking for a logic change from 0 to 1 on a keypress.

The drawing is flawed.  Any keypress will be the same as ALL keys being pressed since the inputs... by means of sharing a resistor... are also all shorted together.

It's time we all started loving resistors for the very useful job they do for us.

retrolefty

Quote
It's time we all started loving resistors for the very useful job they do for us.


And time to also love not needing to use any external resistors at all to read switch contacts as the AVR chip gives us optional internal pull-ups to use so there is no reason to not just utilize negative logic and use the internal resistors.

Lefty

JimboZA

Quote
The drawing is flawed.


No, it's not, since the point that you make pwillard:

Quote
Any keypress will be the same as ALL keys being pressed since the inputs


is exactly the point that James was making when he posted that sketch.
Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please

AMPS-N

i understood above concept like this.


if any of 3 switch has been triggered particular digital pin goes high
Assume i have connected to analog pin. Due to variation of resistor it start reading analog values.depend on analog read signal i can able to judge which mode i need to go..
AMPS

Go Up