Jittery pots - arduino


#1

Hi I have tried about 5 potentiometers and they’re all jittery and fluctuate… Just wondering if you sell something of better quality or have components to get a decent read… I’m using them to adjust HSL values in some neopixels and they’re frustratingly jittery
I.e. even sitting untouched the pot value changes ± 5-20 in value which causes my through hole neo to fluctuate in colour

I tried a cap between ground and analog on the pot but to no avail… I was wondering if software smoothing would be viable next… I’d prefer to clean it up at a component level if possible

Thanks
Tom


#2

I’ve never found a potentiometer that varies like that. You can prove it by measuring the voltage at the wiper with a multimeter. You may be seeing the Arduino ADC noise, in the Atmel chip, which given a stable input voltage will generate different values in software. Software filtering is usually needed. There are also tricks that can be used in code to turn off unused chip resources to stabilise the ADC readings further. The Atmel datasheet has details.


#3

Someone suggested hall effect style pots? These were just pots from jaycar…


#4

I’ve not used those, sorry. Unless you mean rotary encoders, in which case, yes, they are the best for user input, way better than potentiometers, and they aren’t subject to as much noise or thermal change of reading.

I’ve just done a test with an Arduino Uno clone and a Thinker Shield, which has a 10k potentiometer between IOREF and GND, and I’m seeing jitter of one to two least significant bits, over the ten bit resolution. Not seeing ± 5-20.

You might have an unstable AREF or IOREF voltage. Have you tried a different Arduino? Which Arduino are you using? What power source? Is there a difference if the capacitor to ground is attached at the Arduino end of the cabling?


#5

You might also be in an area or near an object that is emitting a lot of EMF.
An easier option might be to just “fix it up in code” and use a smoothing algorithm.

Here is a nice library that you could use:

The example is quite easy to follow:

/*
  Smoothens signal jitter on analog inputs by averaging 
  concurrent readings. The number of readings averaged can 
  range from 1 (no smooting) to 100.
  
  The more readings you average the more consistent the signal 
  becomes. At the same time it takes longer to detect actual 
  changes in the signal.
*/
#include <AnalogSmooth.h>

int analogPin = 1;

// Defaults to window size 10
AnalogSmooth as = AnalogSmooth();

// Window size can range from 1 - 100
AnalogSmooth as100 = AnalogSmooth(100);

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

void loop() {
  // Regular reading
  float analog = analogRead(analogPin);
  Serial.print("Non-Smooth: ");
  Serial.println(analog);
  
  // Smoothing with window size 10
  float analogSmooth = as.smooth(analog);
  Serial.print("Smooth (10): ");  
  Serial.println(analogSmooth);

  // Smoothing with window size 100
  float analogSmooth100 = as100.analogReadSmooth(analogPin);
  Serial.print("Smooth (100): ");  
  Serial.println(analogSmooth100);

  Serial.println("");
  delay(1000);
}

#6

Thanks guys this has all been super helpful! I’ll have a tinker this
evening and see what I come up with :slight_smile:


#7

If you’re running the neopixels from the same power source as the Arduino, the changes in current draw by the pixels (both due to PWM and changing colour/brightness) is probably causing high noise levels on the supply and AREF inputs. So you could try using two separate 5V power supplies, with only the ground connection common, and see if that helps. If that confirms the source, then a single supply with some extra filtering for the Arduino power (RC or LC filter) may then be an option, but a rotary encoder is a nice solution as well.


#8

Thanks Kean! that did it :slight_smile: