Go Down

Topic: UNO reading false high input value (Read 1 time) previous topic - next topic

cioto

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

Code: [Select]

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???  :-[

retrolefty

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

cioto


MarkT

I think the default setting for pins is input mode with internal weak pull-ups enabled.
[ I won't respond to messages, use the forum please ]

James C4S

Quote
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.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

retrolefty

Quote
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

Go Up