Interactive Mission

ESP32 Pull-up vs Pull-down Resistors

A pull-up holds an open input HIGH; a pull-down holds it LOW. Wire the button to the opposite rail: pull-up buttons read LOW when pressed, and pull-down buttons read HIGH. INPUT_PULLUP or INPUT_PULLDOWN supplies the resistor internally on supported GPIOs.

Mission 04FoundationBeginner20-25 minutesParent SafeTeacher Friendly
Pull Up Vs Pull Down Resistors guide illustration

Review, Testing, and References

Author: Abdul Mubeen and the ESP32 Engine editorial team. Last updated: 2026-11-04. Reviewed: educational accuracy and beginner safety. Level: Beginner. Estimated time: 20-25 min.

This guide is written for learning and bench prototyping. Check the testing notes before adapting the circuit to different boards, batteries, relays, motors, or outdoor hardware.

Jump to a section
Mission 04

Choose a default state for your button

The Story

An open switch disconnects the input from the switched rail. A pull resistor keeps that input at a defined voltage until the switch closes. The resistor also limits current when the switch connects to the opposite rail.

Watch the tutorial

Follow this guide’s wiring and GPIO assignments when building; the video may use different pins or a different board.

Open on YouTube

Before you start

Board
Classic ESP32-WROOM-32 DevKit with GPIO27 exposed; Arduino board selection: ESP32 Dev Module. Pin numbers are GPIO numbers, not header positions. ESP32-C3/S3 boards need their own pin map.
Software
Arduino IDE 2.x, esp32 by Espressif Systems 3.x (API review baseline 3.3.2). No extra libraries. Serial Monitor: 115200 baud.
Prerequisite
Upload a sketch and open Serial Monitor first. Know the board’s 3.3 V, GND and GPIO27 labels.
Parts
USB data cable, breadboard, jumper wires and normally open momentary button. The external pull example also needs one 10 kΩ resistor.
Expected result
External pull-down: RELEASED/LOW, PRESSED/HIGH. Internal pull-up: RELEASED/HIGH, PRESSED/LOW. Short mechanical bounce can still occur.

Prerequisites

Pull-up and pull-down wiring compared

GPIO27 with a normally open button; all supply connections are 3.3 V.
Setup / Arduino modeResistor and button wiringReleasedPressed
External pull-up / INPUT10 kΩ from GPIO27 to 3.3 V; button from GPIO27 to GNDHIGHLOW
External pull-down / INPUT10 kΩ from GPIO27 to GND; button from GPIO27 to 3.3 VLOWHIGH
Internal pull-up / INPUT_PULLUPNo external resistor; button from GPIO27 to GNDHIGHLOW
Internal pull-down / INPUT_PULLDOWNNo external resistor; button from GPIO27 to 3.3 VLOWHIGH

ESP32 Internal Pull-up and Pull-down Resistors

pinMode(pin, INPUT) leaves the digital input without an internal pull. INPUT_PULLUP enables a weak pull toward HIGH; INPUT_PULLDOWN enables one toward LOW. Use the wiring and pressed-state test from the comparison table. These modes do not debounce the switch.

Use GPIO27 for these examples. On classic ESP32, GPIO34–39 are input-only and have no internal pull-up or pull-down: use an external resistor there. Other ESP32 families have different restrictions.

Avoid boot-strapping pins GPIO0, GPIO2, GPIO5, GPIO12 and GPIO15 for this first button circuit: a button or resistor can change the boot configuration. GPIO6–11 are normally connected to flash. Check your board pin map before substituting a GPIO.

External Pull-Up and Pull-Down Resistors

Use INPUT with an external pull-up or pull-down so the physical resistor defines the default. External pulls let you choose a stronger pull and work on input-only pins without internal pulls. They also provide a default while the GPIO is not yet configured by setup().

A pull resistor biases an input; it does not convert a 5 V signal into safe ESP32 logic. Use 3.3 V rails in these circuits. A sensor that actively drives HIGH and LOW may need no pull, while an open-drain output needs the pull specified by its manufacturer.

What Value Pull-up Resistor Should I Use with ESP32?

For this short-wire, 3.3 V button exercise, start with 10 kΩ. With the button pressed, the resistor has approximately 3.3 V across it: 3.3 V / 10,000 Ω = 0.33 mA. This is a calculated value, not a measured result or a universal resistor recommendation.

The classic ESP32 datasheet lists about 45 kΩ as the typical internal pull resistance; actual resistance varies. A lower external resistance is a stronger pull but draws more current when pressed. A higher value is more vulnerable to leakage and interference. Long cables and other modules need their own electrical requirements checked.

Wiring Diagram

Follow these steps in order. Unplug USB before you change any wires.

Breadboard showing ESP32 GPIO27 connected to a push button with either a 10 kOhm pull-down resistor to GND or internal pull-up wiring to GND
  1. 1

    Unplug USB. Check the button contacts: the two legs on one side of a four-leg tactile switch are often already joined. Use contacts that are open until pressed; confirm your switch pinout or check continuity with power disconnected.

  2. 2

    Example A: connect GPIO27 to one button contact and 3.3 V to the opposite switched contact. Add 10 kΩ between the GPIO27 node and GND.

  3. 3

    Upload Example A and open Serial Monitor at 115200 baud. Released should read LOW; pressed should read HIGH.

  4. 4

    Unplug USB before changing to Example B. Remove both the 10 kΩ resistor and the button’s 3.3 V connection.

  5. 5

    Example B: connect the button between GPIO27 and GND. Upload Example B; its INPUT_PULLUP setting supplies the pull resistor.

  6. 6

    For external pull-up or internal pull-down, follow the comparison table. Never wire the button directly between 3.3 V and GND.

Wiring and matching Arduino code

Example A: external pull-down (pressed HIGH)

GPIO27 → button → 3.3 V. GPIO27 → 10 kΩ → GND. Upload this complete sketch by itself.

button_external_pulldown.ino
const int BUTTON_PIN = 27;

void setup() {
  Serial.begin(115200);
  pinMode(BUTTON_PIN, INPUT);
}

void loop() {
  bool pressed = digitalRead(BUTTON_PIN) == HIGH;
  Serial.println(pressed ? "PRESSED" : "RELEASED");
  delay(250);
}

For an external pull-up, move the resistor to 3.3 V and the button to GND; keep INPUT and change the pressed test to LOW.

Example B: internal pull-up (pressed LOW)

Unplug USB before rewiring. GPIO27 → button → GND. Remove the external resistor and the old 3.3 V button wire. Upload this complete sketch by itself.

button_internal_pullup.ino
const int BUTTON_PIN = 27;

void setup() {
  Serial.begin(115200);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
}

void loop() {
  bool pressed = digitalRead(BUTTON_PIN) == LOW;
  Serial.println(pressed ? "PRESSED" : "RELEASED");
  delay(250);
}

For internal pull-down on GPIO27, wire the button to 3.3 V, use INPUT_PULLDOWN and test for HIGH. The delay here spaces Serial output; it is not a debounce algorithm.

Supplied pull-down and pull-up wiring

Explore the build photos and recorded results. Open any image to inspect the details.

About this recorded build

Contributor-supplied build photos and Arduino captures. These records are not an independent hardware retest. Some breadboard contacts are hidden; follow the documented pin connections.

The photographs show physical pressed and released positions. Separate Serial Monitor captures of the two pull configurations were not supplied.

ESP32 button circuit with external resistor
Image 01

Supplied external-resistor button circuit for the pull-down example; some connections are obscured.

View full-size image
External-resistor button circuit with button released
Image 02

Released position in the supplied external-resistor build. No Serial state is visible in this photograph.

View full-size image
Finger pressing button in external-resistor circuit
Image 03

