pin State

Hi everybody,

I got an Arduino Mega some weeks ago. It is really a masterpiece, but I came to a point that I think is a big problem (at least for me). I connected the common +5 via 2.2k resistor to dig input and i started reading it. When the +5 is on i got "1" on Serial.print(pin, BIN) and it was stable. But when the +5 are gone (via switch or sth) the "0" are all but stable. If you ask me a percentage - 5% wrong.

Has anyone experienced this too? What sould i do to read "0" for 0V?

Thank you!

Read this: :)

It is called floating input.


well i was thinking the same!

In fact i am not using a switch at all.

I just unpug the +5V line from the supply slot. I also use debounse time.

int pin22 = 22;
int val22A;
int val22B;

void setup() {
      pinMode(pin22, INPUT);                                                                                            

void loop()
  val22A = digitalRead(pin22);
  val22B = digitalRead(pin22);
  if (val22A == val22B)
  Serial.print(val22A, HEX);
  else {Serial.print("-----------------------");}

the only possible way that doesnt returns some "1" among the "0" is when i unplug the wire from the INPUT pin!

Strange for me!

If you disconnect the digital i/o pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, it will more-or-less randomly return either HIGH or LOW. That's why you need a pull-up or pull-down resister in the circuit.



Not a single “1” at 0V!
The pulldown works perfect!

Thank you for beeing there!