2 Potentiometers, 1 value

Hello, I have a problem. I have 2 potentiometers, one is on Analog Pin 2 and the other one Analog 3. But when I try to read the values (see code) the both give approximately the same value. One is just very consistent and the other value is totally not consistent. Both potentiometers are being used for something different and should not have the same value. I have checked the connections multiple times but it stayed the same. I also switched the wires of the analog but it keeps logging the value of the same potentiometer even after switching... I have also tried to put a delay of 100 in between the reads but that didn's change anything either. On the internet they said to read the values twice and that might fix it but didn't change anything, it did make the value that WAS'NT consistent before consistent though. PLEASE HELP!

Code attached!

[ No Errors ]

TimerDing.ino (1.11 KB)

Why do you think this might be an installation problem?

Please post your code, in code tags, along with your schematic.

Hello, I have a problem. I have 2 potentiometers, one is on Analog Pin 2 and the other one Analog 3. But when I try to read the values (see code) the both give approximately the same value. One is just very consistent and the other value is totally not consistent. Both potentiometers are being used for something different and should not have the same value. I have checked the connections multiple times but it stayed the same. I also switched the wires of the analog but it keeps logging the value of the same potentiometer even after switching... I have also tried to put a delay of 100 in between the reads but that didn's change anything either. On the internet they said to read the values twice and that might fix it but didn't change anything, it did make the value that WAS'NT consistent before consistent though. PLEASE HELP!

Code below!

[ No Errors ]

int out;
float timer = 300000.0f;
int interval = 3;
unsigned long previousMillis = 0;

int val = 0;
int intVal = 0;

float prevCalc;

void setup() {

  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  
  Serial.begin(9600);
  prevCalc = float(round(analogRead(A2)/1023.0f*15));
}

void loop() {

    val = analogRead(A3);
    intVal = analogRead(A2);
    
    float calc = float(round(val/1023.0f*15));
    if (calc != prevCalc) {
      timer = float(calc*60.0f*1000.0f);
      prevCalc = calc;
    }

    /*float intCalc = float(round(intVal/));
    if (calc != prevCalc) {
      timer = float(calc*60.0f*1000.0f);
      prevCalc = calc;
    }*/
    Serial.println(intVal);
  
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis > timer){
      Serial.println("Aan");
      delay(interval);
      Serial.println("Uit");
      previousMillis = currentMillis;
    }
    //Serial.println(currentMillis - previousMillis);
}

When switching between analogue inputs it is good practice to discard the first reading and use the second.
How are the potentiometers wired? Are you sure the wiper is connected to the analogue pin and opposite ends of the track connected to VCC, GND.

When something is not working, you go back to the basics.
Assuming you have 10k linear pots (10kB), try this (untested) sketch.
If this is not printing 0-1023, or the pots are influencing each other, then there is something wrong with the wiring.
Leo..

void setup() {
Serial.begin (9600);
}

void loop() {
Serial.print("pot1: ");
Serial.print(analogRead(A2));
Serial.print("\tpot2: ");
Serial.println(analogRead(A3));
delay(1000);
}

Duplicate topics moved and merged

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.