Skip to content

Embedded Systems

What is a pull-up resistor?

A pull-up resistor joins an input pin to the supply so it reads HIGH when nothing else is driving it. A button wired from the pin to ground then pulls the pin LOW when pressed. Without the pull-up, a released button leaves the pin joined to nothing, and it reads at random.

A pin with nothing on it

An input pin measures a voltage and answers in logic. On a 5 V board, digitalRead gives HIGH at 3.0 V or more and LOW at 1.5 V or less. In between, the answer is unreliable.

A push button only joins two wires while you press it. Wire one side to the pin and the other to GND, and a press gives the pin a solid 0 V. Let go and the pin is joined to nothing at all. It's floating: stray charge from your hand, nearby wires and the air pushes it around, and it reads HIGH, then LOW, at random.

Live experiment

Hold the button, then let the pin float

A button from pin 2 to GND, and a program that lights Pip while digitalRead(2) is LOW. Hold the button and let go, then switch the pin to plain INPUT and watch what it reads with nothing holding it.

Try it yourself: free lesson

“Press a button” is lesson 4 of 6 in Blink Bay, Embedded Systems World 1. Free with an account. Lessons unlock in order, so you’ll do the 3 before it first.

A weak spring

The fix is a resistor from the pin to 5 V. It's a weak spring: with the button released, almost no current flows, so the pin sits at 5 V and reads HIGH. Press the button and the pin is joined straight to 0 V. The button wins easily, and the pin reads LOW.

inside the board5 V35 kΩpull-uppin 2releasedreleased: 5 V→ reads HIGHpressed: 0 V→ reads LOW
A pull-up holds pin 2 at 5 V (HIGH); pressing the button pulls it to 0 V (LOW)

The resistor's job is also to limit the current while the button is pressed. With a 35 kΩ pull-up:

I = 5 V over 35 kΩ ≈ 0.14 mA

That's a tiny current, which is why pull-ups are usually tens of kilohms. Too small a value wastes current while pressed; too large leaves the pin easy to disturb.

INPUT_PULLUP

Arduino boards have a pull-up built into every pin, about 35 kΩ on an Uno. One line switches it on, so you don't need a resistor at all:

void setup() {
  pinMode(2, INPUT_PULLUP);
  pinMode(9, OUTPUT);
}

void loop() {
  if (digitalRead(2) == LOW) {  // pressed
    digitalWrite(9, HIGH);
  } else {
    digitalWrite(9, LOW);
  }
}

Notice the test is == LOW. With a pull-up, the button is active-low: pressed reads LOW, released reads HIGH. It feels backwards at first, but it's how almost every button on a microcontroller is wired.

One more thing a real button does: its contacts bounce for a few milliseconds, so one press can read as several. The pull-up doesn't fix that. A short wait or a check on the timing does.

Free lesson

Now build it yourself

Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.

Try it yourself: free lesson

“Press a button” is lesson 4 of 6 in Blink Bay, Embedded Systems World 1. Free with an account. Lessons unlock in order, so you’ll do the 3 before it first.

Or start from the very first lesson, no account needed

Practice questions

Three quick questions from the lessons. Pick an answer to check it.

  1. Question 1 of 3With a pull-up, a pressed button reads…
    Show the answer

    Answer: LOW. Pressed, the button joins the pin to GND, 0 V. That beats the weak pull-up, so the pin reads LOW. Released, the spring wins and it reads HIGH again.

    • Why not “Both at once”? A pin reads one level at a time. The pressed button's direct path to GND wins over the weak pull-up, so it reads LOW.
    • Why not “HIGH”? HIGH is what the pin reads when the button is released and the pull-up lifts it. Pressed, the button joins it to GND, 0 V.
    • Why not “Nothing”? With a pull-up the pin is never left floating, so it always reads a definite level: LOW when pressed, HIGH when released.
  2. Question 2 of 3The pull-up's job is to…
    Show the answer

    Answer: Hold the pin HIGH while the button is released. A released button leaves the pin joined to nothing, and a pin joined to nothing reads at random. The pull-up is a weak spring that keeps it HIGH until a press pulls it LOW.

    • Why not “Slow the board down”? A pull-up doesn't change the board's speed. It only gives the input a definite level while the button is up.
    • Why not “Light the LED”? A pull-up only sets an input pin's level. Lighting an LED is a job for an output pin, with its own resistor.
    • Why not “Press the button for you”? A resistor can't move anything. It just holds the pin HIGH until a real press joins it to GND.
  3. Question 3 of 3The pin is set to plain INPUT, with no pull-up, and nobody presses the button. digitalRead gives…
    Show the answer

    Answer: HIGH and LOW at random. With the button up and no pull-up, the pin is joined to nothing. It floats, and picks up stray electric noise, so it reads HIGH, then LOW, at random.

    • Why not “Always HIGH”? Nothing holds the pin up. Without a pull-up it floats, so stray noise can make it read LOW as well as HIGH.
    • Why not “Always LOW”? Nothing joins the pin to GND either. A floating pin reads whatever stray charge pushes it to, so it changes at random.
    • Why not “1023”? 1023 is the top reading of analogRead. digitalRead only ever gives HIGH or LOW.
Keep practising: free lesson

“Press a button” is lesson 4 of 6 in Blink Bay, Embedded Systems World 1. Free with an account. Lessons unlock in order, so you’ll do the 3 before it first.

Questions people ask

Why does my Arduino button read random values?

The pin is floating. With the button released and no pull-up, the pin is joined to nothing, so stray electric noise pushes it around and it reads HIGH and LOW at random. Use pinMode(pin, INPUT_PULLUP), or fit a resistor from the pin to 5 V.

What does INPUT_PULLUP do?

It switches on a resistor inside the chip from the pin to 5 V, about 35 kΩ on an Arduino Uno (the datasheet allows 20–50 kΩ). That holds the pin HIGH until something stronger, like a pressed button to ground, pulls it LOW.

Why does a pressed button read LOW with a pull-up?

The button joins the pin straight to 0 V, which easily beats the weak pull-up, so the pin reads LOW. Released, the pull-up lifts it back to HIGH. This is called active-low: pressed means LOW.

What is the difference between a pull-up and a pull-down resistor?

A pull-up joins the pin to the supply, so it rests HIGH and a button to ground pulls it LOW. A pull-down joins the pin to ground, so it rests LOW and a button to the supply pulls it HIGH. The Uno and other classic AVR boards only have built-in pull-ups; some newer boards also offer INPUT_PULLDOWN.

Every topic