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.
Does this mean that an OUTPUT pin should never be shorted directly to 0v or that an OUTPUT pin should never be shorted directly to 5v? I've seen both types of shorts in various tutorials, usually via a SPST switch.
int inPin = 7; // choose the input pin (for a pushbutton)
The switch is connected to an input, not output. An input is a very high resistance to ground (10's of meg Ohms at least) so virtually no current flows into or out of an input.
dotancohen:
Off the top of my head, the Pushbutton Tutorial shorts to ground while the button is depressed.
You have to be more detail oriented to read and write code, or you will confuse yourself like this.
That pin is set INPUT, not OUTPUT.
AVR pins can have 1 of 4 modes and can change mode in less than a microsecond.
OUTPUT LOW --- tries to be 0V, can safely sink 25mA continuously, maybe even 30mA but may need cooling. Never connect directly to 5V or OUTPUT HIGH pin.
OUTPUT HIGH --- tries to be 5V, can safely source 25mA continuously, maybe even 30mA but may need cooling. Never connect directly to GND or OUTPUT LOW pin.
INPUT LOW (or just INPUT, default is LOW) --- when not being read is effectively electrically neutral, does not source or sink current. Each digital read will sink about 1 microAmp of charge, almost nothing.
INPUT HIGH --- tries to be 5V through 20K to 50K Ohms resistance (very easy to drain LOW) always. Each digital read is the same as above. The internal resistance makes grounding the pin safe, mode is INPUT_PULLUP.
It is the OUTPUT pins that often need protection from too much current.
That is simply impossible on an Arduino that works correctly. "Shorting" an INPUT_PULLUP pin to ground is exactly what they were designed for. The resistance of these pull-ups is very high (> 30kΩ), so at the low voltages used by a microcontroller, only a very tiny current will flow.
The behavior you were seeing must have been caused by a different problem with your connections and/or code.
dotancohen:
Does this mean that an OUTPUT pin should never be shorted directly to 0v or that an OUTPUT pin should never be shorted directly to 5v? I've seen both types of shorts in various tutorials, usually via a SPST switch.
It's basically current that can damage the pin.
If the pin is set HIGH, and <120 ohm is connected between pin and ground, >40mA will flow (absolute max pin current).
A short is (almost) zero ohm...
Likewise if the pin is set LOW, and the load (short) is connected to 5volt.
In theory, no current will flow if an output pin is set LOW and connected to ground. Likewise for HIGH and 5volt.
Leo..
Wawa:
If the pin is set HIGH, and <120 ohm is connected between pin and ground, >40mA will flow (absolute max pin current).
I was poking around with a simple circuit, output pin to an Opto-Isolater input, other Opto pin to ground, and I forgot to include a current limiting resistor. Some hours later I saw what I'd done so I connected an AVO to measure the current, 78 mA.
This is on a cheap Uno clone and it doesn't seem to be damaged.
I added a resistor to be 'safe' but was I just lucky or can some boards handle higher current?
Peterd51:
I was poking around with a simple circuit, output pin to an Opto-Isolater input, other Opto pin to ground, and I forgot to include a current limiting resistor. Some hours later I saw what I'd done so I connected an AVO to measure the current, 78 mA.
OK, the "Absolute maximum rating" is not telling you what the output can provide if you abuse it, it is telling you what is not safe to abuse and if you do, may damage it in some - unspecified - manner and extent.
The effective internal resistance of an Arduino pin is something like 45 Ohms. In your case, 5 V / 78 mA is in fact, 64 Ohms which is quite correct - I said "something like 45 Ohms" and it is non-linear so it actually changes with the current drawn. More like 45 Ohms if you are drawing a sensible current.
Peterd51:
This is on a cheap UNO clone and it doesn't seem to be damaged.
Well, you don't know, do you? It may fail tomorrow, or it may fail in 2025. (Channelling Grumpy Mike here. ) Nothing to do with clone or genuine UNO.
Peterd51:
I added a resistor to be 'safe' but was I just lucky or can some boards handle higher current?
Depends what you mean by "handle", doesn't it? See previous paragraph.
all I can say is that I had one drawing 78mA for a few minutes at a time, spread over around 3 days, as I tested different timing sequences. Initially just flashing a LED and then sending pulses into my juke box.
I was using my mobile phone to record the sound of the stepper in the receiver as it clicked around, then I played that recording back through a sound to graph program on the PC to check that it had been sent the right numbers of pusles.
Is your board an Uno with the chip in socket? If so, you can bootload a new chip and when the current one quits, replace with the new one. The socket is there for that or remove one chip to go in a stand-alone project and put the new chip on the -development- board... Uno is not designed for end-products.
Does this mean that an OUTPUT pin should never be shorted directly to 0v or that an OUTPUT pin should never be shorted directly to 5v? I've seen both types of shorts in various tutorials, usually via a SPST switch.
dotancohen:
Off the top of my head, the Pushbutton Tutorial shorts to ground while the button is depressed.
A pushbutton connected to an Arduino pin is working with an INPUT. Connecting an input to ground or +5 is OK and will simply read back as LOW or HIGH, respectively. Connecting a pin set as an OUTPUT to ground or +5, however, will damage or destroy the pin or maybe the entire Arduino.