INPUT vs INPUT_PULLUP
Why a floating pin lies and how pull-ups fix it.
INPUT vs INPUT_PULLUP is a free Arduino & IoT Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Arduino & IoT Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Pins Can Listen Too
So far your pins pushed signals out. Now you'll make a pin listen instead, so your board can sense a button and react to it.
Set a Pin as INPUT
To read a button, you first tell a pin it should receive a signal. You do that by setting its mode to INPUT inside setup().
void setup() {
pinMode(2, INPUT);
}A Floating Pin Lies
An INPUT pin with nothing pulling it is called floating. It picks up stray noise and flickers between HIGH and LOW all on its own.
Why Floating Hurts
A floating pin gives you random, false button readings. Your code thinks the button is pressed when nobody touched it. ⚡
Pull Resistors Fix It
A pull resistor gently ties the pin to a known voltage. That gives it a steady default reading until the button changes it.
Pull-Up vs Pull-Down
A pull-up holds the pin HIGH by default; a pull-down holds it LOW. The Arduino has handy pull-ups built right into the chip.
Use INPUT_PULLUP
Skip the extra resistor: set the mode to INPUT_PULLUP and the board enables its internal pull-up for you automatically.
void setup() {
pinMode(2, INPUT_PULLUP);
}The Logic Flips
With INPUT_PULLUP the pin reads HIGH when the button is released, and LOW when it is pressed. The logic is inverted on purpose.
Wire to Ground
Because the internal pull-up holds the pin HIGH, you wire the button between the pin and GND. Pressing it pulls the pin down to LOW.
Less Wiring, Fewer Bugs
INPUT_PULLUP means one less resistor on your breadboard and no floating pin. For most beginner buttons it is simply the easiest choice.
Pick the Right Mode
Reach for plain INPUT only when your circuit already supplies its own pull resistor. Otherwise INPUT_PULLUP keeps things safe and simple.
Quick Check
Think about how INPUT_PULLUP behaves on an idle button.
Recap
You learned that an INPUT pin can float and lie, and that INPUT_PULLUP fixes it: HIGH when released, LOW when pressed. Next you'll actually read that value. 👍
Frequently asked questions
Is the “INPUT vs INPUT_PULLUP” lesson free?
Yes — the full text of “INPUT vs INPUT_PULLUP” is free to read here on the web, and the Arduino & IoT Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Arduino & IoT Academy course, upgrade to CoddyKit PRO.
What will I learn in “INPUT vs INPUT_PULLUP”?
Why a floating pin lies and how pull-ups fix it. You practise Arduino & IoT Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Arduino & IoT Academy?
No prior experience is required. Arduino & IoT Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “INPUT vs INPUT_PULLUP” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Arduino & IoT Academy lesson?
Yes. Every Arduino & IoT Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- INPUT vs INPUT_PULLUP
- Reading a Button State
- if/else: LED Follows the Button
- Wire a Button on a Breadboard