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