The floating pin
A pin your sketch has not set is not LOW. It is undriven, and its lamp 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 a 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. When the ATmega328P resets, its pins start as inputs, and an input takes almost no current, so almost nothing is enough to move it.
What the inverter sees
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, through both of the inverter's limits. The lamp flickers because the pin really is going HIGH and LOW.
Between those limits is a band where the inverter does not promise an answer. The SN74HC04 is a plain inverter with no hysteresis, so an input parked in that band can leave its output part-way, and the lamp glowing at part brightness. A chip with hysteresis, such as a 74HC14, would snap to one side. This board uses the 74HC04, and a half-lit lamp is the evidence.
The fix is one line per pin
Give every pin you use a definite state in setup():
pinMode(pin, OUTPUT)and adigitalWrite, for anything you drive.pinMode(pin, INPUT_PULLUP), for a button or switch to ground. The chip's own pull-up, 20 to 50 kohm, holds the pin HIGH until the button pulls it LOW.
The ATmega328P has no internal pull-down. A switch to 5 V needs a resistor to ground of your own.
Pins you do not use can be left floating. Their lamps will wander, and that is all they will do. A6 and A7 are the exception to the fix: they cannot be set, so only a wire to a rail or a source settles them.
D0 and D1 are not floating, they are busy
The first two lamps on the left, TXD and RXD, sit on D1 and D0. Those pins are
the Nano's USB serial line, the one the upload and Serial.print both use. So
their lamps blink while an upload runs and while the sketch prints, and that is
what a working serial line looks like. A sketch that wants to use them as
ordinary pins loses the serial line while it does, so the
chase sketch leaves them out.
When it does not work
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.
The pin has drifted to a voltage between LOW and HIGH, and the SN74HC04 behind the lamp is not required 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.
D0 and D1 are the Nano's USB serial line, and those two lamps follow it. They blink while an upload runs and whenever the sketch prints with Serial. That is the serial line's activity, not a floating pin.
The same floating pin, now in your sketch as well as on the lamp. 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.
Three Tools rows, the CH340 port, and a cable that carries data.
Set up the Arduino IDE →Edit this page — content/books/nano/the-floating-pin.mdx
Questions about this product
See what other owners have asked, and read their solutions.
This page covers several products. Choose yours to see the right 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.