# What are pull-up resistors for and how are their values calculated?

I have some questions related to pull-up resistors. Just trying to understand in depth here.

1. Why do we use pull-up resistors on the input pins of a microcontroller?

2. Can I directly connect GPIO input pin to high level logic like for example 5V with using any resistor?

3. If pull-up resistor is used to limit the current, the GPIO input pin will anyways have a very high input impedance. Then why do we need a pull-up resistor?

4. How to calculate the value of a pull-up resistor? Why generally 10k ohm resistor is used?

5. Similar questions for pull-down resistor...

• 4) 10k is often a good compromise between EMI susceptibility and current consumption. Applications for demanding environments tend to use 4k7 to 10k or even lower. Whereas low current, consumer electronic applications in less demanding environments tend to compromise and pick higher values. Commented Aug 10, 2023 at 13:04
• 2) how would you input a LOW? Commented Aug 10, 2023 at 17:56
• Please check this document.ti.com/lit/an/slva485/… Commented Aug 11, 2023 at 11:18

When the microcontroller pin is configured as an input, it is effectively electrically disconnected from everything else. That's what we mean by high impedance - the resistance between the pin and anything inside the MCU is very, very high. If you don't connect that pin to something externally, then it's effectively electrically disconnected from everything.

This doesn't mean it isn't being "monitored", the MCU is still measuring to determine if its potential is high or low, so that software can "read" its value, but being physically unconnected, its potential (voltage) is free to rise and fall under the influence of noise and nearby changing potentials. Thus it's liable to flap wildly up and down in potential, seemingly randomly, and this will produce unnecessary switching currents inside the MCU.

Can I directly connect GPIO input pin to high level logic like for example 5V with[out] using any resistor?

Unused inputs can be tied directly to 0V or +3.3V or +5V (depending on the MCU) to prevent the input from freely changing potential, and to avoid unnecessary switching currents.

You could achieve the same effect with a resistor to +3.3V or ground, but a wire is cheaper. Obviously, connecting the pin directly to +3.3V or ground means you can no longer use that pin as either input or output, since its potential is now fixed.

You didn't ask, but unused inputs can be prevented from fluctuating randomly in potential by configuring them as outputs instead.

Why do we use pull-up resistors on the input pins of a microcontroller?

Alternatively, to keep an unused input "quiet", you can tie it to either supply with a resistor, which will work to more gently coerce the pin's potential high or low. If the MCU has this feature, you could configure the pin to use the MCU's own internal pull-up or pull-down resistor.

If you intend to actually use the input, by applying a potential and having the MCU interpret that as a digital high or low, then using a pull-up or pull-down resistor doesn't prevent you from explicitly applying your own high or low potential, from another voltage source, as long as the resistor's "coersion" is far weaker than the source of signal trying to override it.

If you don't intend to use the input today, perhaps you will in the future. Maybe you'd would use a pull-up resistor to quieten an unused input today, but in later or different circuit revisions you could simply not populate that resistor, leaving it free for use.

While all the above is true, as I said, it's probably far easier and cheaper to just tie an unused input directly to a supply rail with a wire, so there must be another reason why we use pull-up and pull-down resistors. To explain why, first you must understand the electronics of components connected in series between supply rails. I wrote another answer about this, which you can read here for more details. In the meantime, I'll refer to these circuits:

simulate this circuit – Schematic created using CircuitLab

In circuit A, node A (which is feeding an MCU input), when switch SW1 is open node A is floating, and since the MCU input is high impedance, it can fluctuate in potential. In other words, the potential at A is undefined. It is only when the switch is closed that the potential at A becomes forced to 0V, because there's now a very low resistance between A and 0V. You can, in a sense, consider the switch to be "pulling down" the potential at A.

The same problem occurs with circuit B, but this time the switch is only able to pull node B high; otherwise the potential at B is undefined, and subject to noise and interference.

Without a pull-up (or down) resistor, when the switch is open, MCU input potential is not being explicitly controlled, and is ambiguous. The MCU would have no reliable way of distinguishing between switch states. We would use a resistor to avoid this condition when the switches are open, which I show in circuits C and D.

For circuit C we are coercing node C high with R3, providing a gentle "pull" towards +3.3V. With the switch open, because that "pull" experiences no opposition, the potential at node C is 3.3V. However, by closing switch SW3, there's suddenly a much more forceful, low impedance tug towards 0V, far stronger than the pull up, so the voltage at C falls very close to 0V. How close depends on the resistance of the switch when its closed. As long as we choose a pull-up resistor R3 far greater than the resistance of switch SW3 when closed, the switch will be able to easily overcome any opposition from R3.

Circuit D shows the same principle using pull-down resistor R4 to gently set node D at 0V, unless switch SW4 is closed, which forcefully pulls D high.

