I have set up my Arduino UNO with 4 input wires, they connect to the port 10, 11, 12, 13, they are connected to my breadboard with nothing on it but the wire.

My code would simply be:

Serial.println(digitalRead(13));


The thing is, after I briefly connect a pin to 5V or 3V3, the reading would start going nuts like: 1 0 0 1 0 1 1 1 0 1 0 1 1 0 Without any sense! Without having any wire connected directly to my VCC (5V or 3V3) the reading is constantly changing, when it should be zero!

Is my Arduino dead? How can I fix this?

• Just connect your triggering pin to ground when not triggered ! – user99014 Feb 1 '16 at 23:46

What you have is called a Floating pin. Digital Input pins are very sensitive to change, and unless positively driven to one state or another (High or Low), will pick up stray capacitance from nearby sources, like breadboards, human fingers, or even the air. Any wire connected to it will act like a little antenna and cause the input state to change. And I mean any wire, the trace on the board, the wire to the breadboard, the breadboard pin, even the metal pin of the IC itself.

This is refereed to in the Arduino reference page:

If the pin isn't connected to anything, digitalRead() can return either HIGH or LOW (and this can change randomly).

If you look at the Arduino Digital Pin Tutorial:

This also means however, that input pins with nothing connected to them, or with wires connected to them that are not connected to other circuits, will report seemingly random changes in pin state, picking up electrical noise from the environment, or capacitively coupling the state of a nearby pin.

Often it is useful to steer an input pin to a known state if no input is present. This can be done by adding a pullup resistor (to +5V), or a pulldown resistor (resistor to ground) on the input, with 10K being a common value. There are also convenient 20K pullup resistors built into the Atmega chip that can be accessed from software. These built-in pullup resistors are accessed in the following manner.

pinMode(pin, INPUT);           // set pin to input
digitalWrite(pin, HIGH);       // turn on pullup resistors


These weak pull resistors force the input pin state into a known state, and are easily overwritten by stronger input voltages, like a direct connection to ground or +5v.

• How about mentioning pinMode(pin, INPUT_PULLUP)? It's easy to remember, and really hard to screw up. – piojo Apr 25 '18 at 14:44

This is normal. Unless an input is connected to something, it will show HIGH or LOW or constantly changing. This is described by the digitalRead reference page on the Arduino web site.

The input pin behaves with some small capacitance, so briefly connecting to 3V3 or 5V will charge the capacitance. You may find a similar effect using a bare finger.

You can avoid the problem by adding a large value resistor between the pin and GND.

Ask yourself why you expect zero?

• pinMode(pin, INPUT_PULLUP ); – jippie Sep 23 '13 at 5:31