Floating input and pull-up lab
Read a button with no pull resistor and watch the value jump around as your hand moves near the wire, then add a pull-down and a pull-up and compare. It shows why every input needs a defined state.
Build it step by step
0 of 7 doneStep 1, floating
Push a bare jumper wire into D2, and leave the other end free.
Read the counts
In mode n the number jumps about as you wave your hand near the wire.
Step 2, pull-down
Add 10 kilohms from D2 to GND and a button from D2 to 5V.
Read the counts
Always 0 until you press, then 100.
Step 3, pull-up
Swap to 10 kilohms from D2 to 5V and the button from D2 to GND.
Read the counts
Always 100 until you press, then 0.
Step 4, built-in pull-up
Remove the resistor, send u, keep the button to GND: the same result.
How do you build a floating input and pull-up lab?
Read a button with no pull resistor and watch the value jump around as your hand moves near the wire, then add a pull-down and a pull-up and compare. It shows why every input needs a defined state. You need Arduino Nano, Tactile push button 6 mm, Resistor 10 kΩ × 2, LED 5 mm red, Resistor 220 Ω, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 40 minutes.
- Level
- Beginner
- Time
- About 40 min
- Parts
- 7
Parts list
- Development BoardsBuyArduino Nano × 1
- SwitchesBuy
- PassivesBuyResistor 10 kΩ × 2
- SemiconductorsBuyLED 5 mm red × 1
- PassivesBuyResistor 220 Ω × 1
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Test wire | Nano D2, other end loose or on the button | The input under test |
| Red LED long leg | Nano D6 through a 220 ohm resistor | Mirrors what the pin reads |
| Red LED short leg | Nano GND | Common ground |
| Pull-down resistor (step 2) | 10 kilohms from D2 to GND | Holds the pin low until the button pushes it high |
| Pull-up resistor (step 3) | 10 kilohms from D2 to 5V | Holds the pin high until the button pulls it low |
| Button | Between D2 and 5V (step 2) or D2 and GND (step 3) | Changes the level |
Code
A pin set as an input with nothing attached is floating. It picks up electrical noise from your hand, the mains wiring and the other wires, and it reads high or low at random, so the count of high readings in each hundred drifts about. A pull-down resistor to ground makes the pin read low until a button connects it to 5 V. A pull-up resistor to 5 V makes it read high until a button connects it to ground. The Nano also has a built-in pull-up that you switch on with INPUT_PULLUP, and that is the neatest choice for a button to ground. In the Serial Monitor at 9600 baud, send n for a plain input and u for the built-in pull-up and watch the counts change. The LED lights when most of the readings are high.
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 INPUT_PIN = 2;
const uint8_t LED_PIN = 6;
char mode = 'n'; // n = INPUT, u = INPUT_PULLUP; change it from the Serial Monitor
void setMode(char m) {
mode = m;
pinMode(INPUT_PIN, m == 'u' ? INPUT_PULLUP : INPUT);
Serial.print("Mode: ");
Serial.println(m == 'u' ? "INPUT_PULLUP (the chip's own pull-up)" : "INPUT (no pull resistor inside)");
}
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
Serial.println("Send n for INPUT or u for INPUT_PULLUP");
setMode('n');
}
void loop() {
if (Serial.available()) {
char c = Serial.read();
if (c == 'n' || c == 'u') setMode(c);
}
int highs = 0;
for (int i = 0; i < 100; i++) {
if (digitalRead(INPUT_PIN) == HIGH) highs++;
delay(2);
}
digitalWrite(LED_PIN, highs > 50);
Serial.print("HIGH ");
Serial.print(highs);
Serial.println(" of 100");
delay(300);
}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.
Send n for INPUT or u for INPUT_PULLUP Mode: INPUT (no pull resistor inside) HIGH 0 of 100
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Floating wire in mode n | Counts jump between low and high |
| 10 kilohm pull-down, no press | 0 of 100 |
| 10 kilohm pull-down, pressed | 100 of 100 |
| 10 kilohm pull-up, no press | 100 of 100 |
| Built-in pull-up with a button to GND | 100 until pressed, then 0 |
If it does not work
Counts never change
Check the wire is in D2 and the code is in the right mode.
Floating reading looks steady
Touch the wire with a finger, it picks up more noise.
LED always off
Check its direction and that the LED is on D6.
Pressed shows no change
Check which side of the button goes to 5V or GND.
Monitor shows nothing
Set 9600 baud.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the floating input and pull-up lab?
Arduino Nano, Tactile push button 6 mm, Resistor 10 kΩ × 2, LED 5 mm red, Resistor 220 Ω, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the floating input and pull-up lab take to build?
About 40 minutes for a beginner maker, in 7 steps.
How do I know the floating input and pull-up lab works?
Floating wire in mode n: Counts jump between low and high. 10 kilohm pull-down, no press: 0 of 100. 10 kilohm pull-down, pressed: 100 of 100.
Counts never change: what should I check?
Check the wire is in D2 and the code is in the right mode.
Floating reading looks steady: what should I check?
Touch the wire with a finger, it picks up more noise.
LED always off: what should I check?
Check its direction and that the LED is on D6.
Pressed shows no change: what should I check?
Check which side of the button goes to 5V or GND.
