Skip to content

ESP32 GPIO Input with Pull-Up Reads Wrong Values

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about ESP32 GPIO Input with Pull. We cover key concepts, practical examples, and best practices.

The Problem

ESP32 GPIO input with pull-up reads floating or incorrect values from a button or switch.

Quick Fix

Wrong

pinMode(4, INPUT);  // No pull-up, floating input
Serial.println(digitalRead(4)); // Random 0/1 values when button not pressed
pinMode(4, INPUT_PULLUP);
bool state = digitalRead(4);
if (state == LOW) {
  Serial.println("Button pressed");
} else {
  Serial.println("Button released");
}
// INPUT_PULLUP enables internal 45K pull-up resistor
Button released
Button pressed (when grounded)
Button released

Prevention

Always use INPUT_PULLUP or INPUT_PULLDOWN for floating inputs. Connect button between GPIO and GND (pull-up) or 3.3V (pull-down). Debounce in software or hardware. Read twice with delay to confirm state change.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### What is the internal pull-up resistor value?

ESP32 internal pull-up is approximately 45 kOhm. External pull-down is ~45 kOhm. Use external 10K resistor for stronger pull.

Can I use INPUT_PULLDOWN on ESP32?

ESP32 supports INPUT_PULLDOWN but the pull-down is weak (~45 kOhm). For reliable sensing, use an external 10K pulldown resistor.

Why do I get noise on input readings?

Floating inputs pick up electromagnetic noise. Always enable pull-up/pull-down. Use a 100nF capacitor to GND for debouncing.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro