latching button/Why on reads HIGH/03. The pull-down and the light
Why on reads HIGH · 03 of 9

The pull-down and the light

A 10 kΩ resistor from SIGNAL to GND holds the pin at 0 V while the switch is open, so off reads LOW. Closing the switch lifts SIGNAL to VCC, so on reads HIGH, and the red LED on the same wire lights with it.

Three things on one wire

The pull-down and the light
Switch
VCC wired to
SIGNAL
5.0 V · HIGH
LED
3.0 mA
Block takes
3.5 mA
On. The switch connects SIGNAL to VCC, so SIGNAL is 5.0 V and reads HIGH. About 0.5 mA goes down the pull-down and about 3.0 mA through the LED. Your board's input takes almost nothing: it only looks at the voltage.

Try the switch both ways, then set VCC to Nothing. The whole board is in that drawing. VCC goes to one side of the switch. The other side is SIGNAL, and SIGNAL goes three places: to your board's input, to GND through a 10 kΩ resistor, and to GND through the red LED and a 1 kΩ resistor.

Why it needs a pull-down

An input pin only looks at a voltage. It takes almost no current, so a pin connected to nothing has nothing to set its voltage, and it drifts. It picks up whatever is nearby, a hand, a mains cable, the wire next to it, and reads HIGH and LOW at random. That is called floating.

With the switch open, SIGNAL would float. The 10 kΩ resistor to GND stops it: it is the only thing connected, so it pulls SIGNAL to 0 V, and the pin reads LOW. A resistor that holds a line at 0 V like this is a pull-down.

When the switch closes, it connects SIGNAL straight to VCC. The switch wins easily, because a closed contact is a fraction of an ohm and the pull-down is 10,000. SIGNAL goes to VCC and reads HIGH. The pull-down now carries a small, steady current, 0.5 mA from 5 V, which is its price.

So on is HIGH and off is LOW. The silkscreen says ACTIVE HIGH for that reason, and your sketch sets the pin as a plain INPUT. There is no pull-up on this board. A block with a pull-up and the switch to GND would read the other way round, and some do; this one does not.

The light belongs to the switch

The LED's anode is on SIGNAL and its cathode goes to GND through 1 kΩ. It lights whenever SIGNAL is HIGH, which is whenever the switch is on. It is not connected to anything your sketch controls. That makes it a reliable way to see the switch's position, and a useless way to see whether your sketch noticed.

The LED is red, and its exact part is not recorded. A red 0805 LED drops about 2.0 V at these small currents, somewhere between 1.8 and 2.2 V, and the resistor sets what it gets:

VCCSIGNAL when onLEDPull-downWhole block
5 V5 Vabout 3 mA0.5 mAabout 3.5 mA
3.3 V3.3 Vabout 1.3 mA0.3 mAabout 1.6 mA

These are worked out, not measured. From 3.3 V the LED is a little dimmer; the XL LED book works through why a 3.3 V supply leaves an LED less. With the switch off, the whole block takes nothing at all.

What it costs to get wrong

Set the pin as an output and the switch becomes a short. With the switch on, SIGNAL is VCC, and a pin driving LOW against it has only its own driver to limit the current. That is how a pin dies. This block is read, never driven.

When it does not work

Should I use INPUT_PULLUP?

No. Use INPUT. The board already has a pull-down, and an internal pull-up fights it: with the switch off, the pin sits at whatever the two resistors divide the supply to, instead of at 0 V. It usually still reads LOW, with less margin, and it buys nothing.

The LED lights, but my sketch does nothing.

The LED is wired to SIGNAL on the block, not to your sketch, so a lit LED only proves that VCC arrived and the switch is on. Check that SIGNAL goes to the pin the sketch reads, and that the pin number is the GPIO number printed beside it.

Can I make it an OUTPUT to light the LED from code?

No, and do not try. With the switch on, SIGNAL is connected straight to VCC. A pin set as an output and driven LOW would then be shorted to the supply through the switch, with nothing to limit the current. Only ever read this pin.

Does it use power when it is off?

No. VCC is connected to nothing on the board but the switch, so with the switch open no current flows at all. With it on, the block takes about 3.5 mA from 5 V and about 1.6 mA from 3.3 V: the LED and the pull-down between them.

Where this goes next

SIGNAL is VCC when the switch is on, so VCC is chosen by your board.

Which supply to use

Edit this page — content/books/latching-button/the-pull-down-and-the-light.mdx

Community

Questions about this product

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

Ask a question ↗

Latching 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