Pages: [1]   Go Down
Author Topic: Strange issues on digitalread  (Read 433 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I seem to have an issue where by if I do a digitalRead on pin 8, if I don't have anything connected to pin 8 it reads low however as soon as I connect a cable without anything attached, thats right a wire with nothing on the end the Arduino reads high.

My code is as follows

Code:
val = digitalRead(8);
  if (val == 1)
  {
    Serial.println(val);
  }

Any ideas why this is?
Logged

Follow my projects - http://www.begerk.co.uk

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24433
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Floating pin.
Common noob problem.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If I set my multimeter to the millivolts range, and wave the cables around in the air, it gives "readings". Same thing.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24433
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If I set my multimeter to the millivolts range, and wave the cables around in the air, it gives "readings".
Yup, my new LED-based electrician's screwdriver scared the pants off me the first time it flashed, a good 20cm from anything solid or conductive.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If I wave the cat around in the air, that gives readings too. smiley-wink
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 65
Posts: 6915
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What do you intend to do with that pin? If you want to sense a button with it, you need pullup or pulldown resistors.
Logged


Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4028
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Arduino has built-in pullups, just set the pin as INPUT and HIGH. Lovely bit of part-count reduction there.
Logged

Examples can be found in your IDE.

Pages: [1]   Go Up
Jump to: