Lesson 4.1 · Module 4: Digital Hardware & Embedded Protocols
Pull-Up Resistors & Button Debounce Explained
How a microcontroller reads a push button. A bare input pin “floats” and reads random noise, and real buttons bounce.
The live, interactive simulation for this lesson opens here when JavaScript is on.
Key ideas
- An unconnected input pin picks up noise and flickers between HIGH and LOW.
- A pull-up resistor gives the pin a definite default level that the button can override.
- A small capacitor smooths the button’s bounce, so one press gives one clean edge.
Try this in the simulation
- With no pull resistor, watch the input lamp flicker (Hi-Z).
- Select pull-up, then hold the button down in the drawing.
- Add the debounce capacitor and count the edges per press.
Why does a microcontroller input need a pull-up resistor?
An input pin that is connected to nothing is “floating”: it picks up stray noise and reads random highs and lows. A pull-up (or pull-down) resistor gives the pin a definite default level that a button can override. Real buttons also bounce, making several quick contacts for one press, and a small resistor-capacitor filter smooths them into one clean edge.
What you’ll learn
- What a floating input is and why it reads random values.
- How to choose between a pull-up and a pull-down resistor, and how big it should be.
- What contact bounce looks like and how many edges one press can make.
- How an RC filter debounces a button.
The formula, letter by letter
Shown with this lesson’s starting values. In the simulation the numbers change as you move the sliders.
- Voltage on the input pin (V · volt)
- Input HIGH threshold (V · volt) : Above this a logic input reads 1. Datasheets usually write it V_IH.
- Input LOW threshold (V · volt) : Below this a logic input reads 0. Datasheets usually write it V_IL.
- Time constant τ (tau) (s · second) : How long an RC or RL circuit takes to get 63 % of the way to its final value. After 5τ it is basically done.
- Pull-up resistor (Ω · ohm)
- Capacitance (F · farad) : How much charge a capacitor stores per volt.
- Current when the button is pressed (A · ampere)
Common questions
What is a pull-up resistor?
A resistor, often 10 kΩ, connected between an input pin and the supply voltage. It holds the pin high until something, like a button to ground, pulls it low.
Do I need an external pull-up if my microcontroller has an internal one?
Often not. Many microcontrollers have built-in pull-ups you can switch on in software. An external one can be better when you need a stronger or more precisely known value.
What is button debouncing?
Making a mechanical button look like a single clean press. You can do it in software by ignoring changes for a few milliseconds, or in hardware with a resistor and a small capacitor.
Keep going
- Next lesson: 4.2 Open-Drain vs Push-Pull Outputs (I2C Pull-Ups)
- Related components: Switch & push button, Capacitor, Resistor