POTENTIOMETER VALUE VARIANCE.

Hello to all, i'm using a pot to to dictate a delay value. this code is 420 lines long so I do not want to put it all here . the part of the code that has me puzzled is below.

 int potValue_1 = analogRead(potentiometer_1);
  int mappedData = map(potValue_1, 0, 1023, 0, 15000);

So after I press a button the following happens
LEDs go high ,
delay for 500,
LEDs go low,
and then the "mapped data" is used as a variable delay before the next part of the program is excuted. the "mappedData" is sent to the serial monitor. but the results of the "mappeddata" vary. results on the serial monitor show readings from 586 to 630.

is this variance normal for Potentiometers??

Thanks in advance.

    digitalWrite(LED_1, HIGH);
    digitalWrite(LED_2, HIGH);
    digitalWrite(LED_3, HIGH);
    digitalWrite(LED_4, HIGH);
    digitalWrite(LED_5, HIGH);
    digitalWrite(LED_6, HIGH);
    digitalWrite(LED_7, HIGH);
    digitalWrite(LED_8, HIGH);
    digitalWrite(LED_9, HIGH);
   
    delay( 500);

    digitalWrite(LED_1, LOW);
    digitalWrite(LED_2, LOW);
    digitalWrite(LED_3, LOW);
    digitalWrite(LED_4, LOW);
    digitalWrite(LED_5, LOW);
    digitalWrite(LED_6, LOW);
    digitalWrite(LED_7, LOW);
    digitalWrite(LED_8, LOW);
    digitalWrite(LED_9, LOW);
noTone(buzzer);
   
    
   delay(mappedData); // Potentiometer control delay. 
   Serial.print("POT DELAY = ");
   Serial.println(mappedData);

the serial monitor show readings from 586 to 630.

No real surprise. The raw pot value may vary a little due to dirty contacts and by mapping 1023 to 15000 you are multiplying the raw value and any variance by 14.

is this variance normal for Potentiometers??

Yes, along with electrical noise in the circuit that you have not shared with us.

What do you see when you print the raw value from the pot ?

Thanks UKHeliBob,

ya, the raw value is fluctuating by 3 or 4 each time and the circuit , to be honest leaves a lot to be desired!!! I never gave it a thought. every day is a day for school.

If you put all led pins in an array all this

    digitalWrite(LED_1, HIGH);
    digitalWrite(LED_2, HIGH);
    digitalWrite(LED_3, HIGH);
    digitalWrite(LED_4, HIGH);
    digitalWrite(LED_5, HIGH);
    digitalWrite(LED_6, HIGH);
    digitalWrite(LED_7, HIGH);
    digitalWrite(LED_8, HIGH);
    digitalWrite(LED_9, HIGH);

Would just become

for(byte i = 0; i < 9; i++){
  digitalWrite(LedPins[i], HIGH);
}

Aka, once you start numbering variables, arrays are the better solution :wink:

PS WHY DID YOU NEED TO SCREAM????!!!! :wink: