Go Down

Topic: Stabilizing a potentiometer (Read 551 times) previous topic - next topic


As Smajdalf said, plus:

I would think a linear pot would be a much better fit than a logarithmic type (part# not provided).
Also, I would take into consideration dimming and perception in your code (not provided).
I'm sure this would help considerably.


"Eliminate pot variations, and add supply variations."

Yes right Leo, good point.  I had assumed the OP would be meauring with respect to the internal reference which
(despite its limitations) is pretty well regulated from supply variation.

So a cap from the arduino's ground pin to A0 should improve matters - assuming the pot is connected to the same ground pin.

Generally schematics dont give a good indication of supply connection layout.

I'm trying to help. If I find your question interesting I'll give you karma. If you find my input useful please give me karma (I need it)


Jul 15, 2020, 01:09 am Last Edit: Jul 15, 2020, 01:11 am by Wawa
This sketch gives a very stable output, even if the A/D value from the pot jumps a bit.
Code: [Select]
const byte potPin = A0; // 10k lin (10kB)
const byte ledPin = 3;
int rawValue, prevValue;

void setup() {

void loop() {
  rawValue = analogRead(potPin); // read pot
  if (rawValue < (prevValue - 2) || rawValue > (prevValue + 2)) { // deadband
    prevValue = rawValue; // update
    analogWrite(ledPin, prevValue >> 2); // 10-bit to 8-bit (0-255)

Go Up