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

logic={1Upin>UIH=2.31 V0Upin<UIL=0.99 Vholdbetween (Schmitt)τ=Rpu C=100 ns,Ipressed=3.3 VRpu=0.00 A\begin{aligned}\text{logic} &= \begin{cases}1 & \htmlClass{mv mv-v_pin}{\htmlStyle{font-size:1.00em}{\htmlData{sym=U_pin}{U_{\mathrm{pin}}}}} > \htmlData{sym=U_IH}{U_{\mathrm{IH}}}=2.31\,\htmlData{funit=V}{\text{V}}\\ 0 & \htmlData{sym=U_pin}{U_{\mathrm{pin}}} < \htmlData{sym=U_IL}{U_{\mathrm{IL}}}=0.99\,\htmlData{funit=V}{\text{V}}\\ \text{hold} & \text{between (Schmitt)}\end{cases}\\ \htmlData{sym=tau}{\tau }&= \htmlClass{mv mv-rpull}{\htmlStyle{font-size:1.02em}{\htmlData{sym=R_pu}{R_{\mathrm{pu}}}}}\, \htmlData{sym=C}{C} = \htmlData{funit=ns,v=1e-7}{\text{100 ns}},\quad \htmlData{sym=I_pressed}{I_{\mathrm{pressed}}} = \tfrac{3.3\,\htmlData{funit=V}{\text{V}}}{\htmlData{sym=R_pu}{R_{\mathrm{pu}}}} = \htmlData{funit=A,v=0}{\text{0.00 A}}\end{aligned}

Shown with this lesson’s starting values. In the simulation the numbers change as you move the sliders.

UpinU_{\mathrm{pin}}
Voltage on the input pin (V · volt)
UIHU_{\mathrm{IH}}
Input HIGH threshold (V · volt) : Above this a logic input reads 1. Datasheets usually write it V_IH.
UILU_{\mathrm{IL}}
Input LOW threshold (V · volt) : Below this a logic input reads 0. Datasheets usually write it V_IL.
τ\tau
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.
RpuR_{\mathrm{pu}}
Pull-up resistor (Ω · ohm)
CC
Capacitance (F · farad) : How much charge a capacitor stores per volt.
IpressedI_{\mathrm{pressed}}
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

Words used in this lesson

Parts in this lesson

All lessons · How components work · Glossary