Learn

Why an input needs a pull-up, not just a switch

Sign up freeor see every lesson
  • 192parts on the bench
  • 25boards running now
  • 1.00xreal time, on every board
Pull-up resistorlive0.000 s 0.00x
Hold the button
A 10 kilohm pull-up, a button, and a NOT gate lighting an LED while it is held.

A pushbutton, on its own, can only ever make a connection. It cannot break one that was not there, and it certainly cannot decide what a wire reads when nobody is touching it. Wire one side of a button to a digital input and the other to ground, with nothing else on that net, and the moment the button is released the input is floating: not driven high, not driven low, sitting at whatever charge happened to be left on it. On a CMOS input, which draws almost no current either way, that leftover charge can sit there for a surprisingly long time, and it can read as a 1 or a 0 more or less at random.

The pull-up resistor fixes this by giving the net somewhere to go when the button is not pressed. In the circuit above, a 10 kilohm resistor runs from 5 V to the same net the button pulls to ground. With the button released, the resistor is the only thing driving the net, so it sits at 5 V: a clean, real, logic high. Press the button and it connects the net straight to ground, which easily overpowers the resistor's weak pull, so the net drops to a clean 0 V. Release it and the resistor pulls it back up. Nothing is ever left undriven.

Ten kilohm is a deliberate choice, not a rule. It has to be small enough that the net returns to 5 V quickly and firmly, and large enough that pressing the button does not waste a meaningful amount of current pulling it to ground: 5 V across 10 kilohm is half a milliamp, small next to almost anything else on the board and easily large enough to define the voltage. The NOT gate on the right turns the released-high, pressed-low signal into a lit LED exactly while the button is held, which is the usual way to make the logic read the way a person expects without loading down the sense net the way wiring an LED to it directly would.

Every board Mokxi models has the same resistor built in and switchable in firmware. The Uno's `INPUT_PULLUP` mode turns on an internal 35 kilohm pull-up inside the ATmega328P itself, and the ESP32-C3 and the other boards offer the same idea on their own pads. That is why the shipped `button` sketches read the pin as low when it is pressed: the internal resistor already does the job the external one does here, just weaker and with one less part on the breadboard. The external version above is what is actually happening underneath either way, made visible.

Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.