As an Amazon Associate we earn from qualifying purchases.
An internal pull-up is a resistor built into a microcontroller that connects an input pin to the supply voltage. You switch it on in software, so you don’t need to add an external resistor to your circuit. This article explains what it does, why it matters, and how to turn on pull-ups for the pins of an Arduino-style board.
What is an internal pull-up?
A digital input pin reads either a high or a low logic level. If nothing is connected to the pin, it is “floating”. It is not clearly high or low, and it can pick up electrical noise and give random readings.
A pull-up resistor fixes this by gently connecting the pin to the supply voltage. With nothing else driving the pin, it reads HIGH. When a button or switch connects the pin to ground, the pin reads LOW, because the resistor is weak enough to let the ground connection win.
Many microcontrollers include this resistor inside the chip. That is the internal pull-up. On the ATmega328P used in the Arduino Uno, the datasheet gives its value as tens of kilohms, so the pull is deliberately weak.
Why use an internal pull-up?
- Fewer parts: a push button can be wired straight from the pin to ground, with no external resistor.
- Simpler wiring: there are fewer connections to get wrong on a breadboard or PCB.
- Stable readings: the pin has a defined idle state instead of floating.
- Lower cost: across many inputs, the saved resistors add up in board space and assembly.
The trade-off is that the internal resistor is fairly high in value. For long wires, noisy environments, or fast signals, an external pull-up with a lower value may work better.
Enabling internal pull-ups on all pins
The sketch below sets every digital pin from 0 to 13 to logic high in setup(). On classic AVR-based Arduino boards, pins start as inputs. Writing HIGH to an input pin enables its internal pull-up resistor.
void setup()
{
int i=0;
for(i=0;i<14;i++)
{
digitalWrite(i, HIGH); //PULLS UP ALL PIN TO LOGIC HIGH
}
}
void loop() {
}
The loop runs through pins 0 to 13 and writes HIGH to each one. Because those pins are inputs at that point, the write turns on the pull-up instead of driving the pin high. The empty loop() is there because every Arduino sketch needs both functions, even when only one does any work.
A clearer way to write it
Relying on the default pin mode works, but it hides what the code is doing. Arduino provides the INPUT_PULLUP mode, which states the intent directly:
void setup() {
for (int i = 2; i < 14; i++) {
pinMode(i, INPUT_PULLUP); // input with internal pull-up enabled
}
}
void loop() {
}
This version starts at pin 2 instead of pin 0. On the Uno, pins 0 and 1 are also used for serial communication (RX and TX), so it is usually best to leave them alone if you use the Serial Monitor or upload over USB.
Reading a button with an internal pull-up
Here is a typical use. Connect one side of a push button to pin 2 and the other side to ground. Then read the pin:
void setup() {
pinMode(2, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
if (digitalRead(2) == LOW) { // button pressed
digitalWrite(LED_BUILTIN, HIGH);
} else {
digitalWrite(LED_BUILTIN, LOW);
}
}
The logic is inverted. The pin reads HIGH when the button is released and LOW when it is pressed. This surprises many beginners, but it is how pull-up inputs always behave.
Common mistakes
- Forgetting the inverted logic: a pressed button reads LOW, not HIGH.
- Using pull-ups on output pins: the pull-up only applies to pins configured as inputs. A pin set as an output is driven directly by the chip.
- Touching pins 0 and 1 on an Uno: this can interfere with serial communication and uploading.
- Expecting a strong pull: the internal resistor is weak. Where noise or long cables are a problem, add an external resistor.
- Assuming every board works the same way: some chips and boards handle
digitalWriteon inputs differently.INPUT_PULLUPis the safer choice where your board supports it.
Pull-up vs. pull-down
A pull-down resistor does the opposite job. It ties the pin to ground, so the pin reads LOW by default and HIGH when something connects it to the supply. Which one you choose depends on how the rest of your circuit is wired. Not every chip has both, so check the datasheet for your part.
If you work with Texas Instruments parts, the MSP430 supports both options on its port pins. You can read about internal pull-down resistors on that platform in a separate guide. For the register-level setup, see this MSP430 assembly language tutorial, which covers interrupts together with pull-up and pull-down configuration.
Frequently asked questions
What does an internal pull-up resistor do?
It connects an input pin to the supply voltage through a resistor inside the chip. The pin reads HIGH by default and goes LOW only when something, such as a button, pulls it to ground.
Do I still need an external resistor?
Often you don’t. For a simple button on a short wire, the internal pull-up is enough. For long cables, noisy surroundings, or special requirements, an external resistor may be more reliable.
What is the difference between digitalWrite(pin, HIGH) and INPUT_PULLUP?
On AVR-based Arduino boards, writing HIGH to an input pin enables the pull-up, which is what the original sketch relies on. pinMode(pin, INPUT_PULLUP) does the same thing in a clearer and more portable way.
Why does my button read LOW when pressed?
With a pull-up, the pin idles HIGH. Pressing the button connects it to ground, so the reading drops to LOW. Check for LOW in your code to detect a press.