Pull-up resistor
On this page
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.
See it
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?
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 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
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
- 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.
- Button pressed
The button joins the pin to ground. The pin is at 0 V and reads 0.
- 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
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
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?
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?
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.
- 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.
Discussion
No comments yet. Questions, results from your own build, a better way to explain it: all welcome.
My notes on this page
Kept on this device only. Nothing is sent anywhere.
Tip: select words in the lesson, or tap a figure or an equation, to put a note right there.
Notes on earlier wording
The lesson has changed and these words are no longer in it. Your notes are kept, with the words you chose.