Electronic – arduino – Why exactly 470 or 1k Ω? (to prevent damage of output pin)

arduinoresistorsshort-circuit

Quote from the Arduino tutorial, section Digital Pins:

Short circuits on Arduino pins, or attempting to run high current
devices from them, can damage or destroy the output transistors in the
pin, or damage the entire Atmega chip. Often this will result in a
"dead" pin in the microcontroller but the remaining chip will still
function adequately. For this reason it is a good idea to connect
OUTPUT pins to other devices with 470Ω or 1k resistors, unless maximum
current draw from the pins is required for a particular application.

These numbers are voodoo to me: Why "470" or "1k"? Why isn't there
exactly one number given, such as "at least 470Ω if there otherwise
would be a short circuit"?

I am interested because I consider using the Arduino as a keyboard
controller
, and – in this use case – lines are basically short circuited if a
button is pressed. Of course, the lines do have some resistance, but I
didn't get the chance to measure it yet.

Best Answer

First a little bit about short-circuits: Short circuit is a circuit which doesn't have any intentional current-limiting elements in the path of the current. The result of that is that circuit elements which we normally take to have zero resistance start acting as resistors and the usual mathematical model for power supplies breaks often resulting in lower than expected voltage and destructive overheating.

Because of the maximum current specifications of the microcontroller, you need a resistive element in the path of the current going from a pin. You can expect the pin to die by outputting 40 mA from it and if I remember correctly 200 mA from all pins at same moment. Nominal voltage for this system is 5 V, so let's see what happens if we calculate the current with 470 \$\Omega\$: \$\frac{5 V}{470 \Omega} \approx 10 mA\$. This happens to be nice and sane value for the current which will not damage the microcontroller. If you instead use 1 \$k \Omega\$ resistor, you'll get 5 mA, which is even safer and consumer even less power. Also those two values of resistors are relatively popular and at the same time provide small currents but not so small that you need to take capacitance of the traces into account when working with them.

In case of actually shorting lines, you should fully expect the lines themselves to have negligible resistance! This would result in directly shorting the pins, which as written in the quote, would result in dead pins. Also shorted lines often result in broken push-buttons, since large current has negative effects on push-button contact lifetime due to overheating and sparking. Instead of using short-circuits for connecting lines, the better way is to place a resistor near the ground of the line. This will limit the current when the line is powered up. By placing the resistor near the ground connection of the line, we ensure that the greatest voltage drop on the line is at its end, so if we short it with another sensing line using a push-button, the sense line sees full voltage.

Also pins set as input are in the so-called "high impedance" mode, meaning that they behave as if they were a resistor with very large resistance connected to ground. If you are 100% sure that the pin will only be a sense pin, then you don't need to put another resistor in front of it. Even in that case, it's a good idea to put a resistor because you might accidentally set a pin as something other than input and potentially cause a short-circuit. If you do place the resistor, keep in mind that there will be very little current going through the sense line, meaning that the voltage drop on the resistor will be very low which will result in the pin seeing full voltage.

If you'd like some more "advanced reading" you could take a look at the datasheet for ATmega328, which is one of the microcontrollers used in some Arduinos. In section 29. Electrical characteristics, you'll see that under Absolute Maximum ratings, the current per I/O pin is 40 mA and for total device is 200 mA.

UPDATE: Please don't confuse Absolute Maximum Ratings with operational ratings! HEre's notice from datasheet for ATmega32U4:

NOTICE: Stresses beyond those listed under “Absolute Maximum Ratings” may cause permanent dam- age to the device. This is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of this specification is not implied. Exposure to absolute maximum rating conditions for extended periods may affect device reliability.

Here are footnotes from page 379 of the same datasheet:

Although each I/O port can sink more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: ATmega16U4/ATmega32U4: 1.)The sum of all IOL, for ports A0-A7, G2, C4-C7 should not exceed 100 mA. 2.)The sum of all IOL, for ports C0-C3, G0-G1, D0-D7 should not exceed 100 mA. 3.)The sum of all IOL, for ports G3-G5, B0-B7, E0-E7 should not exceed 100 mA. 4.)The sum of all IOL, for ports F0-F7 should not exceed 100 mA. If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater than the listed test condition. 4. Although each I/O port can source more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: ATmega16U4/ATmega32U4: 1)The sum of all IOH, for ports A0-A7, G2, C4-C7 should not exceed 100 mA. 2)The sum of all IOH, for ports C0-C3, G0-G1, D0-D7 should not exceed 100 mA. 3)The sum of all IOH, for ports G3-G5, B0-B7, E0-E7 should not exceed 100 mA. 4)The sum of all IOH, for ports F0-F7 should not exceed 100 mA. 5. All DC Characteristics contained in this datasheet are based on simulation and characterization of other AVR microcon- trollers manufactured in the same process technology. These values are preliminary values representing design targets, and will be updated after characterization of actual silicon