Pressed position in the same build; the finger obscures the switch contacts.

View full-size image
Labelled GPIO27 connection on ESP32
Image 04

Additional supplied GPIO27 closeup for the button examples.

View full-size image
Powered ESP32 with two-wire button circuit
Image 05

Supplied two-wire button build for the INPUT_PULLUP example: GPIO27 and GND. The board indicator is not a button-state result.

View full-size image

Expected Behaviour

At 115200 baud the sketch prints RELEASED until you hold the button, then PRESSED. The text is the same in both sketches because each uses the correct pressed polarity.

Example A’s raw input is LOW released and HIGH pressed. Example B’s raw input is HIGH released and LOW pressed. Brief chatter while pressing or releasing is contact bounce; learn debouncing next.

Troubleshooting

Most ESP32 problems are wiring, power, library, or timing issues. Check these first.

  • Always PRESSED or always RELEASED

    Likely cause: Button contacts are already joined, the pin number is wrong, or the input is connected to a rail.

    Fix: Disconnect power, check switched contact pairs and breadboard rows, then match GPIO27 and the chosen example.

  • States are inverted

    Likely cause: The pressed-state test does not match the wiring.

    Fix: Pull-up uses == LOW; pull-down uses == HIGH. Do not swap the rails while leaving the old condition in place.

  • Readings change while the button is untouched

    Likely cause: Missing pull resistor, unsupported internal pull, loose wiring or interference.

    Fix: Check the default path and common ground. Use short wires; classic GPIO34–39 need an external resistor.

  • Extra transitions during a press

    Likely cause: Mechanical contact bounce remains even with a pull resistor.

    Fix: Keep the pull and add debouncing when counting presses. A pull fixes floating, not bounce.

  • ESP32 will not boot after wiring

    Likely cause: A strapping pin is held at an unsuitable level or the supply is shorted.

    Fix: Unplug USB, remove the circuit, inspect for shorts and use GPIO27 for this exercise.

  • No readable Serial output

    Likely cause: Wrong port, baud rate or USB cable.

    Fix: Select the board’s port, set 115200 baud and use a data-capable USB cable.

Knowledge Check

Quick check — no grades, just confidence!

Q1. A button is wired from GPIO27 to GND with INPUT_PULLUP. What means pressed?

Q2. Can INPUT_PULLUP alone give classic ESP32 GPIO34 a default HIGH?

Q3. With a stable default but several counts per press, what is the next fix?

Mini Challenge

No wrong answers — experiment and have fun!

  • Build the alternate wiring from the table. Predict released and pressed readings before powering it, then update the pin mode and pressed test to match.
  • Explain why a pull resistor fixes a floating input but does not remove contact bounce.

FAQs

  • Why does INPUT_PULLUP read LOW when the button is pressed?

    With INPUT_PULLUP the pin normally rests HIGH through the internal resistor. Pressing the button connects the pin to GND, so the pressed state becomes LOW.

  • Does ESP32 have INPUT_PULLDOWN?

    Arduino ESP32 supports INPUT_PULLDOWN on GPIOs that provide an internal pull-down resistor. Pin capabilities vary by ESP32 family and board, and classic ESP32 GPIO34-GPIO39 do not have integrated pull-up or pull-down resistors.

  • What resistor value should I use for an external pull-up or pull-down?

    10 kΩ is the starting value for the short 3.3 V button circuit here. Choose other values from leakage, noise, wiring length and current requirements; it is not a rule for every module.

  • Can I use 5 V with an ESP32 button input?

    No. ESP32 GPIO pins are 3.3 V logic and are not 5 V tolerant. Use 3.3 V for button circuits connected to GPIO.

  • Do pull-up resistors debounce a button?

    No. Pull resistors stop floating. Debouncing handles the tiny rapid on/off transitions caused by the mechanical contacts inside a real button.

Next Mission

Continue Learning

Technical references