Measuring two analog signals but only 1 is reading

Hi,

I'm very new to Arduino. I have an Arduino Duo R3 and I am trying to measure changes in two potentiometers (10 KOhms) on two analog pins. When I rotate the pot connected to A0 it changes the value being read for both A0 and A1. These values are for some reason identical. When I rotate the the pot connected to A1 nothing happens.

I have attached a picture of my wiring setup and my code is shown below. I hope someone can help as I've been googling for a long time with no answers.

const int measure1 = A0; //Each value being measured is named
const int measure2 = A1;

void setup() //the code that goes in the setup section is everything that should happen at the beginning of the program
{  
 
 Serial.begin(9600); // this is the sample rate in bits per second. 9600 is sufficient for most computers
 
 Serial.println("CLEARDATA"); //clears up any data left from previous projects

 Serial.println("LABEL,Date,Time"); //always write LABEL, so excel knows the next things will be the names of the columns. Each item that follows is a column name

 Serial.println("RESETTIMER"); //resets timer to 0 
}

void loop() //all items in here will start after the setup and then repeat 
{

int measure1 = analogRead(measure1); // this tells the arduino to measure the analog value coming through your arduino pin
delay(50);
int measure2 = analogRead(measure2);
 
 Serial.print("DATA,DATE,TIME"); //writes the time in the first column
 
 Serial.print(","); //moves over to the next column
 
 Serial.print(measure1); //writes the measured value 1 in the second column
 
 Serial.print(","); //moves over to the next column

 Serial.println(measure2); //writes the measured value 2 in the third column

 delay(4000); //add a delay before rerunning the loop

}

int measure1 = analogRead(measure1); // this tells the arduino to measure the analog value coming through your arduino pin
delay(50);
int measure2 = analogRead(measure2);

Is measure1 a pin number or a value? You appear to be completely confused as to which it is.

Hi PaulS. I'm totally new to this and didn't know I couldn't use the same name for both. Problem solved. Thanks for your help. :slight_smile:

Try this:

const int Measure1Pin = A0; //Each value being measured is named
const int Measure2Pin = A1;

void setup() //the code that goes in the setup section is everything that should happen at the beginning of the program
{
  Serial.begin(9600); // this is the sample rate in bits per second. 9600 is sufficient for most computers
  Serial.println("CLEARDATA"); //clears up any data left from previous projects
  Serial.println("LABEL,Date,Time"); //always write LABEL, so excel knows the next things will be the names of the columns. Each item that follows is a column name
  Serial.println("RESETTIMER"); //resets timer to 0
}

void loop() //all items in here will start after the setup and then repeat
{
  int measure1 = analogRead(Measure1Pin); // this tells the arduino to measure the analog value coming through your arduino pin
  delay(50);
  int measure2 = analogRead(Measure2Pin);
  Serial.print("DATA,DATE,TIME"); //writes the time in the first column
  Serial.print(","); //moves over to the next column
  Serial.print(measure1); //writes the measured value 1 in the second column
  Serial.print(","); //moves over to the next column
  Serial.println(measure2); //writes the measured value 2 in the third column
  delay(4000); //add a delay before rerunning the loop
}

That's one reason why it's good practice to start your GLOBAL variables with uppercase and put 'Pin' at the end of your pin number constants. Either one would have prevented your mistake. Your problem was having local variables with the exact same name as global variables. When you do that the function can't use the global variables.

Thanks johnwasser. Good explanation and suggestion of using Pin.