If you’ve ever connected a push button to an Arduino and the pin kept flipping between HIGH and LOW on its own without you touching anything, the culprit was a floating pin. In this guide you’ll see what a pull-up or pull-down resistor is, which value to choose and how to fix the problem with a single line of code thanks to INPUT_PULLUP.
In short
- An input pin with nothing connected floats: it picks up noise and changes randomly.
- A pull-up holds it
HIGHat rest; a pull-down,LOW.- The typical value is 10 kΩ; I2C buses use lower values, such as 4.7 kΩ.
pinMode(pin, INPUT_PULLUP)enables the Arduino’s internal pull-up: you don’t need an external resistor, but the logic is inverted.
Why a pin “floats”
A pin configured as an input has extremely high impedance: it draws almost no current. That’s good for reading signals, but it has a side effect.

If the pin isn’t connected to either VCC or GND, its voltage is undefined. Anything can move it: the electric field of your hand, a nearby wire or the power line itself. The microcontroller then reads random values.
The typical case is a push button connected between the pin and 5 V:
- Pressed: the pin is at 5 V and reads
HIGH. Correct. - Released: the pin isn’t connected to anything and floats. It can read anything.
The solution is to give the pin a default state with a resistor.
Pull-up and pull-down: the two options

| Pull-up | Pull-down | |
|---|---|---|
| Resistor between | Pin and VCC | Pin and GND |
| Button between | Pin and GND | Pin and VCC |
| Reading at rest | HIGH | LOW |
| Reading when pressed | LOW | HIGH |
| Logic | Inverted (active low) | Direct (active high) |
| Built into Arduino AVR | Yes (INPUT_PULLUP) | No |
How a pull-up works
With the button released, the resistor “pulls” the pin up toward VCC. Since the input draws almost no current, hardly any voltage drops across the resistor and the pin sees practically 5 V.
When you press it, the pin is connected directly to GND. The resistor limits the current flowing from VCC to GND; without it, pressing the button would be a short circuit.
How a pull-down works
It’s the same principle in reverse: the resistor holds the pin at GND and the button brings it to VCC. It’s more intuitive (pressed = HIGH), but on an Arduino Uno it needs an external resistor.
Which value to choose
The resistor must be low enough to hold the pin firmly against noise, and high enough not to waste current when the button is closed.
The current with the button pressed comes from Ohm’s law, I = V / R:
| Resistor | Current at 5 V | Current at 3.3 V | Comment |
|---|---|---|---|
| 1 kΩ | 5 mA | 3.3 mA | Very firm, but draws quite a lot |
| 4.7 kΩ | ~1.1 mA | ~0.7 mA | Common on I2C buses |
| 10 kΩ | 0.5 mA | 0.33 mA | The default value for push buttons |
| 47 kΩ | ~0.1 mA | ~0.07 mA | Low power, more sensitive to noise |
| 100 kΩ or more | 0.05 mA | 0.03 mA | Only in battery projects with short wires |
Rules of thumb:
- Push buttons and switches: 10 kΩ.
- Long wires or noisy environments: go down to 4.7 kΩ or 2.2 kΩ.
- I2C bus: 4.7 kΩ is the most common value; many modules already have them soldered on. More details in I2C, SPI and UART.
- Battery projects: high values (47–100 kΩ) if the button may stay closed for a long time.
If you don’t know how to read a resistor’s value, check the resistor color code.
INPUT_PULLUP on Arduino
AVR microcontrollers (Uno, Nano, Mega) have an internal pull-up resistor on every digital pin. According to the Arduino documentation, on most AVR boards its value is between 20 kΩ and 50 kΩ.

You enable it like this:
pinMode(2, INPUT_PULLUP);
With that, you just connect the button between the pin and GND. No external resistors.
Example: a button that turns on the built-in LED
Wiring:
- One leg of the button to pin 2.
- The other leg to GND.
const int PULSADOR = 2;
const int LED = LED_BUILTIN;
void setup() {
pinMode(PULSADOR, INPUT_PULLUP);
pinMode(LED, OUTPUT);
}
void loop() {
// With pull-up, pressed = LOW
if (digitalRead(PULSADOR) == LOW) {
digitalWrite(LED, HIGH);
} else {
digitalWrite(LED, LOW);
}
}
Note the comparison with LOW: it’s the inverted logic typical of pull-ups.
Example: external pull-down
If you’d rather have pressed be HIGH:
- Button between pin 2 and 5 V.
- A 10 kΩ resistor between pin 2 and GND.
const int PULSADOR = 2;
void setup() {
pinMode(PULSADOR, INPUT);
Serial.begin(9600);
}
void loop() {
if (digitalRead(PULSADOR) == HIGH) {
Serial.println("Pressed");
}
delay(50);
}
Pull-up and pull-down on the ESP32
The ESP32 has internal pull-up and pull-down resistors on most of its pins:
pinMode(4, INPUT_PULLUP); // internal pull-up
pinMode(5, INPUT_PULLDOWN); // internal pull-down
Watch out for one important exception: according to Espressif’s documentation, pins GPIO34 to GPIO39 on the original ESP32 are input-only and have no internal pull-up or pull-down. If you connect a button there, you need an external resistor.
Also remember that the ESP32 runs at 3.3 V: the external pull-up must go to 3.3 V, never to 5 V.
Common mistakes
| Mistake | Symptom | Fix |
|---|---|---|
Button with no resistor and no INPUT_PULLUP | Random readings, the LED blinks on its own | Enable INPUT_PULLUP or add 10 kΩ |
Using INPUT_PULLUP and comparing with HIGH | Works backwards | With a pull-up, pressed is LOW |
Button between pin and VCC with INPUT_PULLUP | The pin always reads HIGH | With a pull-up, the button goes to GND |
| Internal pull-up on the Uno’s pin 13 | The pin sits at about 1.7 V | The onboard LED pulls the pin down; use another pin |
| Pull-up to 5 V on an ESP32 | Risk of damaging the pin | Always use 3.3 V |
| Reading several presses from a single tap | Mechanical bounce | Add a software delay (debounce) or a capacitor |
A note on bounce
A push button’s contacts bounce for a few milliseconds when they close, producing several rapid changes. Pull-up resistors don’t prevent it. The simplest fix is to ignore changes for 20–50 ms after detecting one, or to use a library such as Bounce2.
Frequently asked questions
Is the internal pull-up or an external one better?
For buttons with short wires, the internal one is enough and saves you components. With long wires or electrical noise, an external 4.7–10 kΩ resistor is more reliable because its value is lower and known.
Can I use a pull-up and a pull-down at the same time?
It makes no sense: they would form a voltage divider and the pin would sit at an intermediate voltage, which might read as neither HIGH nor LOW.
Do outputs need pull-ups too?
Normal outputs don’t, because they set their own level. Open-drain outputs (like the I2C bus) do need them, since they can only pull toward GND.



