ohmio

Circuits / Microcontrollers

Arduino UNO: a button lights an LED

A pin as an input with the internal pull-up: it reads LOW while S1 is pressed, and the program decides the LED

Arduino UNO: a button lights an LED, simulated on a breadboard

Tap a part to see its voltages and currents. It is a model, not a measurement.

What do you need?

How does an Arduino read a button and light an LED?

Here the button and the LED are not wired to each other: the program connects them. pinMode(2, INPUT_PULLUP) makes pin 2 an input with an internal pull-up of about 35 kΩ to 5 V, so with S1 released the pin reads HIGH. Pressing S1 ties pin 2 to GND: it reads LOW, and only about 0.14 mA flows through the pull-up. Every 10 ms the loop reads the button and writes the result to pin 13, so the LED lights through R1 (220 Ω) while the button is pressed. Because the logic is in software, changing behavior means changing a line, not the wiring: you could make the LED toggle on each press, stay on for five seconds, or blink. The button only carries the tiny pull-up current; the LED's current comes from pin 13.

Values from the Protoboard ISO simulation: a model, not a bench measurement.