What happens if I get 5v in an output pin?

I have a (highly simplified) circuit

5v -> 560 ohm resistor -> led -> digitalPin 0

I can turn the LED on by digitalWrite(0,LOW) and off by digitalWrite(0, HIGH).

My question is, what's happening to my arduino if it's pushing 5v out pin 0, and also receiving it in? Someone told me that LEDs only close the circuit when the potential difference between the cathode and the anode is greater than X volts. In this case it should be 5v on both sides, so maybe the circuit doesn't open?

My question is, what's happening to my arduino if it's pushing 5v out pin 0, and also receiving it in? Someone told me that LEDs only close the circuit when the potential difference between the cathode and the anode is greater than X volts. In this case it should be 5v on both sides, so maybe the circuit doesn't open?

Somewhat confuing question. An Arduino I/O pin can only be an input pin or a output pin at any given specific time. They can be programmed on the run to switch from being an input to an ouput pin and visa versa, but not both at the same time. All I/O pins default to input pins upon power up or reset. Can you rephrase your question?

Lefty

when the pin is low your sinking current through the chip to ground, when its high its not really doing anything, as a LED is a diode and only lets juice flow from one direction

Retrofly:

I have an LED I hooked up mentioned above. I can turn it off by setting the pin LOW (short to ground). I can turn it on by setting the pin HIGH (short to 5v).

What exactly is that digitalPin seeing when I set it HIGH. It's attempting to give out 5v right? At the same time it's getting in 5v from the cathode of the LED.

Semi-related, what would happen if I hooked 5V directly up to a digitalPin in output mode set to HIGH.

when the pin is low your sinking current through the chip to ground, when its high its not really doing anything, as a LED is a diode and only lets juice flow from one direction

Not sure I agree with that statement. An Arduino output pins have both active current sink and current source drivers. Of course if current actual flows and in what direction depends solely on what and how the external components are wired up.

Lefty

OP:

5v -> 560 ohm resistor -> led -> digitalPin 0

I can turn the LED on by digitalWrite(0,LOW) and off by digitalWrite(0, HIGH).

then:

I have an LED I hooked up mentioned above. I can turn it off by setting the pin LOW (short to ground). I can turn it on by setting the pin HIGH (short to 5v).

Which is it?

Semi-related, what would happen if I hooked 5V directly up to a digitalPin in output mode set to HIGH.

Why not try it?

I can turn the LED on by digitalWrite(0,LOW) and off by digitalWrite(0, HIGH).

Sorry I got confused on the second time (as it's backwards to how I would normally do it).

I have an LED I hooked up mentioned above. I can turn it off by setting the pin LOW (short to ground). I can turn it on by setting the pin HIGH (short to 5v).

I'm confused, first you posted: "I can turn the LED on by digitalWrite(0,LOW) and off by digitalWrite(0, HIGH)." , that is the opposite?

What exactly is that digitalPin seeing when I set it HIGH. It's attempting to give out 5v right? Correct. At the same time it's getting in 5v from the cathode of the LED. No, the LED is what 'sees' 5v on both sides, therefore no current can flow because there is no voltage differential.
Semi-related, what would happen if I hooked 5V directly up to a digitalPin in output mode set to HIGH. Nothing, no voltage difference so no current flow. However if you wire +5vdc to a output pin and set the output pin LOW, then a short circuit exists and it will burn out the output pin.
Lefty

To expand on retrolefty's explanation of "voltage differential", in a simplified "layman's understanding", which is more than sufficient for an explanation, current "flows" from "high voltage" to "low voltage".

The low voltage is called "ground" (for historical and litteral reasons), and is typically 0 volts (but it doesn't have to be!); so 5V will flow to ground, or 0V, because there is a difference of 5 volts.

If your ground level were instead 2.5 volts, it would still flow, because there is a difference of 2.5 volts. If the ground level were -5 volts, it would flow because the difference is 10 volts.

There is such a thing called a "dual-ended" supply, one which "outputs" a positive and negative voltage; you sometimes see components (operational amplifiers, especially) that need such a supply. It is made by using a dual-ended supply with a common ground.

Imagine if you hooked up two 9V batteries in series, so that you had an 18 volt potential across their two end terminals. If instead, you tapped off the center connection between the two batteries, and called that "ground", you would now have a "dual-ended" supply, where one side output +9 volts, and the other side -9 volts (of course, on the negative side of the supply current is actually flowing from ground to -9 volts - something to keep in mind when you design such circuits).

These are the basics. If you want the real skinny on all of this (and I suggest you probably should read up on it) - find a copy of Grob's "Basic Electronics"; its well worth studying.

:slight_smile:

retrolefty & cr0sh

Sorry for the confusing description. Your explanation makes perfect sense! Thanks!

Sorry for reply an old post. I cant send a PM for being newby here :frowning:

@Scott:
As long as I understood, you wonder why "the two currents didn't crashed": 5v -> resistance -> led <- 5v

I used to think the same :wink: The answer is that Potencial is not the same as current (this phrase is soooo important).
Any wire, if there's no current in it, is at the same potencial (this phrase is sooo impotant too).

For example. This circuit:
5v -> 500ohm -> 100 ohm ----------> (open)
What is the potencial in all the wires? 5v
What is the current in the wires? 0A

so:

5v -> 560 ohm -> (5v) led open circuit (5v)<- 5v

So, having all the wires at 5v, the circuit is consistent: led will be open as hipotesis. No current. 0 current.
The diference of potencial in the resistance is 0. And the current is 0. V=IR holds :wink: R=V/I is not applicable to calculate resistance, of course.

Hope this helps for you and for others :slight_smile: