Offline
Newbie
Karma: 0
Posts: 47
|
 |
« on: December 09, 2011, 11:49:01 am » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Austin, TX
Offline
Faraday Member
Karma: 41
Posts: 5174
CMiYC
|
 |
« Reply #1 on: December 09, 2011, 12:24:22 pm » |
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.)
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 47
|
 |
« Reply #2 on: December 09, 2011, 01:05:14 pm » |
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!
|
|
|
|
|
Logged
|
|
|
|
|
Austin, TX
Offline
Faraday Member
Karma: 41
Posts: 5174
CMiYC
|
 |
« Reply #3 on: December 09, 2011, 01:16:58 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 249
Posts: 16550
Available for Design & Build services
|
 |
« Reply #4 on: December 09, 2011, 04:33:14 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 47
|
 |
« Reply #5 on: December 09, 2011, 05:01:09 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 249
Posts: 16550
Available for Design & Build services
|
 |
« Reply #6 on: December 10, 2011, 12:49:33 am » |
No, just create the interrupt on a Low level instead of High.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 1
Posts: 22
|
 |
« Reply #7 on: January 19, 2013, 08:50:31 am » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 249
Posts: 16550
Available for Design & Build services
|
 |
« Reply #8 on: January 19, 2013, 12:35:46 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
DELHI
Offline
Full Member
Karma: 0
Posts: 135
|
 |
« Reply #9 on: March 14, 2013, 07:39:08 am » |
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.)
|
|
|
|
|
Logged
|
AMPS
|
|
|
|
Cumming, Ga
Offline
Edison Member
Karma: 12
Posts: 1389
Ultimate DIY: Arduino
|
 |
« Reply #10 on: March 14, 2013, 01:03:57 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15314
Measurement changes behavior
|
 |
« Reply #11 on: March 14, 2013, 01:08:19 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Johannesburg UTC+2
Offline
Edison Member
Karma: 34
Posts: 1705
|
 |
« Reply #12 on: March 14, 2013, 01:14:43 pm » |
The drawing is flawed. No, it's not, since the point that you make pwillard: 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.
|
|
|
|
|
Logged
|
IT Crowd: Roy... "Have you tried turning it off and on again?" Moss.. "Have you tried forcing an unexpected reboot?"
|
|
|
|
DELHI
Offline
Full Member
Karma: 0
Posts: 135
|
 |
« Reply #13 on: March 15, 2013, 04:09:24 am » |
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..
|
|
|
|
|
Logged
|
AMPS
|
|
|
|
|