I wired up two 10k linear pots in the usual way (5v on one side gnd on the other and the center pin going to an analog input for each pot). Next I get the values with analogRead and serial print them.
Here's the problem, the first pot reads fine, I get the values from 0 1023 but the second one always stays at 1023.
If I unplug it the input floats and gives random values so there's a connection to the pot. Also I've switched the pots around and same happens on the same line (not same pot). I've also tried with different pins, same story. I even tried it on the arduino uno, teensy 2, and teensy 2++.
This is getting very frustrating I've looked at a ton of similar projects measuring two pots like this and it seems to work for everyone straight of. Am I missing something here? Will putting caps somewhere help?
here's my code:
int pin1 = A0;
int pin2 = A1;
int val1 = 0;
int val2 = 0;
Nothing wrong with using the A0, A1 pin numbers for any of digitalRead/Write() and analogRead(). Using analog pin numbers 0, 1 etc in analogRead() is the only place they are valid, so should you be using some analog pins as digital as well as analog, the A0, A1 names are clearer.
Of course when iterating through analog pins with a for loop the 0, 1 numbering scheme is convenient:
for (int channel = 0 ; channel < 6 ; channel++)
{
int val = analogRead (channel) ;
....
}