Years ago, I encountered a fairly long debate at AVRfreaks.net about whether or not it's OK to directly connect AVR pins that are configured as inputs with internal pullup enabled directly to ground through a button or switch.

From what I recall, the consensus at the time was that it's not (at least, for switches likely to be closed and conducting at reset), because at least some AVR MCUs weren't absolutely guaranteed to have their pins in high-impedance state at reset (at least, not if the chip reset while in brownout state, or something like that).

Thinking back, I'm not sure whether the warnings even applied to the chips I was introduced to at the time (ATtiny2313, ATtiny13, and ATmega162)... I just remember that the others on the site were pretty adamant that I was courting disaster, and I took their word for it.

Fast forward ~15 years.

The current datasheet for the ATmega2560 (at https://ww1.microchip.com/downloads/en/DeviceDoc/ATmega640-1280-1281-2560-2561-Datasheet-DS40002211A.pdf ) does seem to guarantee (on pages 7-9) that the pins used by ports A through L are tri-state high-impedance input pins at reset under all conditions, including when the clock is halted (obviously, any pin Arduino's bootloader subsequently makes use of could behave differently if I tried to hijack it for double-duty reading a button/switch... but the Mega2560 has so many pins, there really isn't any reason to reuse pins Arduino uses for its own purposes).

Offhand, I can think of three potential remaining concerns:

  • If I screw up and accidentally execute code that configures a pin connected directly to ground through a closed switch as a high output, the pin (and probably the whole chip) is likely to go up in smoke. I can deal with this risk.

  • If I were powering it with batteries, I might care about the constant power drain wasting battery life. I'm not, and I don't.

  • I'm not quite sure whether "OK to connect directly to ground through a momentary pushbutton" necessarily equates to "OK to connect directly to ground through a switch that might conceivably be closed and continuously conducting current for the life of the circuit.

So... have I missed anything? And is #3 a legitimate concern, or is it something that's not worth caring about if you're talking about something like 8 pins connected through a DIP switch?

Illustrative circuit:

Ground <-- [switch] --> IO pin (configured for input, internal pullup enabled)

  • 2
    The internal pullup is like 50k. Not much of a current there to be concerned about
    – chrisl
    Commented Dec 5, 2021 at 1:04
  • 1
    I think your analysis is correct. Commented Dec 5, 2021 at 13:27

2 Answers 2


If I screw up and accidentally execute code that configures a pin connected directly to ground through a closed switch as a high output, the pin (and probably the whole chip) is likely to go up in smoke. I can deal with this risk.

In addition to “there is an obvious bug”, there could also be a bug that is only triggered in very rare conditions, or a “cosmic ray” event which causes the processor to mis-execute instructions.

Or, maybe a metal tool or piece of debris fell across two of the processor pins and the other pin is an output that's currently high. (This is impossible to protect against in all cases, of course.)

In any of these cases, the hazard is that you're turning a situation where the device misbehaves temporarily into a situation where the device is permanently damaged.

Will this happen? Likely not. Is it worth protecting against? Depends on your application, on hard-to-quantify risk probabilities, and how much of a bother it would be to replace the processor.

  • The main problem is, I'm stuck working with an Arduino Mega2560 protoshield board that only has a sea of isolated ringed pads. If it were breadboard-like, with 2 or more adjacent pads connected (so I could just solder the DIP switch along the boundary between two sets of pads, then solder the resistors into the next pads over), I wouldn't have even bothered to contemplate the need for the resistors. But in this case, soldering even AWG30 WIRES to the DIP switch contacts was a major pain, and resistors would have had me in tears.
    – Bitbang3r
    Commented Dec 9, 2021 at 23:46

It is usually better to use a resistor when connecting to either +5V or ground. This protects the uP against software bugs, particularly during a hectic debug effort. Even moving on to the next project while forgetting the existing wiring can be a source of trouble.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.