Set pinMode before you write, and use INPUT_PULLUP when you want the pull-up.
What the message means
On AVR boards digitalWrite(pin, HIGH) on a pin set as INPUT enables the internal pull-up. Mixed up with pin changes this gives odd readings.
Fix it in this order
- Set pinMode for every pin in setup().
- Use INPUT_PULLUP for a button to ground, and INPUT only when you wire an external resistor.
- Do not call digitalWrite on a pin you use as an input.
- Remember an input pin reads high with the pull-up and low when pressed.
- Check a pin is not shared with another function.
Why it happens
On AVR boards such as the Uno, writing HIGH to a pin set as an input switches on its internal pull-up resistor, which is tens of kilohms. This is old behaviour that the INPUT_PULLUP mode now states openly. A sketch that writes to a pin and later makes it an input can leave the pull-up on without you noticing, so the pin reads HIGH with nothing connected.
A button wired between the pin and ground with INPUT_PULLUP reads HIGH when open and LOW when pressed, which is the reverse of what many beginners expect.
If you see this, do this
| You see | Do this |
|---|---|
| Input reads HIGH with nothing connected | Pull-up on. |
| Pin does not drive an LED | It is still an input. |
Related
floating input and pull-up, unconnected analog pin.
Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.
Why this happens
On the ATmega328P, as used on the Uno and Nano, each pin has an output register bit and a direction bit. When the pin is an INPUT, writing HIGH to the output register does not drive the pin, but it switches on the internal pull-up resistor, which the datasheet gives as roughly 20 kΩ to 50 kΩ. That is why old sketches used digitalWrite(pin, HIGH) after pinMode(pin, INPUT) to get a pull-up. INPUT_PULLUP does the same thing in a clear way.
The side effect appears when you change direction later. If a pin was set HIGH while an output and you then make it an INPUT, the pull-up is left on and a floating pin reads HIGH. In the other direction, a pin whose bit was left HIGH becomes an output that starts HIGH, which can give a brief unwanted pulse. Other cores, such as ESP32, handle this differently, so check your own board.
How to confirm the cause
- Disconnect everything from the pin and read it. A steady HIGH from an unconnected input suggests a pull-up is enabled.
- Measure the unconnected pin with a multimeter. A voltage near the supply, instead of a wandering one, confirms a pull-up.
- Search the sketch for digitalWrite calls on pins that are also used with pinMode INPUT.
- If an LED on that pin glows faintly while it is an input, the pull-up current is leaking through the LED.
Worked example
The same pin used in two ways. The comments say what the pull-up state is after each line.
pinMode(7, OUTPUT);
digitalWrite(7, HIGH); // output, driving high
pinMode(7, INPUT); // now an input, pull-up STILL on
int a = digitalRead(7); // floating pin reads 1
digitalWrite(7, LOW); // clears the pull-up
int b = digitalRead(7); // floating pin is now unpredictable
pinMode(7, INPUT_PULLUP); // clear, explicit wayCommon mistakes
- Using digitalWrite on an input to get a pull-up and forgetting that it stays on.
- Wiring a switch to ground and then wondering why a pin set INPUT with no pull-up wanders.
- Connecting an LED and resistor to a pin that is left as an input after HIGH.
- Assuming every board treats digitalWrite on an input in the same way.
If this did not fix it
- A truly floating input; add a defined resistor to ground or supply.
- A pull-up and a pull-down fighting each other when you also added an external resistor.
- A sensor output that cannot pull the line low against the internal pull-up.
- The pin shares a function (serial, I2C, SPI) and another part of the code changes its mode.