Working with multiple Pots in multiple Analogue inputs

Hi,

I have been working on a little project for an amplifier.

I am using an Arduino UNO and want to control 6 potentiometers however I keep having issues as the potentiometers either don't read, read incorrectly and read correctly.

The potentiometer connected to A0 works fine and has no issues however the ones in A1 and A2 seem to just fine tune the initial A0 value.
The ones after A2 do not work all together.

These have all been wired up the same but with the wire changing each time for the Analogue read.
I am unsure of what I am doing wrong here.
I have followed tutorials on YouTube however even when copying the tutorials exactly it still has issues.

I am currently at work now but will upload my code once I get back home.

Any help on this would be greatly appreciated.

Please post your code and a wiring diagram

The analogue inputs all use the same comparator in the chip so need settling time between reading of different pins. A common technique is to read the value twice and discard the first reading

These have all been wired up the same but with the wire changing each time for the Analogue read.

What are you talking about? The potentiometers are NOT supposed to be plugged and unplugged at random, which your sentence suggests that you are doing.

Where IS your code?

Hi,

Sorry for the late reply.
I don’t have a wiring diagram unfortunately I can draw one up tomorrow.
But here is my code.

#define analogInPin0 A0
#define analogInPin1 A1
#define analogInPin2 A2
#define analogInPin3 A3
#define analogInPin4 A4

void setup(){

Serial.begin(9600);

}

void loop(){

Serial.print(“0”(analogRead(analogInPin0)));

Serial.print(“1”(analogRead(analogInPin1)));

Serial.print(“2”(analogRead(analogInPin2)));

Serial.print(“3”(analogRead(analogInPin3)));

Serial.print(“4”(analogRead(analogInPin4)));

delay(100);

}

So from what your suggesting with the Delay does that mean I should add some sort of delay per Potentiometer.

Sorry I’m pretty new to this.

UKHeliBob:
Please post your code and a wiring diagram

The analogue inputs all use the same comparator in the chip so need settling time between reading of different pins. A common technique is to read the value twice and discard the first reading

MorganS:

Hi,

I sorry I don't quite get you.
Do you mean uploading the code the arduino or posting/updating the results?

Thanks Again,
Ben

Do you mean uploading the code the arduino or posting/updating the results?

MorganS meant for to read the comment that UKHeliBob made, that you seem to have not read when he posted it.

void loop()
{
  analogRead(analogInPin0); // Read and throw away the value
  Serial.print("0"(analogRead(analogInPin0)));
  analogRead(analogInPin1); // Read and throw away the value
  Serial.print("1"(analogRead(analogInPin1)));
  analogRead(analogInPin2); // Read and throw away the value
  Serial.print("2"(analogRead(analogInPin2)));
  analogRead(analogInPin3); // Read and throw away the value
  Serial.print("3"(analogRead(analogInPin3)));
  analogRead(analogInPin4); // Read and throw away the value
  Serial.print("4"(analogRead(analogInPin4)));
 
  delay(100);
}
/Users/john/Documents/Arduino/sketch_apr28a/sketch_apr28a.ino: In function 'void loop()':
sketch_apr28a:15:44: error: expression cannot be used as a function
   Serial.print("0"(analogRead(analogInPin0)));
                                            ^

Your code won't compile. "0"(analogRead(analogInPin0) makes no sense at all.

Thanks.

Do you know of a better way to structure it?
I'm quite new to this Programming language.
I usually program in HTML/PHP.

Kind Regards,
Ben

If you want to print a zero before reading then just do it first

   Serial.print("0");
   Serial.print(analogRead(analogInPin0));

If that is not what you want to do then please explain what you are trying to do.

analogRead(analogInPin0); // Read and throw away the value

If the result is not used, will the ever vigilant compiler "optimize" it away and not execute it?

JCA79B:

analogRead(analogInPin0); // Read and throw away the value

If the result is not used, will the ever vigilant compiler "optimize" it away and not execute it?

No. The function is assumed to have side-effects so the call can't be optimized away.

Hi,

I have re-Worked the code so it now displays in the monitor.
I am however running into an issue where it should be displaying 0’s for everything but the A0 which Says “this is working”. Do you know of a way to fix this issue?

I am only using 1 Pot at the moment and that is plugged in to A0.

I would like to view all the results independently.

Here is my current code.

void setup(){

Serial.begin(9600);

}

void loop(){
int sensorValue0 = analogRead(A0);
Serial.println(sensorValue0);
Serial.print("this is working ");

int sensorValue1 = analogRead(A1);
Serial.println(sensorValue1);
Serial.print("eighty ");

int sensorValue2 = analogRead(A2);
Serial.println(sensorValue2);
Serial.print("Ben ");

int sensorValue3 = analogRead(A3);
Serial.println(sensorValue3);
Serial.print("Kack ");

int sensorValue4 = analogRead(A4);
Serial.println(sensorValue4);
Serial.print("slack ");
}

I have attached the output of the code.

Example.PNG

If you want them to read 0 connect the unused pins to GND. If you leave them unconnected they can produce any random number when you read them.

Steve

1 Like
 int sensorValue0 = analogRead(A0);
 Serial.println(sensorValue0);
 Serial.print("this is working ");

 int sensorValue1 = analogRead(A1);
 Serial.println(sensorValue1);
 Serial.print("eighty ");

  int sensorValue2 = analogRead(A2);
 Serial.println(sensorValue2);
 Serial.print("Ben ");

 int sensorValue3 = analogRead(A3);
 Serial.println(sensorValue3);
 Serial.print("Kack ");

 int sensorValue4 = analogRead(A4);
 Serial.println(sensorValue4);
 Serial.print("slack ");

Do yourself a favour and read up on arrays. You can then reduce the code above to about 3 lines

I am only using 1 Pot at the moment and that is plugged in to A0.

If you have nothing connected to analog pins 1, 2, 3, and 4, it is foolish to be reading them, and expecting ANY specific value as output.