Go Down

Topic: Strange issues on digitalread (Read 576 times) previous topic - next topic

PeteOC

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: [Select]
val = digitalRead(8);
  if (val == 1)
  {
    Serial.println(val);
  }


Any ideas why this is?
Follow my projects - http://www.begerk.co.uk

AWOL

Floating pin.
Common noob problem.
"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.

Nick Gammon

If I set my multimeter to the millivolts range, and wave the cables around in the air, it gives "readings". Same thing.
http://www.gammon.com.au/electronics

AWOL

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

Nick Gammon

If I wave the cat around in the air, that gives readings too. ;)
http://www.gammon.com.au/electronics

liudr

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

GoForSmoke

Arduino has built-in pullups, just set the pin as INPUT and HIGH. Lovely bit of part-count reduction there.
I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Go Up