Wiring a button: pull-down bad vs INPUT_PULLUP best

The Arduino button tutorial at:


... suggests wiring the button as a pull-down, which could short the power to ground through the input pin if someone happened to run code with a pinMode(2,OUTPUT)

I've seen this diagram several times, but I've lost track of the source:

Can anyone point me to the source?

The perpetrator might be me :face_with_peeking_eye: .

3 Likes

This link does an image lookup.

1 Like
1 Like

No, the resistor prevents a short to ground but you an get a short to 5V, which is just as bad. With a pull-up resistor, you can get a short to ground. The moral is - Don't mix-up inputs & outputs!

The advantage to pull-ups is that there is a built-in pull-up that you can enable.

1 Like

Excellent.

That Share tips you have come across - #999 by LarryD post has the exact schematic image I was looking for.

I built one in a Wokwi at:

1 Like

The external resistor does not prevent shorting 5V to ground directly thorugh a digital LOW pin, bypassing the resistor.

I agree it is indeed bad if you mix up the inputs and outputs, but if the only source of 5V is the pinMode(pin,OUTPUT) and you short that to ground when you press the button, it might be somewhat less damaging that trying to sink the full power supply into the LOW output pin.

For a deployment, @LarryD's 5V on a long wire failure mode seems much more likely than my malicious code failure mode.

This article: 10 Ways to Destroy an Arduino — Rugged CircuitsRugged Industrial Arduino Microcontrollers has a good set of possible failure modes & solutions. Their trick is using a 30mA PTC on each output to limit current in out out of each pin.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.