Pull-down versus pull-up inputs
Wire one button with a pull-down resistor and a second with a pull-up and see that one reads high when pressed and the other reads low. A third button with no resistor at all reads random values, which makes the idea of a floating input clear.
Build it step by step
0 of 7 doneWire button A with its pull-down
D2 reads 0 until pressed.
Wire button B with its pull-up
D3 reads 1 until pressed.
Wire button C with no resistor
Leave D4 floating.
Upload and open the serial monitor at 9600
A table header appears.
Press A and B in turn
A reads 1, B reads 0, and the LEDs light.
Watch C with no press and bring a finger near
The reading wanders.
Switch D4 to INPUT_PULLUP and move C to GND
The reading becomes steady.
How do you build a pull-down versus pull-up inputs?
Wire one button with a pull-down resistor and a second with a pull-up and see that one reads high when pressed and the other reads low. A third button with no resistor at all reads random values, which makes the idea of a floating input clear. You need Arduino Nano, Tactile push button 6 mm × 3, Resistor 10 kΩ × 2, LED 5 mm red × 2, Resistor 220 Ω × 2, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 50 minutes.
- Level
- Beginner
- Time
- About 50 min
- Parts
- 7
Parts list
- Development BoardsBuyArduino Nano × 1
- SwitchesBuy
- PassivesBuyResistor 10 kΩ × 2
- SemiconductorsBuyLED 5 mm red × 2
- PassivesBuyResistor 220 Ω × 2
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Button A leg 1 | Nano 5V | Pull-down button: pressing sends 5 V to D2 |
| Button A leg 2 | Nano D2 and a 10 kilohm resistor to GND | The resistor holds D2 low when idle |
| Button B leg 1 | Nano GND | Pull-up button: pressing sends ground to D3 |
| Button B leg 2 | Nano D3 and a 10 kilohm resistor to 5V | The resistor holds D3 high when idle |
| Button C leg 1 | Nano 5V | Floating button: no resistor on the other side |
| Button C leg 2 | Nano D4 only | Nothing holds D4 when the button is open |
| LED 1 long leg | Nano D8 through a 220 ohm resistor, short leg to GND | Follows button A |
| LED 2 long leg | Nano D9 through a 220 ohm resistor, short leg to GND | Follows button B |
Code
A digital input that is connected to nothing is said to float, and it picks up stray electricity from the air and your fingers, so it reads high or low at random. A resistor of about 10 kilohms fixes that. A pull-down resistor to ground holds the pin low until a button joins it to 5 volts, so the pin reads 1 when pressed. A pull-up resistor to 5 volts holds it high until a button joins it to ground, so the pin reads 0 when pressed. Button C has neither, so D4 reads a jumble that changes if you bring a finger near the wire. The sketch prints all three values whenever any of them changes, and lights the two LEDs while A and B are pressed. Once you have seen the floating pin misbehave, change INPUT to INPUT_PULLUP for D4, move button C's first leg to GND, and see that the Nano's own built-in pull-up does the job without any resistor. Never join 5 volts to ground with a button and no resistor on a pin set as an output.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const uint8_t PULL_DOWN_PIN = 2; // button A, external pull-down
const uint8_t PULL_UP_PIN = 3; // button B, external pull-up
const uint8_t FLOAT_PIN = 4; // button C, no resistor at all
const uint8_t LED_A = 8;
const uint8_t LED_B = 9;
int lastA = -1, lastB = -1, lastC = -1;
void setup() {
pinMode(PULL_DOWN_PIN, INPUT);
pinMode(PULL_UP_PIN, INPUT);
pinMode(FLOAT_PIN, INPUT); // try INPUT_PULLUP here later and compare
pinMode(LED_A, OUTPUT);
pinMode(LED_B, OUTPUT);
Serial.begin(9600);
Serial.println("A (pull-down) B (pull-up) C (floating)");
}
void loop() {
int a = digitalRead(PULL_DOWN_PIN); // 0 idle, 1 pressed
int b = digitalRead(PULL_UP_PIN); // 1 idle, 0 pressed
int c = digitalRead(FLOAT_PIN); // random when idle
digitalWrite(LED_A, a); // lit while A is pressed
digitalWrite(LED_B, !b); // lit while B is pressed
if (a != lastA || b != lastB || c != lastC) {
lastA = a; lastB = b; lastC = c;
Serial.print(a); Serial.print(" ");
Serial.print(b); Serial.print(" ");
Serial.println(c);
}
delay(20);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
A (pull-down) B (pull-up) C (floating) 0 0 0
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| A idle and pressed | 0 then 1 |
| B idle and pressed | 1 then 0 |
| C open | Changes randomly, especially near a finger |
| C with INPUT_PULLUP and GND | Steady 1, then 0 when pressed |
| LEDs | Light only while their button is held |
If it does not work
A or B reads the wrong way
Check which side the resistor and the button go to.
Both LEDs stay dark
Check the LED direction and the 220 ohm resistors.
C looks steady
Hold a finger near the wire, or touch the metal lead.
Readings are always 1
Check the button is not stuck or wired across 5V and D4.
No serial text
Set 9600 baud.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the pull-down versus pull-up inputs?
Arduino Nano, Tactile push button 6 mm × 3, Resistor 10 kΩ × 2, LED 5 mm red × 2, Resistor 220 Ω × 2, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the pull-down versus pull-up inputs take to build?
About 50 minutes for a beginner maker, in 7 steps.
How do I know the pull-down versus pull-up inputs works?
A idle and pressed: 0 then 1. B idle and pressed: 1 then 0. C open: Changes randomly, especially near a finger.
A or B reads the wrong way: what should I check?
Check which side the resistor and the button go to.
Both LEDs stay dark: what should I check?
Check the LED direction and the 220 ohm resistors.
C looks steady: what should I check?
Hold a finger near the wire, or touch the metal lead.
Readings are always 1: what should I check?
Check the button is not stuck or wired across 5V and D4.
