Electronics Fundamentals

Why Floating Inputs Cause Strange Behavior

Why an unconnected input pin reads random values, and how pull-up and pull-down resistors give buttons and switches a reliable default state.

On this page
  1. A pin that is connected to nothing
  2. Where it shows up
  3. The cure: give it a default
  4. Internal pull-ups
  5. Related: contact bounce
  6. Spotting it in practice
  7. Good habits

A pin that is connected to nothing

Digital inputs on a chip or a microcontroller board are meant to read one of two states: high or low. A pin that is not connected to anything is not neither of them. It is undefined. Experimenters call this a floating input, and the effects can be puzzling. An LED flickers with nobody touching a button, a program reports a press that did not happen, or the reading changes when you wave your hand near the board.

The reason is that an input pin has extremely high resistance. It draws almost no current, so it takes very little to push its voltage around. Stray electric fields from nearby wires, your body, mains wiring in the walls or other signals on the board can nudge the voltage across the threshold between high and low. The input then reports whatever it happens to pick up.

This is also a good moment to repeat the basics of safe practice. Do these experiments with low-voltage sources only, and do not open or modify mains-powered equipment unless you are qualified.

Where it shows up

Floating inputs appear in many common situations.

  • A button or switch with one side connected. When open, the pin is connected to nothing at all. When closed, it connects to power or ground. In between, the pin floats.
  • A header or pin left unused. Spare inputs on logic chips are often left unconnected by mistake.
  • A sensor or module that is disconnected, or whose output is only driven some of the time.
  • A transistor gate with nothing holding it. A MOSFET gate that is not driven can float and switch a load unpredictably, as mentioned in the discussion of using a transistor as a switch.

Note that a floating input generally does no harm in terms of damage in modern low-voltage parts, but some older logic can draw extra current or heat up. The bigger issue is unreliable behavior.

The cure: give it a default

The fix is to connect the pin to a known level through a resistor, so it has a defined state when nothing else is driving it.

Pull-down resistor. Connects the input to ground. When nothing else drives the pin, the resistor pulls it low. A button then connects the pin to the positive supply. Pressing reads high, and releasing reads low.

Pull-up resistor. Connects the input to the positive supply. The default is high. A button then connects the pin to ground. Pressing reads low, and releasing reads high. This reversed logic is common and takes some getting used to.

Why a resistor and not a plain wire? A wire would short the supply to ground when the button closes. The resistor limits that current to a tiny amount. As a hypothetical example, a 10,000 ohm pull-up on a 5 volt supply passes 5 / 10,000 = 0.0005 amps, or 0.5 milliamps, when the button grounds the pin. That is small, yet the resistor is weak enough that any deliberate connection overrides it easily.

Typical values are in the range of several kilohms to a few tens of kilohms. Smaller values give a stiffer, more noise-resistant default but waste more current. Larger values save current but are more easily disturbed. The values in the passive components overview give a feel for the choices.

Internal pull-ups

Many microcontroller boards include internal pull-up resistors that can be turned on in software for a pin. This saves a part. A button wired between the pin and ground, with the internal pull-up enabled, works without any external resistor. Check your board’s documentation to see what it offers, since not all pins or chips support pull-downs the same way, and the internal values are usually fairly large.

Whichever method you use, it is wise to state in your notes which one you used, because it affects how you read the pin in software.

Mechanical switches do not close cleanly. For a few milliseconds, the contacts can bounce, producing a burst of rapid changes. A floating pin looks random, but a bouncing switch is a different problem, with a defined default and a messy transition. A small capacitor, a short delay in software or a dedicated debounce circuit handles it. It is worth knowing the difference so you troubleshoot the right thing.

Spotting it in practice

Signs your problem is a floating input:

  • Readings change when you touch the wire or the board.
  • Readings look random or noisy while the button is not pressed.
  • Behavior changes when you move the circuit or when other equipment turns on.
  • Adding a high-value resistor from the pin to ground, or enabling an internal pull-up, makes the problem go away.

A multimeter can help, since a floating pin often reads an unstable voltage, and the techniques are covered in the guide to checking a circuit with a multimeter. Note that a meter itself can disturb a high-impedance node a little.

Good habits

  1. Decide the default state of every input and provide it.
  2. Tie unused inputs on logic chips to power or ground as the datasheet recommends.
  3. Keep wires to sensitive inputs short, especially ones that run alongside power wiring.
  4. Mark which pins use pull-ups on your diagram.
  5. When behavior seems random, check for floating inputs early in your circuit troubleshooting.

A circuit that behaves consistently starts with every input having a defined state.

The complete guide to electronics fundamentals

A Beginner Map of Electronic Components
Read the guide

Keep exploring

Guides from other topics

All topics →