Resistors to ground or power?

I am brand new to Arduino as well as tinkering with electronics in general and I noticed something when doing the projects in the Arduino starter kit book. The first project was just lighting a LED with a push button, but it had the resistor going to the + on the bread board, now I am putting the resistors to the ground on the next project. What are the differences as well as when would you need to do one vs the other? Thanks

You choose one or the other depending on your choice of logic. With a pullup, a momentary push switch will be "high" or "on" when not pushed and "low" or "off" when pushed. On the other hand with a pulldown resistor, the logic is reversed and the switch is then "on" when pushed. Depends on the action you want: on or off when pushed?

The Arduinos have built in pullup resistors though, so it's a lot easier to go for that logic since then you merely enable them in code:

pinMode (myPin, INPUT_PULLUP);

PS... just in case it wasn't clear to you why you should use either of these approaches in the first place: the connection through the resistor to either high (pullup) or low (pulldown) is to make sure the pin is always in a known state. If it's left unconnected, it may pick up stray radiation from the surrounds and its state may wander. So we force it one way or the other with a pullup or pulldown resistor to one state, then when we press the switch it obviously swings to the opposite state since that's the purpose of the button.

Thank you, that helped a lot. So when you choose to use pullup you will have the resistors going to the + and going to the - if you choose to use pulldown?

kfrancis1492:
Thank you, that helped a lot. So when you choose to use pullup you will have the resistors going to the + and going to the - if you choose to use pulldown?

Yep.

I think the kfrancis's question may be even simpler than it seems at first. I don't think ou is asking about pullup vs. pulldown resistors (although I could be wrong). My interpretation of the question is that kfrancis is asking about current-limiting resistors on output pins.

Let's talk about current-limiting resistors on output pins. Ohm's law states that current = volts divided by resistance. What that means is that if you put a voltage across a very low-resistance circuit, you will get a very high current. High currents create heat, and beyond a certain point, high currents make things burn out, light on fire, and blow up. This is how a fuse works: when current exceeds a certain threshold, the fuse heats up and burns out.

When you configure an Arduino's pin in output mode and then set the pin to HIGH, the Arduino puts 5v on the pin. If the pin is not connected to anything, there is nowhere for current to flow, so the 5v just sort of sits there, like a water spigot that is closed. There's pressure behind the spigot, but no water is coming out. Now let's say you connect an LED's anode (positive) leg to the pin. Now there is 5v on the cathod leg of the LED, but still nowhere for current to flow. Finally, you connect the LED's cathod (negative) leg to the Arduino's ground. BAM. Now there's somewhere for current to flow, and it starts to flow.

What's the current flow in that circuit? Ignore for a minute the LED's resistance, which is a whole can of worms all its own. The gist of the situation is that the resistance in the circuit is low, so the current flow is high, and very shortly, or possibly very quickly, your LED is going to burn out. If your LED burns out quickly, you may save your Arduino's output pin from burning out first.

To fix situations like this, we install a current-limiting resistor in any circuit where there is not enough inherent resistance in the circuit to keep current-flow to a desirable level. For example, if you are putting 120v through an incandescent light bulb, the bulb itself has plenty of resistance, and no additional resistance is needed. When we install an LED on an Arduino, the LED alone won't keep the current flow down low enough, so we install a resistor. What value resistor? The desired current flow for a typical 5mm LED is less than about 20 mA. 5v / 20 mA = 250 Ohms would be the minimum resistor value to use. Actually, that is incorrect, because the LED itself "drops" some number of volts, but forget about that for now, and just get the gist of: V = IR.

Now to get to your question: does it matter where you put the resistor? The answer, in the case of a current-limiting resistor, is, in many cases, no. There is no practical difference between these circuits:

+5v -> LED -> Resistor -> GND
+5v -> Resistor -> LED -> GND

In either case, the resistor will reduce current flow in exactly the same way.

