push button/How a press becomes HIGH/04. The light on the board
How a press becomes HIGH · 04 of 9

The light on the board

A red LED and a 1 kΩ resistor sit on SIGNAL, so the LED lights whenever SIGNAL is HIGH: while the button is down, with no code involved. About 3 mA from 5 V, about 1.3 mA from 3.3 V, and a way to tell a wiring fault from a sketch fault at a glance.

Two paths to ground

The light on the board
VCC
The button
LED
about 3.00 mA
Pull-down
0.50 mA
From VCC
about 3.50 mA
Pressed, SIGNAL is at 5 V. About 3.00 mA goes through the 1 kΩ resistor and the LED, and 0.50 mA through the pull-down. The LED is bright enough to see across a desk.

With the button down, SIGNAL is at VCC and current has two ways back to ground. One is the 10 kΩ pull-down. The other is R3, 1 kΩ, and the red LED after it. Both paths only carry current while the button is down, so the LED is a direct picture of SIGNAL: lit is HIGH, dark is LOW.

The current for both comes from the block's VCC pin, through the switch. Your microcontroller's input pin supplies none of it.

How bright

The LED is red, and its exact part is not recorded, so the arithmetic below takes the typical drop of a red 0805 LED: about 2.0 V, somewhere between 1.8 and 2.2 V. It is worked out rather than measured, and the currents are approximate:

from 5 V:    (5.0 V - 2.0 V) / 1 kΩ = about 3 mA
from 3.3 V:  (3.3 V - 2.0 V) / 1 kΩ = about 1.3 mA

From 3.3 V the LED is a little dimmer. The reason is the same as for the TK01's blue LED, and why it is dimmer on 3.3 V works it through.

A test that needs no code

The LED lights from the wiring alone, so it splits every fault in two before you open the sketch:

  • Press and the LED lights. VCC, GND and the switch are fine, and SIGNAL went HIGH. If the sketch still sees nothing, the fault is between SIGNAL and your code: the pin number, or the SIGNAL wire.
  • Press and the LED stays dark. The block has no supply. Check VCC, then GND, then that the cable is not one pin over.

When a press does nothing starts from exactly this split.

When it does not work

The LED is dimmer on my ESP32.

Normal. A red LED takes about 2.0 V before it conducts, and 3.3 V leaves about 1.3 V for its 1 kΩ resistor: roughly 1.3 mA. On a 5 V Uno the same LED gets about 3 mA and is plainly brighter.

Does the LED load my microcontroller's pin?

No. The LED's current comes from VCC, through the switch, not from your pin. Your pin is an input: it only measures the voltage on SIGNAL and supplies nothing. The block's current comes out of your board's 3V3 or 5V pin.

Can I turn the LED off?

Not from code. It is wired to SIGNAL, so it lights whenever the button is down and VCC is connected. That is the point of it: it shows the hardware is working even when the sketch is not.

Does the LED change what my pin reads?

No. Pressed, the switch holds SIGNAL at VCC whatever the LED draws. Released, the LED passes nothing at 0 V, so it cannot lift SIGNAL off LOW. The pull-down alone decides the released level.

Where this goes next

Three wires and a sketch that prints what the pin says.

The first read

Edit this page — content/books/push-button/the-light-on-the-board.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