Pull-up and pull-down resistors are vital components in the world of electronics, especially in microcontroller-based circuits. Whether you're using an Arduino, Raspberry Pi, or any other microcontroller, understanding pull-up and pull-down resistors is essential. In this blog, we'll dive deep into these components, how they work, and why they are crucial for reliable circuit performance.

Arduino

related projects, submodules and templates

If you’re just getting started with
Arduino
, we have many

What are Pull-ups and Pull-downs?

Pull-up and pull-down resistors are components added to circuits to ensure that pins on a microcontroller have a known voltage level, usually either VCC (5V or 3V) or GND (0V), before they are actively driven by other components. Pull-ups pull the voltage level up to VCC when the pin is not active, while pull-downs pull the voltage down to 0V.

Pull-up Resistor vs Pull-down Resistor

To more clearly highlight the distinctions between pull-up and pull-down resistors, I'll present a side-by-side comparison in the table below:

| Pull-up Resistors | Pull-down Resistors | | :=== | :=== | | Connect between I/O pin and +supply voltage, with an open switch connected between I/O and ground. | Connect between an I/O pin and ground, with an open switch connected between I/O and +Supply. | | Keeps the input “High” | Keeps the input “Low” | | More commonly used | Less commonly used |

What is PinMode and DigitalRead in Arduino?

In Arduino, setting the pinMode for a GPIO (General Purpose Input/Output) pin as INPUT sets the microcontroller to read incoming signals. If digitalRead reads a high voltage close to 5V, it will return HIGH, and if it reads close to 0V, it returns LOW. However, when a pin is set as an INPUT and is not connected to any voltage or is between different voltage levels, it is said to be "floating," and its state could be unreliable.

Importance of Pull-up and Pull-down Resistors in Circuits

To prevent a pin from floating, we use either a pull-up or a pull-down resistor. The resistance usually ranges around 1K to 10K ohms, although the exact value can be calculated based on the impedance requirements of the circuit.

When connected in a circuit, the resistor pulls the voltage across the pin to a known level. For example, with a pull-up resistor, a digitalRead on an Arduino GPIO pin will return HIGH unless actively driven low. This ensures a stable logic level, thus making the reading consistent and reliable.

Schematics and Practical Examples

In a typical pull-up schematic, the resistor is connected between the pin and VCC. For pull-downs, the resistor connects the pin to GND. These schematics often appear in circuits with switches, NAND gates, CMOS, and TTL logic devices.

A typical schematic diagram of pull-up resistor and pull-down resistors used in ESP32 microcontroller
Typical pull-up resistor and pull-down resistors used in ESP32 microcontroller.

Role in Digital Protocols and Transistors

Pull-up and pull-down resistors also have their place in digital protocols like I2C, where they are used to maintain data line and clock line states. They also find applications in circuits with transistors, acting as a voltage divider when the transistor is in the ON or OFF state.

Arduino's Built-In Pull-ups and Pull-downs

Since pull-up resistors are so commonly needed, many MCUs, like the ATmega328 microcontroller on the arduino microcontrollers often have internal pull-up and sometimes pull-down resistors that can be enabled or disabled through software by setting pinMode to INPUT_PULLUP or INPUT_PULLDOWN. This is extremely useful when you're low on external components.

To enable internal pull-ups on an Arduino, you can use the following line of code in your setup() function:

pinMode(5, INPUT_PULLUP); // Enable internal pull-up resistor on pin 5
pinMode(6, INPUT_PULLUP); // Enable internal pull-up resistor on pin 6
pinMode(7, INPUT_PULLUP); // Enable internal pull-up resistor on pin 7

How to Calculate Resistance of a Pull-up Resistor?

The value of the resistor in ohms is essential for maintaining the impedance balance in the circuit. A value too low will cause excessive current to flow through the circuit, while a too high resistance may not effectively pull the voltage level to 0V or 5V.

Let's say you want to limit the current to approximately 1mA when the button is pressed in the circuit above, where Vcc = 5V. What resistor value should you use?

To calculate the pull-up resistor, we'll be using Ohm's Law:

V = I x R, where V is the Vcc, I is the current through the pull-up resistor and R is the resistance of pull-up resistor

Rearrange the above equation with little algebra to solve for the resistor:

Pull Resistor Resistance = Vcc / current through the pull-up resistor = 5V / 0.001A = 5k ohms

Pull-ups vs. Pull-downs: When to Use Which?

