12
\$\begingroup\$

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.

\$\endgroup\$
  • 2
    \$\begingroup\$ If you are using the pins to detect buttons I would think the pins would be configured as inputs, in which case shorting the pin to ground would be fine. \$\endgroup\$ – Gorloth Apr 24 '13 at 22:14
  • 5
    \$\begingroup\$ 470 and 1000 are common values that tinkerers are likely to have laying around. So this is like "Use around 500 to 1000 ohms!", but then normalized to common resistor values. \$\endgroup\$ – Kaz Apr 24 '13 at 23:42
18
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ This is great, thanks for writing in such detail for us. \$\endgroup\$ – Patrick Hughes Apr 25 '13 at 2:09
  • \$\begingroup\$ Thanks for the insight! In the title, I now corrected input pin to output pin. I plan to use a Leonardo, by the way, which is based on the ATmega32u4. Its 5 V I/O pins are specified for up to 40 mA. \$\endgroup\$ – feklee Apr 25 '13 at 11:19
  • \$\begingroup\$ @feklee Be very careful here! Those pins are specified to die at 40 mA! Take a look at the full datasheet and pay special attention to footnotes on page 379 and to the notice on page 378. \$\endgroup\$ – AndrejaKo Apr 25 '13 at 12:31
  • 1
    \$\begingroup\$ In fact those footnotes are so important that I'll quote them here in the answer. \$\endgroup\$ – AndrejaKo Apr 25 '13 at 12:32
13
\$\begingroup\$

The short answer is that Arduino is targeted towards hobbyists with little electrical engineering knowledge, and it's instructions are simplified enough to get the point across. Those two values are safe, and gives the user an option instead of a fixed demand.

Both are standard sized resistors. 470Ω and 1kΩ, when used with the Arduino 5V VCC voltage, provide a safe current draw (5v / 470Ω ~ 0.011A (11mA), 5/1000 = 0.005A (5mA)). And the current draw is useable for transistors or leds or similar parts.

Frankly, any value resistor that will give a current draw within the maximum of the microprocessor's pin current (40mA) will work. That means any resistor above 125Ω.

\$\endgroup\$
  • \$\begingroup\$ Thanks, also for explaining why these resistors are popular! \$\endgroup\$ – feklee Apr 25 '13 at 11:22
  • 1
    \$\begingroup\$ @feklee I can't see a full explanation of this, but you might be interested in it: en.wikipedia.org/wiki/E24_series#E_series \$\endgroup\$ – TNW Apr 25 '13 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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