In a moment I will address the "current limiting" benefits of R3 and R4, but for now, let me illustrate another incredibly useful benefit for pull-up resistors (and I suppose pull-down, but that's not seen so often). Consider these circuits:

simulate this circuit

On the left (E) I illustrate how two or more switches can be connected in parallel, such that pressing any one of them will pull the output node E low. The exciting part is that we may use any type of switching element in the place of the those mechanical devices, such as transistors, which fulfill the same role.

I've done that in circuit F. The advantage here is that those transistors can be switched electronically, by the output from some prior stage, and by combining them in parallel like this, you can have any one of them "activate" some MCU function.

This technique is called "wire-NOR" (or often just "wire-OR") since switching any transistor on (which requires a "high" base/gate potential), or activating any switch, will cause the output F to go low.

Many devices such as sensors, comparators, logic gates and I2C bus participants use transistors in this "open-collector" or "open-drain" configuration, where the collector/drain of the transistor (the output) is not actually connected to anything inside the IC, leaving you free to join many collectors/drains together. With a single external pull-up resistor, you can have any of the devices pull their common output low. See the LM393 comparator and the 74HC03 logic IC.

If pull-up resistor is used to limit the current, the GPIO input pin will anyways have a very high input impedance. Then why do we need a pull-up resistor?

There's no need to limit current if you are connecting an unused input high or low, since as you point out, the high impedance of that input will draw almost no current. That's why you don't need to use a resistor in that particular role, and can employ a direct link instead.

However, in all the circuit scenarios I illustrated above, a resistor is mandatory. Imagine what would happen if we replaced any of the resistors above with a direct link to the supply rail. When the switching element closes, this would create a direct short circuit across the supply, causing unconstrained current flow, and something would break.

How to calculate the value of a pull-up resistor? Why generally 10k ohm resistor is used?

Low resistances correspond to higher currents. Higher currents correspond to higher power dissipation and consumption. For battery powered equipment this is critical. For mains powered systems, not so much. Given that we are typically dealing with a few volts, and the currents we can use without burning things up or being so small that the signal is swamped by noise and interference, range between microamps and milliamps, and we most often find ourselves using resistances in the 1kΩ to 1MΩ range.

What you settle on yourself is entirely dependent on the application, its power constraints, and any noise sources present. Using a 1kΩ pull-up resistor for a switch in a system being powered by a coin cell would be silly; you'd be better off closer to 1M. On the other hand, using open-collector PLC sensors in an industrial setting, with electrical noise everywhere, but oodles of current at your disposal, kilohms are much more sensible.

For a typical home project with a switch and a pull-up resistor, anywhere from 10kΩ to 100kΩ might be perfectly fine, a compromise between power consumption and noise immunity.

### Update: When don't we need a pull-up/down resistor?

If the device providing the MCU input signal is already able to both pull-up and pull-down itself, which we refer to as an output that can both sink and source current, then you don't need a resistor. In fact, putting a resistor where one is not needed is usually detrimental to performance in some way.

I illustrated open-collector/drain configurations above, which do require a pull-up resistor, but the great majority of logic devices available today have what we call "push-pull" outputs, or already have built-in pull-up/down resistors when required.

For example, the 74HC00 IC, which contains four NAND gates in a single package, each output having two transistors, one that "pulls" down, like Q6b above, and another that pulls up to the positive supply, replacing R6 above. Contrast this with the open-drain alternative, the 74HC03, which I referred to above, and which contains only the lower "pull-down" output transistor. The 74HC00 outputs can directly drive an MCU input with no resistor necessary to pull anywhere, but the 74HC03 will need one, or some other means of "pulling up".

Many digital sensor devices have open-collector/drain outputs, which would require a pull-up resistor, the value of which can only be determined from consulting their datasheets. The only useful information comes from datasheets, so I would encourage you to get used to reading them, and paying careful attention to what you can/must or cannot/must-not connect to their outputs.

It might help you to swap your question around; instead of asking when does my MCU input require a pull-up/down resistor, perhaps it's better to ask when the source of the signal fed to the MCU needs to be pulled up or down. In other words, if the source is thin air (the MCU input is "floating"), it's the source that needs help being a one or a zero, with a resistor to one or the other supply rails.

Why do we use pull-up resistors on the input pins of a microcontroller?

They are not always necessary if the driving source (the thing that drives the signal to the input pin) is an unambiguous logic level for both high and low. If the driving source is open-collector (open-drain) then, you need a pull-up resistor but, some MCUs allow you to program the option of using an internal pull-up/down.

I sometimes add pull-ups if there are some inputs that I think I might wish to use in the future and, I also add a test-point to make that process easier.

Can I directly connect GPIO input pin to high level logic like for example 5V with using any resistor?

If the GPIO device runs on 5 volts then yes. If the GPIO device runs on (say) 3.3 volts then a series resistor can be used but, preferably, use a potential divider.

If there is any doubt or, you might wish to future-proof possible redesign changes then use a resistor. Add a test point too for the reasons given above.

If pull-up resistor is used to limit the current, the GPIO input pin will anyways have a very high input impedance. Then why do we need a pull-up resistor?

It may be needed in the case of open-collector/drain outputs that feed that pin.

How to calculate the value of a pull-up resistor? Why generally 10k ohm resistor is used?

No calculation involved other than make sure it is not so high that input bias currents might make the logic level at the input ambiguous. Don't make it so low that open-collector/drain outputs have to drive a lot of wasted current aka wasted power. Usually 4.7 kΩ to about 470 kΩ is typically used on most designs but, like I said check the input bias currents.

• " no calculation involved" It is interesting that not a single answer mentions input capacitance and raise/fall timing requirements, which sometimes are defining parameters for choosing pull up/down resistance. I2C anyone? Commented Aug 10, 2023 at 18:03
1. We use them in a circuit if they are needed, and we don't use them when they are not needed. When they are needed is another question. They are used to for example define a voltage level to an input thay would otherwise be undefined. Inputs cannot be left floating unconnected, for many reasons.

2. Yes. If the MCU is specified to tolerate 5V on input without damage, you can connect the pin directly to 5V.

3. Aha, this should have been the first question why they are used, instead of how to calculate them. Most often they are used to keep an input at high logic level whem nothing else drives the input. For example, a pushbutton that eithe connects the input to 0V or disconnects it from 0V. If you don't have a pull-up, the input floats and it has no defined logic level, it could be anything and it is a very high impedance input so a nearby disturbance source such as a mobile phone or finger can make it toggle high and low.

4. With Ohm's law. Resistance is voltage divided by current. But generally the value does not matter much so 10k is a good compromise to be strong enough for most purposes to keep the line pulled up and weak enough for most purposes so not a lot of current flows. So that's why nobody uses for example 10 ohms or 10 megaohms.

5. Exact same answers 1..4 for pull-downs as for pull-ups.

Although pull-up and pull-down elements (resistors, transistors, leaks, etc.) can exist separately, in practice they are together to form a voltage divider. This is because transistors are not ideal switches (with zero and infinite resistance) and there are always leaks. For this reason, the resistance value of the pull-up resistor matters. Let's examine its effect at two different values of the pull-up resistor - 1 kΩ and 10 kΩ. For simplicity, I have modeled the pull-down element with a variable resistance of two values - 100 Ω and 1 MΩ.

## Strong pull-up resistor PU = 1 kΩ

PD = 100 Ω: If the resistance of the pull-up resistor is not high enough (1 kΩ), and the resistance of the pull-down element (of the open-collector transistor) is not low enough (100 Ω), a significant voltage appears at a low level of the input voltage (logic 0).

simulate this circuit – Schematic created using CircuitLab

PD = 1 MΩ: At high level (logic 1), the input voltage drop is small because the resistance of the pull-down element (cut-off transistor and leaks) is high (1 MΩ) compared with PU (1 kΩ).

simulate this circuit

## Weak pull-up resistor PU = 10 kΩ

PD = 100 Ω: It is enough to increase the resistance of the pull-up resistor 10 times (10 kΩ) and the input voltage at low level (logic 0) is greatly reduced.

simulate this circuit

PD = 1 MΩ: As above, at high level (logic 1) the input voltage drop is small because the resistance of the pull-down element (cut-off transistor and leaks) is relatively high (1 MΩ) compared with PU (10 kΩ). This is why 10 kΩ is a commonly used value.

simulate this circuit

## Complementary pull resistors PU = 100Ω/1MΩ, PD = 1MΩ/100Ω

The problem with the 1-resistor configuration above is that the pull-up resistor has a constant resistance and the requirements for it are contradictory - on the one hand, it must have a low resistance to ensure a high level of input voltage at logic 1; on the other hand, it must have a high resistance to ensure a low input voltage level at logic 0. This contradiction is solved (for example, in the case of complementary stages) as its resistance is dynamic and changes in the opposite direction to the resistance of the pull-down element.

Logic 0: PU = 1 MΩ, PD = 100 Ω -> Vin = 0 V.

simulate this circuit

Logic 1: PU = 100 Ω, PD = 1 MΩ -> Vin = 5 V.

simulate this circuit

• Can I politely ask the downvoter to clarify what they don't like about my answer? It would be interesting to exchange valuable thoughts… Commented Aug 12, 2023 at 15:49