মূল বিষয়বস্তুতে যান
Learn/Digital inputs/Buttons and pull-up resistors
Digital inputs · Lesson
12 min read

Buttons and pull-up resistors

Why an unconnected input 'floats', and how INPUT_PULLUP fixes it.

What You Will Learn

  • Explain a floating input
  • Wire a button with INPUT_PULLUP
  • Read inverted logic (pressed = LOW)

An input pin that isn't connected to anything is 'floating': it picks up electrical noise and reads random HIGH/LOW values. A pull-up resistor gently holds it HIGH until something stronger (a button to GND) pulls it LOW.

The Uno has built-in pull-up resistors (about 20–50 kΩ). pinMode(2, INPUT_PULLUP) turns one on — then wire the button between pin 2 and GND.

Arduino C++
pinMode(2, INPUT_PULLUP);
...
if (digitalRead(2) == LOW) {
  // pressed!
}
Button controls an LEDarduino-uno
Open in Lab
UNOATmega328P: The 8-bit AVR microcontroller that runs your sketch (16 MHz, 32 KB flash, 2 KB RAM).ATmega328PUSB-B: USB connection for uploading sketches and for the Serial Monitor. Also powers the board (5 V).DC jack: Barrel jack for 7–12 V from a battery pack or adapter (centre positive).ATmega16U2: Converts USB to serial for uploads and Serial.print().RESET: Restarts your sketch from the beginning (setup() runs again).L (D13): Built-in LED connected to pin 13 (LED_BUILTIN).ON: Power indicator.5 V regulator: Turns 7–12 V from VIN/jack into a steady 5 V.16 MHz: Clock source: the microcontroller runs 16 million cycles per second.ICSP: In-circuit programming header (SPI). Used to burn a bootloader; not needed for normal uploads.220 Ω+
Note: Press the button on the canvas (or hold it) and watch the LED and serial output. Then change INPUT_PULLUP to INPUT and see the floating warning.
On the ESP32, GPIO34–39 have no internal pull-ups. Use an external 10 kΩ resistor there.

Check Your Understanding

Test what you learned in this lesson

1With INPUT_PULLUP and a button to GND, what does digitalRead return while pressed?

2What is a floating input?