Go Down

Topic: Strange issues on digitalread (Read 619 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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
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. ;)
Please post technical questions on the forum, not by personal message. Thanks!

More info:
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.
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Go Up