# Debounce a Potentiometer?

Even when I'm not touching the pot, analogRead returns a range of values, typically +/- 3.

Even mapping the 10bits to a range of 50-241 will still flicker +/- 1

How do you ignore the noise? I have a 7 segment display showing the pot value and it jumps all over the place.

This method sort of works yet really sucks as I can't change the value by 1.

``````  if(abs(prevPotValMap - potValMap)>1){
Serial.print("potValMap ");
Serial.println(potValMap);
prevPotValMap = potValMap;
}
``````

Try putting a 100nF cap from the analog input pin to ground.

You have a 100nF cap from Aref to ground as well, yes? (is included on most Arduino boards)

You can filter/decouple in analog (as crossroads said) or in digital as well. Do averaging of the values (ie sum 32 pot measurements and divide by 32) or implement a low pass filter: new_value=A*old_value+B*new_value where A+B=1, and the smaller the B (ie. B=0.2) the bigger the filtering effect. P.

I've been struggling with this for a while. Perhaps a plain old 10k pot is too erratic for what I need, which is:

Dial in BPM (Beats per Minute) and convert to the microSeconds for the display.

I only want a range of 50-240 BPMs out of thing, but it has to sit there rock steady and musical.

I wanted to dial in the integer portion only with the pot, and have inc+/dec- buttons for the 1/10s of a BPM. A coarse/fine arrangement.

To eliminate a lot of things: - I grabbed a spare Arduino (Freeduino) - did the most basic analogRead() tut - tried the smoothing tut with numReadings up to 40! - tried the .1 uF cap over the middle and ground pins of the pot - tried different pots - did the software LPF with assorted values - various averaging algo's

I hear of people getting stable +/- 1, what am I doing wrong? Do I have to go discreet steppers like switches? Hope not, I don't need 6 switches for coarse, medium, fine +/- that would be unusable in low light conditions -or- by anyone that's ingested intoxicants.

Geez, I'd have this wrapped up in minutes if it were a software UI. I feel like such a stoopid boob.

Happy Halloween everybuddy!

Carl

Here's the potentiometer spazziness I'm talking about:

Looks like it is contained to 20mV, what is the period of the wave and what could it be tied to?

How do folks deal with this?

Thanks, Carl

I had a similar problem with an Arduino app that used an external 78l05 voltage regulator. The regulator had a low level oscillation at about 20 Mhz on the output. The problem went away when I added a 0.1 ufd cap across the regulator input.

the potentiometer spazziness

While you might not think that word is offensive, remember this is a world forum and in the UK this is a very offensive word to use, and I don't mean potentiometer.

You will always get a reading +/- 1 out of any A/D converter, that is the nature of converters. You need to do one or more of the things you have been told about:- 1) Add some capacitors to smooth the output. 2) Add some software to take the average and thus smooth the output. 3) Implement a threshold so that you only consider a number to have changed when it is say 3 or 4 units away from the previous reading. When you detect this distance then increment (or decrement) the number and look again.

My regrets for using the “s” word. Here we use it to describe what someone being swarmed by mosquitoes looks like.

I’ve been doing more reading on the AREF as crossroads eluded to earlier, read your blog about decoupling, some forum archives here and on bildr.org, LPF on wiki. One thing I could improve upon is move the cap away from the pot and nearer the input pin on the Arduino.

I will hook the scope up and watch the changes I make to the circuit and see if I’m improving things. I was previoulsly trying to draw conclusions from the serial output.

From looking at the wave, it appears to be 1.75MHz Just wonder what else clocks at that frequency…

Hmm... ten cycles in 0.55 microseconds.. Looks more like 18 Mhz to me.

Take a 0.1 or 0.01 ufd capacitor, ground one end then poke around the circuit with the other end and see if you find a spot that removes the oscillation.

Have you tried the running average code?

http://arduino.cc/playground/Main/RunningAverage