Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Pages: [1]   Go Down
Author Topic: Strange issues on digitalread  (Read 562 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
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: 318
Posts: 26927
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
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 535
Posts: 19768
Lua rocks!
View Profile
WWW
 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

http://gammon.com.au/electronics
Please post technical questions on the forum - not by personal message. Thanks!

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 318
Posts: 26927
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
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 535
Posts: 19768
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://gammon.com.au/electronics
Please post technical questions on the forum - not by personal message. Thanks!

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 76
Posts: 7354
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: 100
Posts: 4869
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

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Pages: [1]   Go Up
Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Jump to: