analogRead gives random values on an unconnected pin

An analog input with nothing attached floats and picks up noise. It is not an error, but it cannot be trusted.

What the message means

The input has very high impedance, so stray fields move its voltage. The reading changes with your hand near the wire.

Fix it in this order

  1. Connect the sensor output to the pin and its ground to the board ground.
  2. If you want a defined idle level, add a resistor of about 10 kohm to ground or to the supply.
  3. Check the pin name: A0 is not the same as digital pin 0.
  4. Read the pin twice and keep the second value if you switch between several analog pins quickly.
  5. Use the supply voltage the board uses as reference when you convert the reading to volts.

Why it happens

The ADC input is a high-impedance node. When nothing drives it, the charge on the sampling capacitor inside the chip is not held by any source, so it drifts with stray pickup from nearby wires, your hand, or mains noise. Each analogRead returns whatever the converter measured at that instant. A floating input has no reference voltage of its own, so the number has no fixed meaning.

Analog inputs are designed to read a voltage source with a defined impedance. A resistive divider, a potentiometer wiper, or a sensor output all provide that. Adding a pull-down or pull-up resistor sets the idle level, so the reading is stable when the sensor is absent. Choosing a resistor that is low enough to define the node, yet high enough not to waste power, is a standard design step.

If you see this, do this

You seeDo this
Changes when you touch the wireFloating input.
Stable but wrongCheck the wiring and the reference voltage.

Confirm the fix

  1. Print analogRead on the unconnected pin ten times; wide swings with nothing attached confirm a floating input.
  2. Touch a jumper wire lead to the pin and watch the value change; then tie the pin to ground and confirm it reads near zero.
  3. Measure the pin voltage with a multimeter while the sketch runs and compare it with the analogRead result converted to volts.

Common mistake: Many readers assume analogRead on an empty pin returns zero, when in fact the pin floats and returns a changing value that looks like a real signal.

floating digital input, LDR divider.

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.