PUSH BUTTON BASICS: HOW THEY WORK WITH
MICROCONTROLLERS
🔘 WHAT IS A PUSH BUTTON?
A push button is a momentary switch commonly used in embedded
systems to make or break an electrical connection when pressed. It
typically comes in two types: Normally Open (NO), where no current
flows until pressed, and Normally Closed (NC), where current flows until
pressed. Push buttons are low-power components, usually rated for 3.3V
or 5V, and they require debouncing either through software or hardware
to avoid signal noise. When connected to a microcontroller, push
buttons are often used with pull-up or pull-down resistors to define a
INTERNAL_PULLUP
connect an internal resistor between pin 2 and
default logic state—HIGH when not pressed (pull-up) and LOW when not
pressed (pull-down). Pressing the button inverts this logic state, allowing Vcc (5V) so that the pin stays HIGH unless
the microcontroller to detect user input reliably. something pulls it LOW
BUTTON IS NOT PRESSED
The circuit from pin to GND is open.
So pin is pulled up to Vcc through the
internal resistor.
const int ledPin = 13;
const int buttonPin = 2;
void setup() { BUTTON IS PRESSED
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP); // Enable internal pull-up resistor Button connects pin directly to GND.
} Now, current flows from Vcc → internal
resistor → pin → button → GND.
void loop() { Pin sees 0V, so digitalRead(2) returns LOW.
int buttonState = digitalRead(buttonPin);
if (buttonState == LOW) { // Button pressed (pin reads LOW)
digitalWrite(ledPin, HIGH); // Turn LED ON
} else {
digitalWrite(ledPin, LOW); // Turn LED OFF
}
}
HOW TO CALCULATE A PULL-UP RESISTOR VALUE
Let’s say you want to limit the current through the pull-up resistor to approximately 1mA when the
button is pressed.
GIVEN:
Vcc = 5V
Target current = 1mA = 0.001A
We can use Ohm’s Law to find the required resistor value:
V=I×R
Rearranging to solve for resistance:
R=V/I
Substitute the values:
R=5/0.001A
=5000 ohm
APPLICATION
Pull-up resistors are commonly used in microcontroller circuits (like Arduino) to ensure that a digital
input pin reads a stable and defined logic level when no active signal is connected.
🛠 Example: Detecting the state of a push button, where the pin should read HIGH when idle and
LOW when the button is pressed.