How a press becomes HIGH · 03 of 9

The pull-down

An input pin with nothing connected to it reads HIGH and LOW at random. The 10 kΩ resistor from SIGNAL to GND gives it something to read when the button is up: 0 V, LOW. Pressed, the switch overrules it and the pin reads HIGH.

A pin with nothing on it

An input pin measures a voltage and draws almost no current doing it. That is what makes it useful, and it is also the trouble. With the button up and no resistor, SIGNAL is joined to nothing at all. A pin in that state is called floating, and it reads whatever tiny charge happens to be on it: your hand nearby, the wire beside it, the last level it saw.

The pull-down
The 10 kΩ resistor
The button
SIGNAL
0 V
Reads
LOW
Through the resistor
0.00 mA
Released, nothing connects SIGNAL to VCC, and the 10 kΩ resistor ties it to ground. Nothing flows, so there is no voltage across the resistor, and SIGNAL sits at 0 V. The pin reads LOW, every time.

Set the figure to Taken off and Released. The pin's reading wanders between HIGH and LOW with nobody touching the button. A sketch reading it sees presses that never happened. The pattern in the figure is a picture of that behaviour, not a recording: a real floating pin can also sit on one level for minutes and then flip.

What the resistor does

The 10 kΩ resistor, R1 on the board, runs from SIGNAL to GND. With the button up, no current flows through it, so there is no voltage across it, and SIGNAL sits at exactly the same 0 V as ground. The pin reads LOW, every time.

Press, and the switch connects SIGNAL straight to VCC. The resistor is still there, but a switch contact is a fraction of an ohm against its 10 kΩ, so the switch wins outright. SIGNAL goes to VCC and the pin reads HIGH. The resistor now passes a small current, 0.5 mA from 5 V, and that is the whole price of it.

A resistor that holds a line at ground until something drives it is a pull-down. The same trick towards the supply is a pull-up.

Why this matters for your sketch

Two things follow, and every sketch in this book uses both.

  • pinMode(pin, INPUT), not INPUT_PULLUP. The block brings its own resistor. Adding the chip's internal pull-up as well sets the two against each other, and with the button up SIGNAL settles near a volt: neither a clean LOW nor a level you can rely on.
  • HIGH is pressed. A pull-up board is the mirror image, and its sketches treat LOW as the press. On this one, test for HIGH.

In MicroPython the same thing is Pin(pin, Pin.IN) with no pull argument.

When it does not work

Should I use INPUT_PULLUP?

No, use INPUT. The block already has its pull-down. Switching on the chip's internal pull-up as well puts two resistors in a tug of war on SIGNAL, and with the button up it settles somewhere around a volt: not a clean LOW, and not a level any datasheet promises to read the same way twice.

Does the pull-down waste power?

Only while the button is down. Released, there is no voltage across it and nothing flows. Pressed, it passes 0.5 mA from 5 V or 0.33 mA from 3.3 V, which is small next to the red LED on the same line.

Why 10 kΩ and not some other value?

It is strong enough to hold SIGNAL firmly at 0 V against the tiny currents that leak into an input, and weak enough that a press costs well under a milliamp. 4.7 kΩ or 47 kΩ would also work. 10 kΩ is the value most boards settle on.

Can I add my own pull-down resistor?

There is no need, and it changes nothing useful. A second resistor in parallel just lowers the total and raises the current a press costs. The one on the block is already doing the job.

Where this goes next

The red LED on SIGNAL, and why it is the first thing to look at when something is wrong.

The light on the board

Edit this page — content/books/push-button/the-pull-down.mdx

Community

Questions about this product

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

Ask a question ↗

Push Button

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