Atlas Robotics
FundamentalsBasic

Pull-up and pull-down resistors: solving the problem of floating GPIO pins

Atlasbot · 20/8/2026 · 9 min read

Pull-up and pull-down resistors: solving the problem of floating GPIO pins
Pull-up pulls the foot to default HIGH, pull-down pulls it to default LOW

By wiring a push button to a GPIO pin with nothing else, the code reading digitalRead() can return a wildly varying value even if no one touches the button — this is almost always the result of a floating pin, and a pull-up/pull-down resistor is the standard solution.

Floating foot problem

When a GPIO pin is configured as INPUT but not firmly connected to HIGH or LOW (For example: one end of the push button is connected to the pin, the other end is connected to GND, but when not pressed, the pin "floats" without connecting anything) — this pin is very sensitive to environmental electromagnetic noise (the surrounding wires act as small noise-receiving antennas), causing digitalRead() to read a random value of 0 or 1 even though the physical state remains unchanged.

Pull-up resistor — default HIGH

Resistor pull-up connects the GPIO pin to the positive source (VCC) through a large value resistor (usually 4.7kΩ-10kΩ). When the button is not pressed, the pin is "pulled up" to a stable HIGH through this resistor. When presses button (the button connecting the pin to GND), the pin is pulled to LOW — the current through the resistor is now very small so it does not cause a short circuit.

VCC ──[ Pull-up resistor ]── GPIO pin ── Push button ── GND

Not pressed: pin = HIGH (pulled up through resistor)
Pressing: pin = LOW (connect straight to GND, overcome resistor)

Pull-down resistor — default LOW

Conversely, resistor pull-down connects the GPIO pin to GND. When button is not pressed, the pin is at a stable LOW level. When presses button (the button connecting the pin to VCC), the pin is pulled to HIGH.

GPIO pin ──[ Pull-down resistor ]── GND
GPIO pin ── Push button ── VCC

Not pressed: pin = LOW (pulled down through resistor)
Pressing: pin = HIGH (connect straight to VCC, overcome resistor)

Summary: Pull-up = default HIGH, press to LOW (logic "active-low"). Pull-down = default LOW, press to HIGH (logic "active-high"). Which type to choose depends on how the push button is connected to the source/GND.

Internal pull-up — no need for separate resistors

Most modern microcontrollers (Arduino, STM32, ESP32) have built-in pull-up resistors inside the chip, enabled by software — no need to solder additional resistors for simple uses such as reading a button push:

// Arduino — enable internal pull-ups using software
pinMode(2, INPUT_PULLUP);

void loop() {
  if (digitalRead(2) == LOW) {   // LOW means pressing (active-low logic of pull-up)
    // processed when the button is pressed
  }
}

Most microcontrollers do not have internal pull-downs as common as pull-ups (some models have, but fewer) — if pull-downs are needed, usually you still have to solder a separate resistor, or change the circuit to use an internal pull-up with active-low logic instead of active-high.

Technical details

Formulas

Apply Ohm's law (U = I×R, see Voltage/Current/Power) to calculate the current through the pull-up resistor while the button is being pressed — this is the "wasted" current flowing straight to GND, which needs to be small enough not to waste energy but large enough to prevent noise:

I = VCC / R

VD: VCC = 5V, R pull-up = 10kΩ
I = 5V / 10.000Ω = 0.5mA

The 0.5mA current is very small compared to the GPIO pin limit (20-40mA) — this is why pull-up/pull-down resistors always choose large values (kΩ), not small values like LED current-limiting resistors (usually only hundreds of Ω).

Parameters

Common pull-up/pull-down resistor values and corresponding current consumption at 5V power:

Resistance valueLine when activeReviews
1kΩ5mAToo small — wasted line, rarely used
4.7kΩ~1.06mAPopular, good anti-interference
10kΩ0.5mAMost popular, well balanced
1MΩ0.005mAToo large — easily overwhelmed by noise

Register / Bit / Byte

On the STM32, enabling internal pull-up/pull-down (instead of leaving pins floating or regular push-pull) is configured via register GPIOx_PUPDR (Pull-Up/Pull-Down Register) — which also uses 2 bits per pin like GPIOx_MODER: 00 = no pull, 01 = pull-up, 10 = pull-down, 11 = reserve (not used). The pinMode(pin, INPUT_PULLUP) function on the Arduino actually only sets these 2 bits to the value 01 for the corresponding pin.

Practical applications

The emergency stop button (E-stop) on AMR robots is almost always designed as active-low with pull-up — the default circuit reads HIGH (safe) when the wire is not broken, and only switches LOW when the button is actually pressed or the wire is broken/open circuit. This design is much safer than the active-high type: if the signal wire is broken due to vibration while the robot is moving, the leg will automatically return to the state of "considering the stop button pressed" instead of silently signaling "still safe" - the same pull-up/pull-down principle also applies to limit switches at many points on the robot's mechanical structure.

Practical example: complete push button circuit

const int BUTTON_PIN = 2;
const int LED_PIN = 13;

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);  // Uses internal pull-ups, no need for separate resistors
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  bool pressed = (digitalRead(BUTTON_PIN) == LOW);  // LOW = pressing
  digitalWrite(LED_PIN, pressed ? HIGH : LOW);
}

How to connect: one pin of the push button is connected to pin 2, the other pin is connected straight to GND — no need for a separate resistor because INPUT_PULLUP is used. This is the most popular way to connect push buttons in Arduino/ESP32 projects because it saves one component.

Common mistakes

  • Mistaken active-low logic when using pull-up — uses INPUT_PULLUP but the code checks == HIGH to detect button press — reverse logic, code will react when not presses the button instead of when pressed.
  • Ignore the resistor, leave the pin floating — the reading is haphazard, easily mistaken for a hardware or code error while the cause is just a lack of pull-up/pull-down.
  • Choosing an inappropriate resistor value — too small a resistor (eg 220Ω) when pressing a button will create an unnecessarily large short-circuit current through the resistor; Too large a resistor (e.g. 1MΩ) may not be strong enough to provide stable noise protection — around 4.7kΩ-10kΩ is common and safe for most situations.
  • Using internal pull-down on a chip that doesn't support it — calling the internal pull-down function/setup on a microcontroller with only internal pull-up (no internal pull-down) will not have the expected effect or give a compile error — check the datasheet before assuming the chip has both.

Conclusion

Pull-up/pull-down properly solves the "floating pin" problem — pulling the GPIO pin to a specified level when there is no active signal, avoiding random read noise. Prioritize internal pull-ups (INPUT_PULLUP) when possible to save on components — only need separate resistors when pull-downs are needed or the chip does not support internal pull-ups. The next article in this category is about Interrupts — how to handle events like button presses more efficiently than repeatedly reading digitalRead() in a loop.

Get new articles and lessons by email

When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.

Unsubscribe any time with the link in each email. See our Privacy policy.

Pull-up and pull-down resistors: solving the problem of floating GPIO pins — Atlas Robotics