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
Right
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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro