Observe an undefined input, then give it a default
The Story
digitalRead() reports HIGH or LOW from the voltage at an input. It does not report whether the wire is connected. A disconnected input can therefore look steady or change unexpectedly; neither result makes it a dependable switch input.
Watch the tutorial
Follow this guide’s wiring and GPIO assignments when building; the video may use different pins or a different board.
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 a normally open momentary button. No external resistor is needed for the After example on GPIO27.
- Expected result
- Before: an open INPUT has no guaranteed state, even if it appears steady. After: INPUT_PULLUP reads HIGH released and LOW when the button connects GPIO27 to GND.
Prerequisites
Why an open input can change
INPUT is high impedance: the pin draws very little current. Without a driven signal or pull resistor, leakage and charge on the wire can move its voltage. Nearby electric fields can couple into a loose lead, which is why moving your hand may change the reading.
Unconnected does not mean grounded. A floating pin might read HIGH, LOW, alternate, or remain at one value during this experiment. There is no required random pattern and no guaranteed LOW. digitalRead() returns a logic state, not an exact voltage measurement.
Wiring Diagram
Follow these steps in order. Unplug USB before you change any wires.
-
1
Before: unplug USB and connect one jumper to GPIO27. Leave its other end unconnected. The illustration shows this floating test lead.
-
2
Upload the Before sketch and set Serial Monitor to 115200 baud. Observe it; a steady value is also possible. Do not treat it as a reliable default.
-
3
With GPIO27 still configured as INPUT, briefly connect the lead to GND (LOW), then to 3.3 V (HIGH), one rail at a time. Keep away from 5 V and adjacent contacts; never join the two rails.
-
4
After: unplug USB. Connect a normally open button between GPIO27 and GND using contacts that only join when pressed. Remove the loose test lead.
-
5
Upload the After sketch, which enables INPUT_PULLUP. Released now reads HIGH; held pressed reads LOW. No external resistor is needed on GPIO27.
Wiring and matching Arduino code
Before: unconnected INPUT
One end of a jumper on GPIO27; the other end open. Upload this complete sketch by itself. This is a demonstration, not wiring to use in a finished project.
const int INPUT_PIN = 27;
int lastState = -1;
void setup() {
// Initialize Serial Monitor at 115200 baud
Serial.begin(115200);
// Configures GPIO 27 as a standard digital input (floating test)
pinMode(INPUT_PIN, INPUT);
}
void loop() {
// Sample the digital logic state on GPIO27; not an exact voltage
int currentState = digitalRead(INPUT_PIN);
// Print when the sampled logic level changes
if (currentState != lastState) {
if (currentState == HIGH) {
Serial.println("GPIO 27 reads HIGH");
} else {
Serial.println("GPIO 27 reads LOW");
}
// Save current state value
lastState = currentState;
}
// Sample every 50 ms; this does not stabilize an unconnected input
delay(50);
}
The supplied Before variant prints the initial sampled state and then only sampled changes, checking every 50 ms. Silence can mean the floating pin stayed at the same sampled state; it is not a guaranteed default. This is not a voltage measurement or edge-capture instrument.
After: button to GND with INPUT_PULLUP
Disconnect power before rewiring. GPIO27 → normally open button → GND. No connection from the button to 3.3 V; the internal resistor provides the pull-up. Upload this sketch by itself.
const int INPUT_PIN = 27;
void setup() {
Serial.begin(115200);
pinMode(INPUT_PIN, INPUT_PULLUP); // Button from GPIO27 to GND.
}
void loop() {
int state = digitalRead(INPUT_PIN);
Serial.println(state == LOW ? "LOW - PRESSED" : "HIGH - RELEASED");
delay(250);
}
The internal pull defines the released state after pinMode() runs. LOW means pressed in this wiring. The 250 ms print interval is not debouncing and can miss quick taps.
Supplied open GPIO27 experiment and sampled changes
Explore the build photos and recorded results. Open any image to inspect the details.
About this recorded build
Contributor-supplied photos and IDE captures, not an independent hardware retest. IDE captures show Arduino IDE 2.3.10 / ESP32 Dev Module; COM7 or COM8 belongs to that computer. Installed core and library versions were not supplied. Photographs cannot prove every hidden breadboard connection; trace the documented pins on your own parts.
One jumper is attached to GPIO27 and its other end is open. The supplied screenshot shows sampled HIGH/LOW changes. The main Before example now uses the same change-only reporting and 50 ms polling. An open input can also look steady; this experiment does not measure exact voltage or capture every electrical transition.
The original .ino and duplicate ZIP retain a contributor comment claiming Core v3.3.12. The installed core was not shown, so that comment is unverified and is not adopted as this guide’s software baseline. The displayed guide sketch omits that unsupported version/linker-fix claim. A 50 ms delay limits polling; it does not electrically stabilize a floating input.
No photo or Serial capture of the separate After/INPUT_PULLUP button experiment was supplied. That existing lesson remains clearly separate.

