Potentiometer jumping from 0% to 100%

When lowering my Potentiometer, everything is fine, but when it hits zero, it looks fine for a moment but then jumps back to 100%. I have a B10K wired like this.
image
Is there anything I can do to stop this? I don't want my ksp ship to randomly accelerate...

Here is my code

#define POTENTIOMETER_PIN A0

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

void loop()
{
  int data = analogRead(POTENTIOMETER_PIN);
  int percentage = map(data, 0, 1023, 0, 100);
  Serial.print("Potentiometer at ");
  Serial.print(percentage);
  Serial.println("%");
  delay(100);
}

It sounds like a bad pot. If you have an ohmmeter measure the two pins and see if it goes to infinity when you are at minimum. From your description I would expect that. Replace it with a working pot would solve the problem. You can also reverse the gnd and Vcc connections and see if it behaves similar but jumps to zero.

I have a 20 pack, should I just use another one or will this happen again?

If you do not connect it wrong it will work first time.

Once you have the pot sorted, and you want a more stable 0-100% readout, try this sketch.
Leo..

// converts the position of a 10k lin(B) pot to 0-100%
// pot connected to A0, 5volt and ground

int rawValue;
int oldValue;
byte potPercentage;
byte oldPercentage = 101;

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

void loop() {
  // rawValue = analogRead(A0); // add dummy read, if needed
  rawValue = analogRead(A0); // read pot
  // ignore bad hop-on region of a pot by removing 8 values at both extremes
  rawValue = constrain(rawValue, 8, 1015);
  // add some deadband
  if (rawValue < (oldValue - 4) || rawValue > (oldValue + 4)) {
    oldValue = rawValue;
    // convert to percentage
    potPercentage = map(oldValue, 8, 1008, 0, 100);
    // Only print if %value changes
    if (oldPercentage != potPercentage) {
      Serial.print("Pot is: ");
      Serial.print(potPercentage);
      Serial.println(" %");
      oldPercentage = potPercentage;
    }
  }
}

my guess is that the wiper is leaving the track, so A0 is open circuit.
you can put a resistor (say 1M) across gnd and output that will fix that without significantly affecting the reading.
Does it work OK at the +Vcc end?

Potentiometer tracks are inherently noisy. While you COULD add some simple digital filtering in your code, its easier just to add a capacitor (around 10uF) between output & GND.

1 Like

If it was one of those deals; 20 for $9 USD. Then yes throw it out and use another.
But check it with an ohmmeter first

1 Like

That is exactly what I have… I’ll try the new code

If you are worried about crashing you ship, then buy a good quality linear pot. May cost $2.50-$5.00 each.

"If you buy cheap, you buy twice."

Old Hanseatic merchant's proverb

1 Like

I have already smoldered, can I unsmolder and return?

That completely depends on the policies of the merchant you bought it from. I assume you mean "soldered" not "smoldered"...

Obviously, a part with solder on it can't be resold as new.

1 Like

Show us your soldering.
Pots do fail when you solder them too close to the carbon track.
Leo..

MEK (if legal) or Freon (def not legal) cleaned up many of my crackling pots. What cancer?

Cleaning only works for old pots. OP said that they were new.
I have seen beginners poke wires through the rivits of the carbon track, and solder that.
That definitely makes the pot unreliable, forever.
Leo..

1 Like

Everything is shipped in containers over salt water... probably half a year ago. It is understandable that one or most of them have corrosion. I see it in "new" metal parts treated with a film of shipping oil.

Which means the pot's ground was faulty.
A dirty pot would not jump to 100%, assuming no pull up on the pin was used.
Leo..

1 Like

What do you mean cancer?


image
I'm not sure what's happening here, I plugged the first pin on the left into GND, next I plugged the middle into A0, and then I put the last one into VCC. I have a Arduino Pro Micro board and I'm confused onto what's happening here. Does anyone know what could be causing this?

1 Like

Hi,
If that is the raw ADC count, then you have some noise.
What value is the potentiometer?

If you let the pot sit on its own does the rolling stop?

Try putting a 0.1uF capacitor between gnd and A0.

Don't forget, with 5V reference.
1 count = 5V / 1023 = 4.8mV

Tom.. :smiley: :+1: :coffee: :australia: