Skip to content
You Start with one site
Amounts in Start with one site
Microcontrollers · Concept

Pull-up resistor

One idea Beginner 5 min read
Found this useful?

A door with a spring closes by itself when nobody holds it. Without the spring it stays wherever the wind leaves it. An input pin needs the same help. A pull-up resistor connects the pin to the supply through a large resistance, so the pin reads high whenever nothing else is driving it.

It reads 1?Nothing is connecting it to the supply.No reason to be high
It reads 0?Nothing is connecting it to ground.No reason to be low
It floatsThe pin follows electrical noise from the air and from wires nearby.0 or 1, at random

See it

Predict first

A button is wired between an input pin and ground. There is no resistor anywhere. The button is not pressed. What does the program read on the pin?

See it: a button, a pin and one resistor

Voltage on the pin
The program reads
Current through the pull-up

With the resistor in place the pin always has a known level: 5 V when the button is released, 0 V when it is pressed. Current flows only while the button is pressed, and a larger resistor wastes less of it. With the resistor removed and the button released, the pin is connected to nothing.

The idea

An input pin draws almost no current, so it cannot set its own voltage. A pin that is connected to nothing is floating: its voltage follows any electrical noise nearby, and the program reads 0 or 1 at random.

The pull-up resistor gives the pin a level to rest at. While the button is open, no current flows through the resistor, so no voltage is lost across it and the pin sits at the full supply voltage. When the button closes, it connects the pin directly to ground, and the pin reads 0. The resistor then limits the current from the supply to ground:

I = Vsupply ÷ Rpull-up

I is the current while the button is pressed, in amperes

A small resistor wastes current on every press. A very large one, above about 100 kΩ, holds the pin so weakly that noise can still move it. 10 kΩ is a common choice. Most microcontrollers also have a pull-up inside the chip, of about 20 to 50 kΩ, which the program switches on.

One worked number

The question

A button connects a pin to ground. A 10 kΩ pull-up resistor connects the same pin to 5 V. What is the voltage on the pin with the button released and with it pressed, and what current flows while it is pressed?

Show the worked solution, 3 steps
  1. Button released

    No path to ground, so no current flows. The resistor loses 0 A × 10,000 Ω = 0 V. The pin is at 5 V and reads 1.

  2. Button pressed

    The button joins the pin to ground. The pin is at 0 V and reads 0.

  3. Current while pressed

    The whole 5 V is now across the resistor. I = 5 V ÷ 10,000 Ω = 0.0005 A, which is 0.5 mA. Press the button in the figure to check.

The mistake to avoid

With a pull-up, pressed does not read as 1. Released reads 1 and pressed reads 0. A program that starts a pump when the pin reads 1 will run the pump whenever nobody is touching the button. Test for 0 when you mean pressed.

The same resistor connected to ground is a pull-down. The button then connects the pin to the supply, and pressed reads 1.

Check yourself

Question 1

A sensor line has a 4.7 kΩ pull-up to 3.3 V. A device holds the line at 0 V. What current flows through the resistor?

Question 2

A start button is wired from a pin to ground, with a pull-up. The program starts a motor when the pin reads 1. What does the operator see?

Question 3

A door contact on a 2 m cable is wired from an input pin to ground, with no resistor. The log shows the door opening and closing many times a second whenever a nearby motor starts. What is the fix?

Where you meet it

  • Float switches and door contactsA switch at the end of a long cable needs a pull-up near the controller, often a smaller one than the chip has inside.
  • Sensors that share two wiresMany digital sensors share one pair of signal wires. Each device only pulls a wire low, and a pull-up on each wire returns it to high.
  • Pulse outputs of metersA water or energy meter often has an output that can only connect to ground. The pull-up supplies the high level between pulses.
Key points
  • An input connected to nothing floats, and reads 0 or 1 at random.
  • A pull-up resistor holds the pin high until something pulls it low.
  • With a pull-up, released reads 1 and pressed reads 0.
  • Current flows only while the pin is held low: supply voltage ÷ resistance.
Practice

Found this useful?

Discussion

    Comments show your name. Be kind, stay on the topic.