Pro Mini: Button and LED

by VladM

5 parts

A push button on D2 lights an LED on D12. The sketch sets D2 to INPUT_PULLUP, so the chip's own pull-up holds D2 at 5 V; the button pulls it to 0V, digitalRead returns LOW, and the sketch turns on D12 and the board's L LED. Click the button to press it and click it again to let go: this button stays where you leave it. The probes read D2 at 5.00 V released and 0V pressed, D12 at 4.77 V with the red LED lit, and 137µA through the pressed button: the pull-up's current, 5V over about 36.5kΩ (the ATmega328P data sheet's typical curve). The LED answers within a fraction of a millisecond: on this sheet the chip reads its inputs at least every 0.67 ms of circuit time, and one pass of loop() takes microseconds.