Ardunio, Odd analog reading serial outputs, help?

Whenever I try to read a voltage using analogRead() from my analog pin 15 on a Ardunio mega from a button that should always be sending a five volt current through, except when down I am getting this reading. Even though the stream is constant.

0
0
0
0
0
0
21
129
252
429
610
818
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
977
871
720
558
356
134
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
5
65
148
298
484
683
900
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1017
928
810
664
488
275
45
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
34
110
226
386
578
788
994
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1007
888
772
610
429
222
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

Do you have a capacitor in parallel to the switch for some reason? Also maybe The code that prints that may help people debug the reason behind the results

Chorvath:
Whenever I try to read a voltage using analogRead() from my analog pin 15 on a Ardunio mega from a button that should always be sending a five volt current through, except when down I am getting this reading. Even though the stream is constant.

For the record, "five volt current" is a little bit nonsense. Volts and Current aren't interchangeable.

How is your button wired?

http://www.truploader.com/view/886638

That is a link to a picture showing my setup.

PS extra info:
I am using a OSEPP mega 2560 which is a board that is very similar to the Ardunio mega. I am using the Ardunio v1.o compiler.
My code :
int val = 0;

void setup()
{
Serial.begin(9600);
}

void loop()
{
val = analogRead(15);
Serial.println(val);
}

The button is digital, so why are you using it as analog?

Looks like the button is floating. To be honest, it would probably be better if you drew a schematic of what is going on (or at least, what you think is going on.) If you were using the input as a digital input, you could turn on the internal pull-ups to fix that.

It defiantly is floating see this:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

Thanks grumpy and James, I solved my problem with a high pull up!

Take a look at how your data looks... and this watch this video I made of a floating pin:

Notice anything in common? :wink: