TactivergeLite

Lite / Building Machines That Respond / Week 20

Pull-ups: giving a button a resting voltage

A button only connects two wires. So why does every microcontroller button also need a resistor?

About 30 min · 3 goals · Checked by automated tests · Full interactive version

Why should I care?

Floating inputs cause some of the strangest bugs in electronics: a machine that switches on when you wave your hand near it. A single resistor fixes it, and choosing its value is your first real electrical design trade-off.

Predict

A pin has a resistor to 3.3 V, and a button from the pin to 0 V. What does the pin read when the button is NOT pressed?

  1. 0
  2. 1
  3. It floats
Guess first, then reveal

The resistor gently pulls the pin up to 3.3 V, so it reads 1. Press the button and it connects the pin firmly to 0 V, so it reads 0. Pressed = 0 is called **active low**.

Discover

Build a voltage divider: R1 is the pull-up (10 kΩ). For R2, try a very small resistance (a pressed button) and then a very large one (an open button plus the pin's huge input resistance). Watch where Vout goes each time.

What the interactive shows (text version)

In the circuits lab, a voltage divider has R1 (the pull-up) on top and R2 (the button) underneath, with Vout = Vin × R2 ÷ (R1 + R2). A tiny R2 (pressed button) gives Vout near 0 V; a huge R2 (open button) gives Vout near Vin. That is why a pull-up input reads 1 when released and 0 when pressed.

You can also open the interactive on the full site when you have a faster connection.

Understand

The pull-up idea

A pull-up resistor connects the input to the supply. With the button open, almost no current flows (the pin barely draws any), so there is almost no voltage across the resistor and the pin sits at the supply: reads 1. Pressing the button connects the pin straight to 0 V: reads 0. The resistor stops that press from being a short circuit.

It is a voltage divider

Treat the pull-up as R1 and the button as R2 in a divider: Vout = Vin × R2 ÷ (R1 + R2). Open button: R2 is enormous, so Vout ≈ Vin. Pressed: R2 ≈ 0, so Vout ≈ 0 V. A pull-down is the mirror image: resistor to 0 V, button to the supply, so pressed = 1.

Strong or weak?

While pressed, the pull-up carries I = V ÷ R. A 10 kΩ pull-up at 3.3 V wastes 0.33 mA; a 1 kΩ one wastes 3.3 mA, which matters on a battery. But a very weak pull-up (say 1 MΩ) is easily disturbed by noise and long wires. Typical choices sit between about 4.7 kΩ and 47 kΩ, and many chips have a built-in pull-up you can switch on.

Explain it another way

Intuitive

A pull-up is a gentle spring holding a gate shut. The button is your hand pushing it open: much stronger than the spring, so you win, but the spring always returns it to a known position.

Technical

Internal pull-ups are typically tens of kilohms. In active-low logic, firmware tests if read(pin) == 0: for 'pressed'. Long cables add capacitance, so stronger pull-ups give faster, cleaner edges at the cost of current.

Mathematical

Pressed: I = V ÷ R. Open: V_pin = V × R_in ÷ (R + R_in), where R_in (often > 1 MΩ) ≫ R, so V_pin ≈ V. Power wasted while pressed: P = V² ÷ R.

Applied

Keyboard matrices, car-door switches and the reset button on most boards use pull-ups. Engineers prefer active low partly because a broken wire then reads 'not pressed' rather than 'pressed'.

Worked example 1

A 5 V system uses a 4.7 kΩ pull-up. How much current flows while the button is held, and how much power is wasted?

I = 5 V ÷ 4.7 kΩ ≈ 1.06 mA. P = V × I = 5 × 0.00106 ≈ 5.3 mW. Tiny, but on a coin cell it adds up if the button is held for hours.

Common mix-ups

Practice

Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.

Practice 1. With a pull-up and a button to 0 V, which line of code means 'button pressed'?

mA

mA

Practice 4. A pull-down resistor connects the pin to 0 V and the button connects it to 3.3 V. What does a press read?
Practice 5. Why not use a 10 MΩ pull-up to save even more current?

Apply it

A battery-powered doorbell button may be held for a long time by a child. Compare 1 kΩ, 10 kΩ and 100 kΩ pull-ups at 3.3 V: current while held, and how robust each is to noise on a 5 m cable. Recommend one in two sentences.

Reflect

Why do you think engineers often prefer that a broken wire reads 'not pressed'?

Write your answer on paper or in your own notes. Lite never stores what you write.

← Pins: high, low and in betweenDebouncing: one press, one count →