Fundamentals

Pull-Up vs Pull-Down Resistors Explained

An unconnected input is not zero. It floats, and a floating input can change state with a nearby hand. A pull resistor gives it a defined resting value.

22 November 20268 min read
A pushbutton and a resistor wired to an Arduino input pin on a breadboard
A pull resistor sets the resting state of an input until a button changes it.

Bu projeyi gerçekten kurmak istersen parçaları hobidevre.com'dan temin edebilirsin →

Build it for real

To build this project for real, get the parts from hobidevre.com → hobidevre.com →

More build guides: hobidevre.com/blog

Why inputs float

A digital input measures voltage relative to ground. If nothing drives the pin, its voltage is undefined. Very small leakage currents and nearby electric fields can move it across the logic threshold, so the sketch sees random changes even though nobody touched the button.

This is why a button with only one connection to an input does not work reliably. Closing the button connects the pin to one level, but opening it leaves the pin connected to nothing. A pull resistor supplies the missing connection for the open state.

The pull-down approach

A pull-down resistor connects the input to ground. With the button open, the pin sits at LOW. Pressing the button connects the pin to the supply, overriding the resistor and making the reading HIGH. The resistor limits current during the press so the supply is not shorted to ground.

The logic is intuitive: pressed means HIGH. The cost is one extra resistor per button and a little more wiring. For a simple circuit where you want the code to read naturally, a pull-down is easy to explain and easy to teach.

The pull-up approach

A pull-up resistor connects the input to the supply. With the button open the pin reads HIGH. Pressing the button connects the pin to ground, so the reading becomes LOW. The resistor again limits current, this time from the supply through the resistor to ground.

The logic is inverted compared with a pull-down, but the circuit uses fewer parts if the board has an internal pull-up. Reading the inverted state correctly is the only adjustment needed in code.

Using INPUT_PULLUP

Most boards include a pull-up resistor on each digital input that can be enabled in software. Setting the pin mode to INPUT_PULLUP removes the need for an external resistor. Connect the button between the pin and ground, and the input reads HIGH when open and LOW when pressed.

The internal resistor is convenient but has a relatively high value. It is fine for buttons and slow signals. For a long cable or a noisy environment, an external resistor with a lower value may give a more stable result.

Remember that pressed can mean LOW

With a pull-up, the pressed state is LOW. Code written for a pull-down will behave backwards: the LED lights when the button is released. This is not a hardware fault. Change the condition in the sketch so that LOW means pressed, and the circuit will respond correctly.

Write the expected state in a comment near the pin definition. When you return to the project later, the comment prevents a wrong assumption about which level means a press. Testing with a simple print of the raw pin state confirms the convention in seconds.

Choosing a resistor value

The resistor must be large enough to limit current when the button is pressed and small enough to hold a clear logic level when it is open. A value in the kilo-ohm range is typical. Much too large and the input becomes noise-sensitive; much too small and the pressed current is wasteful.

For most hobby buttons the exact value is not critical. Use a common value from your parts box and verify that the reading is stable. If the input still changes without a press, check the wiring and breadboard contacts before changing the resistor.

Which one should you use

Use the internal pull-up for ordinary buttons: it is the simplest circuit and uses no extra parts. Use an external pull-down when you want the natural logic of pressed equals HIGH, or when the sensor documentation specifies one. Both are valid; the wrong choice is leaving the input floating.

Some sensors include their own pull resistor on the signal line. Check the module documentation before adding another. A sensor that already has a pull-up often works correctly with no external part at all.

Whatever you choose, verify with a serial print of the raw state while pressing and releasing. A stable change between two values is the proof that the input is no longer floating.

const int BUTTON = 2;

void setup() {
  pinMode(BUTTON, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  Serial.println(digitalRead(BUTTON));
  delay(200);
}
  • Floating input: undefined reading
  • Pull-down: resting LOW, pressed HIGH
  • Pull-up: resting HIGH, pressed LOW
  • INPUT_PULLUP: no external resistor needed

Get the parts

Pushbuttons and resistor assortments are available from hobidevre.com if you want to build both versions.

Frequently asked questions

What happens if I leave the input floating?

The reading changes unpredictably with noise, so the sketch may detect presses that never happened.

Why does my button work backwards?

With a pull-up, pressed means LOW. Change the condition in the sketch to match the circuit.

Do I need an external resistor with INPUT_PULLUP?

No. The internal pull-up is used. Connect the button between the input pin and ground.

Related reading

Practise in the browser

Open the same layout in the simulator and follow the steps. Sign in to save your work.