Skip to content

6 min read

Connect a Push Button to Arduino Without a Resistor

A push button needs a defined voltage when it is not pressed. The Arduino can supply that definition internally, so one wire to a pin and one to ground are enough.

Push button wired between a digital Arduino pin and ground on a breadboard

At a glance

Why a bare button gives unreliable readings

A push button is a momentary switch: it connects two contacts only while you press it. If you connect one side to a digital pin and leave the other side unconnected, the pin is floating when the button is open. A floating input is not a logical HIGH or LOW. It picks up stray charge from your fingers and nearby wires, so digitalRead can flip between 0 and 1 without anyone touching the button.

The textbook fix is an external pull-down or pull-up resistor, typically 10 kilo-ohms, that holds the pin at a known level until the button overrides it. The Arduino already has a resistor of roughly 20 to 50 kilo-ohms inside the microcontroller. Enabling it removes one resistor and one wire from the project.

What INPUT_PULLUP actually does

pinMode(2, INPUT_PULLUP) connects an internal resistor from pin 2 to the supply voltage inside the chip. With the button released, that weak resistor pulls the pin HIGH. When you press the button you connect the pin directly to ground, which is a much stronger path, so the pin reads LOW. The resistor limits the current to a small, safe value while the button is closed.

This is why the logic is inverted: pressed means LOW and released means HIGH. Nothing is wrong with the code when this happens; it is the expected behaviour of a pull-up input.

Wiring with no external parts

Place the button so its two legs straddle the centre trench of the breadboard. Run one jumper from the first leg to digital pin 2. Run a second jumper from the other leg to any GND pin on the board. There is no connection to 5 V: the internal resistor handles that job. Check that the two legs are not in the same row, or the button will be shorted out and the pin will read LOW all the time.

Reading the button in code

Set the pin mode once in setup(), then read it in loop(). A compact test is: if (digitalRead(2) == LOW) { /* pressed */ }. Because the signal is inverted, compare against LOW to detect a press. If you prefer active-HIGH logic in the rest of your program, store bool pressed = !digitalRead(2); and use that variable everywhere. Keeping the inversion in one place prevents scattered mistakes.

If you drive an LED from the same sketch, remember that the LED still needs its own series resistor. The internal pull-up only affects the input; it does not limit current for an output.

Contact bounce and why it matters

Mechanical contacts do not close cleanly. For a few milliseconds the metal surfaces make and break contact several times, so one press can look like five. A counter that increments on every falling edge will jump by several steps. This is not a wiring error and no extra component is required to fix it.

Software debounce records the time of the last change with millis() and ignores further changes for 20 to 50 milliseconds. A steadier method samples the pin on a fixed schedule, updates a history variable only when the reading is stable for a few samples, and acts on the transition. Both approaches use only the pin you already wired.

When an external resistor is still the right choice

INPUT_PULLUP is convenient, but its value is only approximate and it is relatively weak. In a noisy environment, or with a very long cable, a smaller external resistor can give a cleaner signal. An external pull-down also lets a pressed button read HIGH, which some circuits need. Choose a value around 10 kilo-ohms: low enough to be stable, high enough not to waste current.

Never connect a button directly between 5 V and a pin with no resistance at all. When the button is closed, the pin would be tied to the supply with no current limiting, which is a condition the input was not designed for.

Frequently asked questions

Do I need a resistor for a push button on Arduino?

No. Use pinMode(pin, INPUT_PULLUP) and wire the button between that pin and GND. The microcontroller supplies an internal pull-up resistor.

Why does my button read HIGH when pressed?

A pull-up input reads HIGH when released and LOW when pressed. Compare against LOW, or invert the value once in your code.

Why does one press count several times?

Mechanical contact bounce makes the signal toggle for a few milliseconds. Ignore new changes for 20 to 50 ms using millis(), or require several stable samples.

Can I put the button on an analog pin?

Yes. Analog pins can be used as digital inputs with pinMode and digitalRead, so the same INPUT_PULLUP wiring works there.

Related pages