UNO reading false high input value

Hi,
I have an Arduino UNO and this sample sketch:

void setup(){
  pinMode(4, INPUT);
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

void loop(){
 if(digitalRead(4)==HIGH){
   digitalWrite(13, HIGH);
 }else{
   digitalWrite(13, LOW);
 }
 Serial.println(digitalRead(4));
 delay(100);
}

Is it normal that the UNO reads high input value on input 4 as soon as I connect a wire to the input? The wire is floating, not connected to anything!
Did I break the atmega??? :-[

It is normal that performing a digitalRead() on a pin with nothing connected to it (including just a wire going nowhere) will return random and invalid data. That is called a floating input and will go away if wired to an active circuit or by using pulldown or pullup resistors.

Lefty

Ok thanks so much!

I think the default setting for pins is input mode with internal weak pull-ups enabled.

I think the default setting for pins is input mode with internal weak pull-ups enabled.

Just the shear number of people who post with floating pin problems would suggest the pull-ups are not enabled by default.

Just the shear number of people who post with floating pin problems would suggest the pull-ups are not enabled by default.

Correct. Heck I wouldn't even be a god member if it wasn't for responding to posts involving floating inputs, and yea, LEDs with no resistors. ;D

Lefty