Pages: [1]   Go Down
Author Topic: UNO reading false high input value  (Read 1214 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 44
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 44
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok thanks so much!
Logged

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12070
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

[ I won't respond to messages, use the forum please ]

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6146
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: