Analog input giving strange values when a simple wire is plugged

Hello all,

I just bought an Arduino and started playing with it.

My issue is that analog and digital value seems totally crazy when I plug a wire into the hole. The wire is a simple 5 cm long wire that ends in the air. It is NOT connected to any electronic devices.

I understand that there are pertubations and noise in the air, but I cannot believe they are 5 V high...

Serial.println(analogRead(A0));

gives the following result:

265 207 226 294 251 204 237 296 237 203 248 296 227 203 263 292 219 207 276 284 213 212 283

and as soon as I plug the cable:

238 1023 332 0 205 1023 370 0 171 1023 413 0 144 1012 462 0 113 973 730 0 17 595 1023 83 3 343 1023

Any idea?

What you are seeing is perfectly normal, a 'floating input pin' either digital or analog is just reading noise and giving readings that are not valid. Adding a wire just increases the noise level and therefore increases the variations in readings. The results of reading a digital or analog input pin is only valid if there is a 'valid' electrical signal wired to the pin. And 'valid' has several requirements.

Lefty

Thank a lot!

Googling " 'floating input pin'" and wikipedia gives me really a lot of great information.

I guess I need to learn how to activate the internal pull up resistor, because I don't want to add resistors on every input!

Will read a lot, thanks for the hint

Waza_be: Thank a lot!

Googling " 'floating input pin'" and wikipedia gives me really a lot of great information.

I guess I need to learn how to activate the internal pull up resistor, because I don't want to add resistors on every input!

Will read a lot, thanks for the hint

Well I would ask why would you want to read a pin that has nothing wired to it in your sketch? Floating input pins are not a problem if you are not using those pins for anything useful.

Lefty

Because I need to read buttons input from an old videogame. (https://docs.google.com/open?id=0BxpXApcdNdskNWhaeXg5ZGlNem8)

When the buttons are not pressed, I get an open circuit and the pin is connected to nothing, resulting a floating input

So, I ended using the answer you posted here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1261680395

  pinMode(buttonAPin, INPUT);
  digitalWrite(buttonAPin, HIGH);

and I connected the other side of the button to the ground, and that works fine, with no noise at all

Value is one when I do not press the button and turn into zero when pressed

Well I was responding to your statement:

I guess I need to learn how to activate the internal pull up resistor, because I don't want to add resistors on every input!

I would state you really meant: I guess I need to learn how to activate the internal pull up resistor, because I don't want to add resistors on every input that I will be using!

So, yes pull-ups, either external or internal, are required in some cases, as in simple switch contacts. Other times they are not needed, and for sure if you are not using a input pin at all it does not have to be pulled up.

Lefty