Same LED on D9, plus a button on D2. Hold it down and the LED is on, let go and it is off. Up to now every pin was an output and I decided what happened. This is the first one where the world decides and I react.
Why INPUT_PULLUP works
The internal pull-up is a roughly 30 kΩ resistor on the silicon, between 5 V and the pin. What changes is whether current flows through it.
| Switch | Current | Drop across the pull-up | Pin sits at |
|---|---|---|---|
| Open | none | 0 × 30000 = 0 V | 5 V, HIGH |
| Closed | 5 / 30000 ≈ 0.17 mA | 0.00017 × 30000 = 5 V | 0 V, LOW |
So open is HIGH and closed is LOW. Active-low falls out of the circuit, it is not a property of buttons. A pull-down with the switch going to 5 V gives the opposite convention.
What I learned
- A bare input pin floats. No defined voltage, picks up noise, reading scrambles between HIGH and LOW. A rock solid constant reading means it is tied to something, not floating
INPUT_PULLUPcosts no parts. The resistor is inside the chipbool pressed = (digitalRead(PIN) == LOW)is the translation layer. Electrical on the right, human on the left==is an operator that produces a value. It is not owned byif. Watch=vs==, it sometimes compiles and just misbehaves quietly- 4-leg button has only 2 nodes. Each face's legs are joined inside. Use diagonal legs and orientation stops mattering. Wrong pair is a permanent short and the pin is stuck LOW forever
- Input pins measure and draw nothing, so 30 kΩ is fine. Output pins drive real current, so theirs has to be small. Same board, opposite rules
- Split the system before guessing. Input path and output path are independent, so pull the suspect part and halve the fault space
- Stuck is a measurement, not an absence. Constant
PRESSEDproved the pin was tied to ground, because floating would have scrambled - No output and output that never changes are different faults entirely
- Serial is an instrument, not a log.
printlnanddigitalWriteread the same variable, so it shows what the software thinks, separate from what the hardware did - Monitor baud must match
Serial.begin(9600). Opening the monitor resets the board. Never wire anything to D0 or D1, shared with USB - Schematics: supply at top, ground at bottom, signal left to right. LED triangle points at the bar, triangle is the anode. Every ground symbol is the same node
- A sketch runs whenever the board has power. No stop button. Unplug it or overwrite it with an empty sketch
delay(50)stops Serial flooding and hides bounce by accident. Both are the wrong fix