Contributor Before setup: a loose test lead, not a finished reliable input circuit. Keep the free end away from power and adjacent contacts.
View full-size image
Sampled changes from the contributor’s Before sketch, printed on changes only. This capture is not a universal expected pattern or a timing measurement.
View full-size imageExpected Behaviour
Before: GPIO 27 reads HIGH or GPIO 27 reads LOW prints for the first sample and then only when the sampled state changes. The contributor screenshot contains both states. Your open input may remain at one state; no random pattern is guaranteed. A 50 ms polling interval can miss short changes.
After: HIGH - RELEASED while the button is open, LOW - PRESSED while held closed, using the separate INPUT_PULLUP sketch. The supplied loose-wire photo and screenshot document Before only; no After capture was supplied.
ESP32 Internal Pull-up and Pull-down Resistors
INPUT_PULLUP supplies a weak internal path to HIGH after the pin is configured. The button overrides that path by connecting to GND. INPUT_PULLDOWN provides the opposite default on supported pins; its button would connect to 3.3 V. An external pull resistor works with INPUT instead.
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.
Troubleshooting
Most ESP32 problems are wiring, power, library, or timing issues. Check these first.
The floating test always reads HIGH or always LOW
Likely cause: The input can settle at one level, or the lead may accidentally touch a rail.
Fix: Check that the lead is open. Do not expect constant flipping. Compare its response when intentionally connected to GND and 3.3 V, then run the pull-up example.
After example still changes with the button untouched
Likely cause: Wrong sketch, unsupported pin, loose connection or an accidental short.
Fix: Confirm INPUT_PULLUP, GPIO27 and the button-to-GND wiring. Classic GPIO34–39 require external pulls.
After example always says PRESSED
Likely cause: GPIO27 is permanently connected to GND, often through the wrong pair of tactile-switch legs.
Fix: Disconnect power and identify contacts that only join on a press. Check breadboard rows and continuity.
A short tap is missed or a press produces chatter
Likely cause: Sampling occurs every 250 ms, and mechanical switches bounce.
Fix: Hold the button for this test. For event counting, use faster sampling and debouncing in the next lessons.
Serial output is absent or unreadable
Likely cause: Wrong port, baud rate, upload or USB cable.
Fix: Upload to the correct board port, use a data cable and set Serial Monitor to 115200 baud.
Knowledge Check
Quick check — no grades, just confidence!
Q1. An unconnected INPUT reads LOW for ten seconds. What can you conclude?
Q2. With INPUT_PULLUP and a button from GPIO27 to GND, what happens when held pressed?
Q3. What does digitalRead() tell you?
Mini Challenge
No wrong answers — experiment and have fun!
- Compare the open INPUT and released INPUT_PULLUP readings. Explain why only the second has a defined default, even if both happen to print HIGH.
- Continue to the pull-resistor guide to build an external pull-down and predict how its pressed state differs.
Next Mission
Continue Learning
Technical references
- Espressif Arduino-ESP32 GPIO API — INPUT, INPUT_PULLUP, INPUT_PULLDOWN and digitalRead().
- Espressif ESP32 GPIO restrictions — Classic ESP32 input-only pins and internal pull limitations.
- Espressif ESP32 Series datasheet — Electrical characteristics, typical internal pull resistance and boot strapping pins.
- Arduino-ESP32 3.3.2 release — Documentation-review baseline for the examples; no compilation or hardware test is claimed.

