Pages: [1]   Go Down
Author Topic: problem with multiple analog inputs! buggy arduinos? needs caps?  (Read 1005 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

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;

void setup(){
  Serial.begin(9600);
  pinMode(pin1, INPUT);
  pinMode(pin2, INPUT);
}

void loop(){
  val1 = analogRead(pin1);
  val2 = analogRead(pin2);
  Serial.print(val1);
  Serial.print("    ");
  Serial.println(val2);
}


Any help would be greatly appreciated!!


* potprob.jpg (395.01 KB, 1137x1173 - viewed 36 times.)
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13718
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Here's the problem, the first pot reads fine, I get the values from 0 1023 but the second one always stays at 1023.
That means that the GND of the second pot is not connected well

try to use a new wire between the failing pot and the GND of the arduino.

Note it can be a bad connector in the breadboard!

please use the # button (just above the smileys) to post code with proper tags.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's it! thanks I switched every thing up and it works, I think its the ground power line that might be cut off.
pheww, thanks
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Some breadboards have the power and/or ground lines at the edges split into 2 equal parts. Maybe yours is like that.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34183
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is wrong:-
Code:
int pin1 = A0;
int pin2 = A1;
Change it to:-
Code:
int pin1 = 0;
int pin2 = 1;
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is wrong:-
Code:
int pin1 = A0;
int pin2 = A1;
Change it to:-
Code:
int pin1 = 0;
int pin2 = 1;

Why do you think the first example is wrong. I thought A0 was a predefined alias for analog pin 0, A1 for analog pin 1, etc. ?

Lefty
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
needs caps?

In general, capacitors (and inductors) are evil and you should try to use fewer of them if you can.
Logged

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12179
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
  for (int channel = 0 ; channel < 6 ; channel++)
  {
    int val = analogRead (channel) ;
    ....
  }
Logged

[ I won't respond to messages, use the forum please ]

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13718
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this works too

Code:
for (int channel = A0 ; channel <= A5 ; channel++)  // even channel < A6 works !!
  {
    int val = analogRead (channel) ;
    ....
  }
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: