ESP32-S3 bases/Thirty-six lights/04. The floating pin
Thirty-six lights · 04 of 9

The floating pin

A pin your sketch has not set is not LOW. It is undriven, and its LED shows whatever it picks up — flickering under a fingertip, or glowing half-lit on its own. The back of the shield says so, and the fix is one line.

The sentence on the back

The underside of the shield carries one paragraph of advice, and it is the most useful thing printed on it:

By default, GPIO pins are in a floating state, so touching them with your finger can change their state and make the LED blink. To fix this, set the pinMode to output and specify HIGH or LOW.

"Floating" means nothing is holding the pin at any voltage. A GPIO that has not been set is an input with no pull resistor, and an input takes almost no current — so almost nothing is enough to move it.

What the inverter sees

What an undriven pin looks like to the inverter
no pinMode yet
What setup() has done to the pin
Your hand
Counts as HIGH above
about 2.4 V
Counts as LOW below
about 0.9 V
LED
half-lit
Left alone, the pin drifts, and can park in the middle. Between the two dashed lines the SN74HC04 does not promise to say HIGH or LOW, and this chip has no hysteresis to make it choose. An LED that glows dimly on a pin you never touched is this, not a fault.

Leave a pin alone and it drifts. Put a finger on it and it swings with the hum your body picks up from the wiring in the walls, fifty or sixty times a second, right through both the chip's LOW and HIGH limits. The LED flickers because the pin really is going HIGH and LOW.

Between those two limits is a band where the inverter does not promise an answer. The SN74HC04 on this board is a plain inverter with no hysteresis, so an input parked in that band can leave its output part-way, and the LED glowing at part brightness. A chip with hysteresis, such as a 74HC14, would snap to one side. This board uses the 74HC04, and the half-lit LED is the evidence.

The fix is one line per pin

Give every pin you use a definite state in setup():

  • pinMode(pin, OUTPUT) and a digitalWrite, for anything you drive.
  • pinMode(pin, INPUT_PULLUP), for a button or switch to ground. The chip's own pull-up holds the pin HIGH until the button pulls it LOW.
  • pinMode(pin, INPUT_PULLDOWN), for a switch to 3.3 V.

Pins you do not use can be left floating. Their LEDs will wander, and that is all they will do.

Before setup() runs

Every pin floats from the moment the board powers up until your sketch sets it — except six the ESP32-S3 holds itself. That is why a handful of LEDs are already steady while the rest shimmer, and it is the next page.

When it does not work

LEDs flicker when I touch the board or move my hand near it

Those pins are floating. Your body picks up hum from the mains wiring around it, and an undriven input picks that up from you. Set each pin you use with pinMode — OUTPUT and a digitalWrite, or INPUT_PULLUP — and the flicker stops on those rows.

An LED glows dimly on a pin nothing is connected to

The pin has drifted to a voltage between LOW and HIGH, and the SN74HC04 behind the LED does not have to decide which it is. Its output sits part-way and the LED lights part-way. It is harmless, and it goes away the moment the pin is driven or pulled.

A button on an input pin reads HIGH and LOW at random

The same floating pin, now in your sketch as well as on the LED. A button that only connects the pin to ground needs a pull-up to hold it HIGH the rest of the time: pinMode(pin, INPUT_PULLUP) turns on the one inside the chip.

Is a flickering LED doing any damage?

No. The ESP32-S3 input and the inverter input are both high-impedance, and neither is harmed by sitting at an in-between voltage. What it costs is a wrong reading if your sketch reads that pin, which is exactly what the LED is warning you about.

Where this goes next

Nine pins are busy before your sketch starts. Here is what their LEDs do.

Lights that move on their own

Edit this page — content/books/esp32s3-base/the-floating-pin.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

ESP32-S3 N16R8 PinPulse Shield, 36 GPIO LEDs

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum