# Noise from potentiometer reading

**URL:** <https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290>\
**Category:** General Guidance\
**Created:** [June 3, 2023, 5:32pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290 "2023-06-03T17:32:14Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![hk\_jh](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hk_jh/32/1013044_2.png) [@hk\_jh](https://forum.arduino.cc/u/hk_jh)\
**Post date:** [June 3, 2023, 5:32pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/1 "2023-06-03T17:32:14Z")

</div>

I'm using three B10k pots on breadboard with the following function:

wired as:  
wiper leg \>\> analog pin  
one leg \>\> gnd  
other leg \>\> +5V

```arduino
void readPotentiometers() {
  for (int i = 0; i < numButtons; i++) {
    int potValue = 1023 - analogRead(potentiometerPins[i]); // Read the potentiometer value
    //has analog value changed more than the filter amount ?
    if (abs(lastValue[i] - potValue) > filter) {
      if (lastValue[i] != potValue) {
        //update to the new value
        lastValue[i] = potValue;
        Serial.print("Potentiometer");
        Serial.print(i + 1);
        Serial.print(": ");
        Serial.println(potValue);
      }
    }
  }
}

```

I'm still having some noise ( unwanted fluctuating in numbers from the analog pins) . How can I get rid of it?  
Does the fact I'm using breadboard contributing to the noise? will soldering the pots will eliminate the noise? will using larger value of pot will help?

Thanks

---

<div class="post-metadata">

**Author:** ![Paul\_KD7HB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_kd7hb/32/1127958_2.png) [@Paul\_KD7HB](https://forum.arduino.cc/u/Paul_KD7HB)\
**Post date:** [June 3, 2023, 5:51pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/2 "2023-06-03T17:51:50Z")

</div>

To debug, display the Actual value read from the AD pin. Add different small value capacitors from the wiper to ground. See which value makes the greatest difference. A larger value pot will just make the noise have a greater value.  
With an AD conversion, the LO bit will always be changing from 0 to 1 and back because of the uncertainty of the actual process. If more than the LO bit is changing, then you may need to smooth/average the readings.

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [June 3, 2023, 6:07pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/3 "2023-06-03T18:07:35Z")

</div>

> [@hk\_jh](#):
>
> B10k pots

That value is okey.  
Is there any difference, in the trouble, between the different buttons?  
Is there any pattern, noise coming at certain times?  
Do You have an oscilloscope available to take a closer look att the analog inputs?

I use the same kind of analog controlling DC motors and never experienced and motor jumping.

---

<div class="post-metadata">

**Author:** ![hk\_jh](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hk_jh/32/1013044_2.png) [@hk\_jh](https://forum.arduino.cc/u/hk_jh)\
**Post date:** [June 3, 2023, 6:23pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/4 "2023-06-03T18:23:52Z")

</div>

> [@Railroader](#):
>
> Is there any difference, in the trouble, between the different buttons?

between the difference pots? I don't see much difference.

I noticed the if my filter value is 2 the reading is just fine (noise is gone) but if I'm taking the filter value to 1 the fluctuating is back.

I have added 10nF cap between wiper to ground which I think helped to reduced the fluctuating

edit: so it seems to work very stable even when filter is equal to 1. I think the fluctuating I'm facing is because the pots not sitting stable on my breadboard

---

<div class="post-metadata">

**Author:** ![hk\_jh](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hk_jh/32/1013044_2.png) [@hk\_jh](https://forum.arduino.cc/u/hk_jh)\
**Post date:** [June 3, 2023, 6:24pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/5 "2023-06-03T18:24:27Z")

</div>

> [@Railroader](#):
>
> I use the same kind of analog controlling DC motors and never experienced and motor jumping.

even not small fluctuating of two close values?

---

<div class="post-metadata">

**Author:** ![madmark2150](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@madmark2150](https://forum.arduino.cc/u/madmark2150)\
**Post date:** [June 3, 2023, 6:34pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/6 "2023-06-03T18:34:24Z")

</div>

Breadboards are noisy. Hard wire (soldered or screw terminals) with SHIELDED wire for best results. Breadboards are not recommended for HF analog work because of parasitic coupling and intrinsic stray capacitance.

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [June 3, 2023, 6:39pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/7 "2023-06-03T18:39:06Z")

</div>

> [@hk\_jh](#):
>
> even not small fluctuating of two close values?

Rock solid, powered by Pc USB. Most of the time not even 1 digit change.

> [@hk\_jh](#):
>
> my filter value is

What filter? There's no filtering in that code. You made the mistake of posting a snippet. Don't do that again.  
Please post a picture of the setup. Long cables, noisy equipment nearby, noisy environment in general?

---

<div class="post-metadata">

**Author:** ![hk\_jh](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hk_jh/32/1013044_2.png) [@hk\_jh](https://forum.arduino.cc/u/hk_jh)\
**Post date:** [June 3, 2023, 6:48pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/8 "2023-06-03T18:48:56Z")

</div>

> [@Railroader](#):
>
> Rock solid, powered by Pc USB. Most of the time not even 1 digit change.

On breadboard?

---

<div class="post-metadata">

**Author:** ![hk\_jh](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hk_jh/32/1013044_2.png) [@hk\_jh](https://forum.arduino.cc/u/hk_jh)\
**Post date:** [June 3, 2023, 6:50pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/9 "2023-06-03T18:50:16Z")

</div>

> [@Railroader](#):
>
> What filter? There's no filtering in that code. You made the mistake of posting a snippet. Don't do that again.  
> Please post a picture of the setup. Long cables, noisy equipment nearby, noisy environment in general?

Full code:

```arduino
const int numButtons = 3; // Number of buttons
const int numPots = 3; // Number of pots

const int buttonPins[numButtons] = {2, 3, 4}; // Button pin numbers
const int ledPins[numButtons] = {5, 6, 7}; // LED pin numbers
const int potentiometerPins[numPots] = {A0, A1, A2}; // Potentiometer analog input pins
const int heartbeatLED = 13;

bool ledStates[numButtons] = {false}; // States of LEDs
bool previousStates[numButtons] = {false}; // Previous states of buttons
unsigned long debounceDelay = 25; // Debounce delay time in milliseconds

unsigned long lastDebounceTime[numButtons] = {0}; // Last time the button was toggled

int lastValue[numPots];
const byte filter = 1; //adjust as needed

//timing variables
unsigned long previousMillis = 0;
unsigned long heartbeatMillis;

void setup() {
  for (int i = 0; i < numButtons; i++) {
    pinMode(buttonPins[i], INPUT_PULLUP); // Set button pins as inputs with internal pull-up resistors
    pinMode(ledPins[i], OUTPUT); // Set LED pins as outputs
    pinMode(heartbeatLED, OUTPUT);
  }

  Serial.begin(115200); // Initialize serial communication
}

void loop() {
  checkButtons();
  readPotentiometers();
  checkHeartbeatTIMER();

}

void checkButtons() {
  for (int i = 0; i < numButtons; i++) {
    bool currentButtonState = (digitalRead(buttonPins[i]) == LOW); // Read the current state of the button

    // Check if the button state has changed and enough time has passed for debounce
    if (currentButtonState != previousStates[i] && (millis() - lastDebounceTime[i]) > debounceDelay) {
      lastDebounceTime[i] = millis(); // Update the debounce time

      ledStates[i] = !ledStates[i]; // Toggle the state of the LED
      digitalWrite(ledPins[i], ledStates[i]); // Update the LED state

      Serial.print("Button");
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.println(ledStates[i]);

      previousStates[i] = currentButtonState; // Update the previous button state
    }
  }
}

void readPotentiometers() {
  for (int i = 0; i < numButtons; i++) {
    int potValue = 1023 - analogRead(potentiometerPins[i]); // Read the potentiometer value
    //has analog value changed more than the filter amount ?
    if (abs(lastValue[i] - potValue) > filter) {
      if (lastValue[i] != potValue) {
        //update to the new value
        lastValue[i] = potValue;
        Serial.print("Potentiometer");
        Serial.print(i + 1);
        Serial.print(": ");
        Serial.println(potValue);
      }
    }
  }
}

void checkHeartbeatTIMER() {

  //is it time to toggle the heartbeatLED ?
  if (millis() - heartbeatMillis >= 500ul) {
    //restart this TIMER
    heartbeatMillis = millis();

    //toggle the heartbeatLED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }
} //END of checkHeartbeatTIMER()

```

wiring:

 ![Screen Shot 2023-06-03 at 21.49.57](https://europe1.discourse-cdn.com/arduino/original/4X/3/d/b/3db40ab0d6d4823615c8e62a58a0725b65f55fa5.png)

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [June 3, 2023, 7:04pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/10 "2023-06-03T19:04:06Z")

</div>

> [@hk\_jh](#):
>
> On breadboard?

No.  
Breadboard and short cables usually works rather well. Know the digital uncertainty in the last bit, the half bit issue. A real value of 55.5 will be alternating between 55 and 56. Totally normal.

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [June 3, 2023, 7:06pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/11 "2023-06-03T19:06:11Z")

</div>

How is this built in reality? Camera and picture......

---

<div class="post-metadata">

**Author:** ![hk\_jh](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hk_jh/32/1013044_2.png) [@hk\_jh](https://forum.arduino.cc/u/hk_jh)\
**Post date:** [June 3, 2023, 7:08pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/12 "2023-06-03T19:08:00Z")

</div>

![PXL_20230603_190701124](https://europe1.discourse-cdn.com/arduino/original/4X/2/d/0/2d006cdf82a746367bb4fe6f4a78f68798e0d1c7.jpeg)

---

<div class="post-metadata">

**Author:** ![madmark2150](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@madmark2150](https://forum.arduino.cc/u/madmark2150)\
**Post date:** [June 3, 2023, 7:18pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/13 "2023-06-03T19:18:16Z")

</div>

Yeah, you're going to have noise with that. Stable readings need stable connections. LSB is 5mV, 50mV is +-10 counts. Get a terminal shield and power distribution board and screw everything down.

 ![20230217_170447](https://europe1.discourse-cdn.com/arduino/original/4X/d/4/8/d48774b218ca99ff1b46f59d77cb9bdf7bfcc845.jpeg)

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [June 3, 2023, 7:25pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/14 "2023-06-03T19:25:36Z")

</div>

Thanks. That's a radio receiver.

---

<div class="post-metadata">

**Author:** ![PieterP](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@PieterP](https://forum.arduino.cc/u/PieterP)\
**Post date:** [June 3, 2023, 8:03pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/15 "2023-06-03T20:03:03Z")

</div>

Try using a combination of digital filtering and hysteresis, e.g. [Arduino Helpers: 1.FilteredAnalog.ino](https://tttapa.github.io/Arduino-Helpers/Doxygen/d3/dbe/1_8FilteredAnalog_8ino-example.html).

---

<div class="post-metadata">

**Author:** ![tom321](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tom321/32/1126662_2.png) [@tom321](https://forum.arduino.cc/u/tom321)\
**Post date:** [June 3, 2023, 8:09pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/16 "2023-06-03T20:09:33Z")

</div>

> [@hk\_jh](#):
>
> I'm still having some noise

what is sowing serial plotter ?

---

<div class="post-metadata">

**Author:** ![Wawa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wawa/32/1211303_2.png) [@Wawa](https://forum.arduino.cc/u/Wawa)\
**Post date:** [June 3, 2023, 8:37pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/17 "2023-06-03T20:37:53Z")

</div>

Try this.  
Leo..

```arduino
void readPotentiometers() {
  for (int i = 0; i < numPots; i++) { // numPots, not numButtons
    potvalue = analogRead(potentiometerPins[i]; // dummy read
    int potValue = analogRead(potentiometerPins[i]); // swap the outside pot wires to use this

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 30, 2023, 8:38pm UTC](https://forum.arduino.cc/t/noise-from-potentiometer-reading/1134290/18 "2023-11-30T20:38:29Z")

</div>

Closed on November 30, 2023, 8:38pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
