0% found this document useful (0 votes)
4 views1 page

Push Button

Uploaded by

dhinakarmkr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Push Button

Uploaded by

dhinakarmkr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

PUSH BUTTON BASICS: HOW THEY WORK WITH

MICROCONTROLLERS

DHINAKAR MURUGESAN
B.E.MECHATRONICS ENGINEERING

🔘 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
INTERNAL_PULLUP
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 connect an internal resistor between pin 2 and
buttons are often used with pull-up or pull-down resistors to define a
Vcc (5V) so that the pin stays HIGH unless
default logic state—HIGH when not pressed (pull-up) and LOW when not
pressed (pull-down). Pressing the button inverts this logic state, allowing something pulls it LOW
the microcontroller to detect user input reliably.
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.

You might also like