When designing real-world devices, placement of resistors may be more important. Consider a scenario where you have a +5v circuit, and the resistor is placed all the way at the end of the circuit, near the GND connection. Now imagine that, somehow, accidentally, the +5v circuit gets shorted to a ground wire. If the short happens "upstream" of the resistor, the current will no longer be flowing through the resistor, and it will no longer be limited by the resistor. So in some real-world scenarios, it makes sense to install the current-limiting resistor as close to the +5v source as possible, so that any short-circuit that occurs is very likely to occur "downstream" of the resistor. But this is just one possible consideration, of many. On the lab bench, that's not something that you really have to think about.

The issue with pullup vs. pulldown resistors has to do with input pins, not output, and is as was previously described.

1 Like

kfrancis1492:
I am brand new to Arduino as well as tinkering with electronics in general and I noticed something when doing the projects in the Arduino starter kit book. The first project was just lighting a LED with a push button, but it had the resistor going to the + on the bread board, now I am putting the resistors to the ground on the next project. What are the differences as well as when would you need to do one vs the other? Thanks

In a single series circuit... the resistor limits the current regardless of where it's placed... unless there's more than one path.

So before or after makes little difference unless you're using it as a voltage reference for something else.

(Again i'm very very sorry if any of my information is wrong as Master Mike will verbally punish me)

joshuabardwell:
I think the kfrancis's question may be even simpler than it seems at first. I don't think ou is asking about pullup vs. pulldown resistors (although I could be wrong). My interpretation of the question is that kfrancis is asking about current-limiting resistors on output pins.

The first experiment is using a push button. The second experiment is using LEDs.

So the question, unknowingly, became "what is the difference between a pull-up resistor and a current limiting resistor?"

Ah, right... I saw the word "push-button" and thought it was to do with pullups and pulldowns, whereas he was probably asking if the order of + led resistor - vs + resistor led - makes any difference.

Sorry if i caused any confusion!

kfrancis1492:
Thank you, that helped a lot. So when you choose to use pullup you will have the resistors going to the + and going to the - if you choose to use pulldown?

Because you always draw ground (or negative power) at the bottom of the circuit and
supply (positive) at the top. Hence up and down.

A pull-up or pull-down resistor is the terminology applied to an input or a bussed signal
where the resistors define the voltage level when nothing else is driving the line (such
as a push-button switch when open). Usually the value isn't critical at all, 1k to 1M will
both work.

Current-limiting is to protect the output driver of a chip (or its load) from excess current
which would cause damage or other undesired effects (power wastage?). You calculate the
correct value for a current limiting resistor.

Good insight.

joshuabardwell:
I think the kfrancis's question may be even simpler than it seems at first. I don't think ou is asking about pullup vs. pulldown resistors (although I could be wrong). My interpretation of the question is that kfrancis is asking about current-limiting resistors on output pins. ---snip---

Excellent write-up. Cheers man. :wink:

Thanks for all the help, and sorry for the confusion with the question.
"+5v β†’ LED β†’ Resistor β†’ GND
+5v β†’ Resistor β†’ LED β†’ GND

In either case, the resistor will reduce current flow in exactly the same way."

That is what I was originally looking for, but now I have another question. So the order in which the resistor is in does not matter when being used on an output pin because it will add resistance to the current regardless, but how exactly does it affect an input pin? If connected to the ground and negative side the switch in this case will be LOW by default, and if connected to the + to the positive side of the switch would default to HIGH?

Switches don’t have a positive or negative side. They have terminals that either form a circuit (closed) or don’t (open), and when the button is pressed (or latched) the circuit path between those terminals changes.

In a button + pull-up/down configuration, your switch connects directly to the input pin, along with a resistor to either V+ (pullup) or Ground (pulldown). The other side of that switch (open until the button is pressed) connects directly to the opposite rail. When the button is not pressed, the state of the input is determined by the resistor. Either high (pullup) or low (pulldown). When the button is pressed, the short to either rail over-rides the high resistance from the resistor and the input pin follows the rail connected through the button.

1 Like

Ok I see, so the resistor should always be on the same side of the switch that the wiring going to the pin is on? The only difference will be whether or not it goes to the 5V or ground, which would dictate pull-up or pull-down.

kfrancis1492:
Ok I see, so the resistor should always be on the same side of the switch that the wiring going to the pin is on? The only difference will be whether or not it goes to the 5V or ground, which would dictate pull-up or pull-down.

Yes, exactly. Now we are talking about pullup/pulldown resistors, NOT current-limiting resistors, and the location matters. Your description is correct. When the switch is closed, the pullup/pulldown resistor connects the input pin to either ground or +5v, providing a "default" value. Without this connection, the pin would be floating at no particular voltage level, and could randomly read high or low.

That should be "when the switch is open". XD

joshuabardwell:
I think the kfrancis's question may be even simpler than it seems at first. I don't think ou is asking about pullup vs. pulldown resistors (although I could be wrong). My interpretation of the question is that kfrancis is asking about current-limiting resistors on output pins.

Let's talk about current-limiting resistors on output pins. Ohm's law states that current = volts divided by resistance. What that means is that if you put a voltage across a very low-resistance circuit, you will get a very high current. High currents create heat, and beyond a certain point, high currents make things burn out, light on fire, and blow up. This is how a fuse works: when current exceeds a certain threshold, the fuse heats up and burns out.

When you configure an Arduino's pin in output mode and then set the pin to HIGH, the Arduino puts 5v on the pin. If the pin is not connected to anything, there is nowhere for current to flow, so the 5v just sort of sits there, like a water spigot that is closed. There's pressure behind the spigot, but no water is coming out. Now let's say you connect an LED's anode (positive) leg to the pin. Now there is 5v on the cathod leg of the LED, but still nowhere for current to flow. Finally, you connect the LED's cathod (negative) leg to the Arduino's ground. BAM. Now there's somewhere for current to flow, and it starts to flow.

What's the current flow in that circuit? Ignore for a minute the LED's resistance, which is a whole can of worms all its own. The gist of the situation is that the resistance in the circuit is low, so the current flow is high, and very shortly, or possibly very quickly, your LED is going to burn out. If your LED burns out quickly, you may save your Arduino's output pin from burning out first.

To fix situations like this, we install a current-limiting resistor in any circuit where there is not enough inherent resistance in the circuit to keep current-flow to a desirable level. For example, if you are putting 120v through an incandescent light bulb, the bulb itself has plenty of resistance, and no additional resistance is needed. When we install an LED on an Arduino, the LED alone won't keep the current flow down low enough, so we install a resistor. What value resistor? The desired current flow for a typical 5mm LED is less than about 20 mA. 5v / 20 mA = 250 Ohms would be the minimum resistor value to use. Actually, that is incorrect, because the LED itself "drops" some number of volts, but forget about that for now, and just get the gist of: V = IR.

Now to get to your question: does it matter where you put the resistor? The answer, in the case of a current-limiting resistor, is, in many cases, no. There is no practical difference between these circuits:

+5v -> LED -> Resistor -> GND
+5v -> Resistor -> LED -> GND

In either case, the resistor will reduce current flow in exactly the same way.

When designing real-world devices, placement of resistors may be more important. Consider a scenario where you have a +5v circuit, and the resistor is placed all the way at the end of the circuit, near the GND connection. Now imagine that, somehow, accidentally, the +5v circuit gets shorted to a ground wire. If the short happens "upstream" of the resistor, the current will no longer be flowing through the resistor, and it will no longer be limited by the resistor. So in some real-world scenarios, it makes sense to install the current-limiting resistor as close to the +5v source as possible, so that any short-circuit that occurs is very likely to occur "downstream" of the resistor. But this is just one possible consideration, of many. On the lab bench, that's not something that you really have to think about.

The issue with pullup vs. pulldown resistors has to do with input pins, not output, and is as was previously described.

Finally i understand this thing! Really appreciate this!

1 Like

kfrancis1492:
I am brand new to Arduino as well as tinkering with electronics in general and I noticed something when doing the projects in the Arduino starter kit book. The first project was just lighting a LED with a push button, but it had the resistor going to the + on the bread board, now I am putting the resistors to the ground on the next project. What are the differences as well as when would you need to do one vs the other? Thanks

If everything is connected in a 'row' --- ie. chained together in a line (ie. "series" connections), then no difference in the basic control of the LED from a basic circuit theory point of view. This is for a resistor, switch, and LED in a straight line, with the voltage source connected on the appropriate end, and ground connected on the other end. Interchange the order of the components....... you'll still have the same control of the LED.