I'm trying to read analog value controlled by potentiometer. I receive different values for the same potentiometer position. For example, when I expect to receive 0, times to times I receive 1 and 2.
Code:
void setup() {
Serial.begin(9600);
}
void loop() {
int value = analogRead(A0);
Serial.println(value);
}
That is what they do. Good quality potentiometers are better, but they still have that.
Only in a simulation (such as in Wokwi simulation where you made that picture ) it is perfect zero, but not in real life.
In software, you can add a filter or hysteresis.
A capacitor from the wiper to groud will hep to bypasss noise. A starting point is the 0.1uF ceramic cap. It will not eliminate noise, but shoud reduce it.
As you can see, a wide range of values can be used. Many times one will see 2 or more caps connected in parallel. Each cap's value will allow it to bypass different frequencies. A 0.1uF ceramic cap will help to bypass higher frequencies. The 4.7uF is more effective at lower frequency.
Analysis and/or observation will indicate which to use in this case.