analogRead multiple value Problem

Hi guys,
can someone help me:

I am currently reading 2 values ​​from the potentiometer (i.e. 2 * analogRead). The problem when I adjust the potentiometer the second value is also changed.
Switch to Poti 1: value 0 to 1023 and show me this on the serial monitor.
to potentiometer 2: change values ​​from 0 to 1023 and the value of potentiometer 1 will also influence itself although they are connected separately.
Here below is the program code:

void HandlePot(void){

static int old_val_1=0;
int already_val_1;

static int old_val_2=0;
int already_val_2;

int current_1=analogRead(A2);
int current_2=analogRead(A9);

int current_x1= current_1 * 5 /1023;
int current_x2=current_2 * 5/1023;

already_val_1= current_x1;
already_val_2=  current_x2;

if(already_val_1!=old_val_1){
Serial.print("3");
Serial.println((String)current_x1);
}
if(already_val_2 != old_val_2){

Serial.print("4");
Serial.println((String) current_x2);
}

old_val_2=already_val_2;
old_val_1=already_val_1;
delay(400);

}

thanks

Hello
Post the schematic of your project.

Which Arduino board do you use ?

Why do you arrange douple post?

I am using Arduino Mega 2560 board.
I need two values ​​that look right on interface.

I have a simple code down here but always the same problem.

Change potentiometer 1 then the two values ​​will change.

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(A2, INPUT);
pinMode(A9,INPUT);
}

void loop() {
// put your main code here, to run repeatedly:

int current1= analogRead(A2);
int current2=analogRead(A9);

int voltage1= current1 * (5./1023.);
int voltage2= current2 * (5./1023.) ;

Serial.print("Poti_1 ");
Serial.println(voltage1);
Serial.print("Poti_2 ");
Serial.println(voltage2);
delay (1000);
}

Read each channel twice and only process the second reading.

It works in a virtual world: https://wokwi.com/arduino/projects/308062377567322690.
I had to change A9 to A7, because the simulation is still in development and only the first analog inputs seems to be implemented.

We like to know more.
You can draw a schematic on a piece of paper and make a photo of it. Or you can tell that it is the same as the simulation.
Can you show a photo ? Perhaps you use a breadboard. They have often bad contacts.

it is the same as the simulation.
i use this adapter for my arduino Mega. (https://www.amazon.de/electronics-salon-Terminal-Adapter-Arduino-mega-2560-R3/dp/B01CU3OB5Y/ref=asc_df_B01CU3OB5Y/?tag=googshopde-21&linkCode=df0&hvadid=447401151351&hvpos=&hvnetw=g&hvrand=2634984513463296530&hvpone=&hvptwo=&hvqmt=&hvdev=c&hvdvcmdl=&hvlocint=&hvlocphy=9043700&hvtargid=pla-568542063787&psc=1&th=1&psc=1)
I think the problem is coming from this adapter.

Tip: That link can be shortened to this: https://www.amazon.de/electronics-salon-Terminal-Adapter-Arduino-mega-2560-R3/dp/B01CU3OB5Y/

On the photo it seems good quality, but the Mega board is upside down.
You could check the connections with a multimeter.

Thanks to Whandall for noticing the Doppelpost / double post. Let's hope no one will answer there, or we get confused.

@ihebkebaier
I have deleted your other topic on the same subject. Posting twice on the same subject is against the forum rules because of the possibility of 2 different groups of volunteers spending their time trying to help, each unaware of what the other is doing. I kept this topic as it has the most replies.

Please read How to get the best out of this forum

Thanks.

Shows us the wiring plz

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.