Choosing between pull-ups and pull-downs often depends on the specific requirements of your circuit. However, pull-ups are generally more common because CMOS and TTL logic chips usually have a higher noise margin at the high-end (closer to VCC than to GND).

The Physics Behind It: Ohm's Law

Ohm's Law is the foundation when it comes to understanding resistors. The formula V = I * R, where V is the voltage, I is the current, and R is the resistance, governs how resistors work in circuits. The resistor limits the current that can flow between VCC and the input pin, balancing the impedance and providing a stable voltage level for digitalRead to interpret.

Real-world Applications: Switches and Sensors

In real-world applications, pull-up and pull-down resistors are commonly used with switches and sensors. When a switch is open, a pull-up resistor will ensure that the voltage at the pin is pulled up to VCC (5V or 3V). When the switch is closed, it connects the pin directly to GND, overriding the pull-up and bringing the voltage to 0V.

In sensor applications, a pull-up or pull-down can help stabilize the voltage level read by the microcontroller, offering a more accurate and reliable reading. For example, a pull-up can ensure that a temperature sensor starts with a known "high" state before it sends its own signal.

Voltage Dividers and Level Shifters

In some cases, pull-up or pull-down resistors are part of a voltage divider circuit, especially when you're interfacing 5V and 3V components. A voltage divider consists of two resistors in series connected across a voltage supply. The output voltage can be tapped between the two resistors, providing a reduced voltage that is proportional to the ratio of the resistors.

Common Pitfalls and Tips

  1. Wrong Resistor Value: Choosing a resistor with a value too low can cause excessive current to flow, wasting power and possibly damaging the microcontroller pin.
  2. Forget to Connect the Resistor: When the resistor is not connected, the pin will float, leading to unreliable readings.
  3. High-impedance Sources: If you're connecting a high-impedance source to a pin, even a large pull-up or pull-down resistor may not effectively set the logic level. In this case, consider using a buffer or amplifier circuit.
  4. Wire Length: Longer wire runs can introduce noise and resistance, affecting the performance of pull-up and pull-down resistors.

Final Thoughts

Pull-up and pull-down resistors are more than just "additional components" in your electronic projects; they're fundamental to the reliable operation of microcontrollers, transistors, and logic gates. Understanding their function, role in circuits, and practical applications can make the difference between a project that functions inconsistently and one that operates reliably.

By now, you should have a solid understanding of pull-up and pull-down resistors, how to set the pinMode and use digitalRead in your Arduino projects, and the significance of resistance and impedance in these configurations. Whether you're a hobbyist or a professional, these resistors are tools you'll come back to time and time again.

With this, we've reached the end of our comprehensive guide. Happy building!

If this sounds interesting to you and you'd like to request a demo or learn more, please contact sales.

Contact Sales
Profile avatar of the blog author

Jharwin Barrozo

Jharwin is an electronics engineer mainly focused on satellites. He built his own ground station using Flux to monitor RF activities on the International Space Station. Find him on Flux @jharwinbarrozo

Go 10x faster from idea to PCB
Flux is an all-in-one EDA. Use re-usable blocks, scripting, and a library you don’t have to manage to dramatically reduce the time it takes to go from idea to prototype.
Illustration of sub-layout. Several groups of parts and traces hover above a layout.Illustration of sub-layout. Several groups of parts and traces hover above a layout.
Flux is a better way to build PCBs
Go 10x faster from idea to PCB by reducing busy work, never starting from scratch, and keeping your team in sync. All from the browser.
Screenshot of the Flux app showing a PCB in 3D mode with collaborative cursors, a comment thread pinned on the canvas, and live pricing and availability for a part on the board.
Flux is a better way to build PCBs
Go 10x faster from idea to PCB by reducing busy work, never starting from scratch, and keeping your team in sync. All from the browser.
Screenshot of the Flux app showing a PCB in 3D mode with collaborative cursors, a comment thread pinned on the canvas, and live pricing and availability for a part on the board.
Flux is a better way to build PCBs
Go 10x faster from idea to PCB by reducing busy work, never starting from scratch, and keeping your team in sync. All from the browser.
Screenshot of the Flux app showing a PCB in 3D mode with collaborative cursors, a comment thread pinned on the canvas, and live pricing and availability for a part on the board.
Flux for Enterprise
Learn how Fortune 500s are revolutionizing hardware design at scale with AI.
Flux for Enterprise
Join leading Fortune 500s and over 300k hardware engineers revolutionizing the way they build PCBs with AI
Flux for Enterprise
Join leading Fortune 500s and over 300k hardware engineers revolutionizing the way they build PCBs with AI