Noise on reading a potentiometer

Hi All,

My question might be very simple for some of you. I have an Arduino Uno, and I want to read a potentiometer. Very simple. The problem is the noise. Is there any way that I decrease the noise? For example, when the potentiometer is fixed on a value, I don't see any fluctuation (even small ones) in the serial monitor.

Thanks

Is the potentiometer a new one? How do you have it wired? Is you "noise" only when moving the slider on the potentiometer?

you can decide to ignore some of the least significant bits

by dividing
int stableValue = analogRead(A0) >> 2;

or just canceling out the LSbs you don't want
int stableValue = analogRead(A0) & 0b1111111111111100;

1 Like

Yes, it is. The noise is around 10-20 in the range of 0 to 1023. But I don't want this as well. I want a fixed number when the slider is fixed.
No, I can see the noise even when the slider is static.

And it is wired how?

Great thanks J-M-L. It worked perfectly. But could you please explain a bit about the code you sent me and how they function?

Thank you

basically you read the value but you ignore what's going on in the low bits.

with the & 0b1111111111111100 masking you nullify the 2 low bits (corresponding to 0,1,2 and 3)

➜ if you read 0, 1, 2 or 3 you'll see 0
➜ if you read 4, 5 ,6 or 7, you'll see 4
➜ if you read 8,9,10 or 11, you'll see 8
etc

with the >> 2, it's dividing by 4
➜ if you read 0, 1, 2 or 3 you'll see 0
➜ if you read 4, 5 ,6 or 7, you'll see 1
➜ if you read 8,9,10 or 11, you'll see 2
etc

Be aware of the noise during conversion... I've used the adc a lot, but have never had a noise problem.

The datasheet for the 328p states ... section 23.6

"The ADC features a noise canceler that enables conversion during sleep mode to reduce noise induced from the CPU core and other I/O peripherals."


I would think you have something lose or not properly connected. As @Paul_KD7HB has stated... we need a schematic.

If the 'pot' on your input is of a reasonable value the impedance is low, so noise from the pot is probably not the issue.

If you have problems with the noise you might have to put it to sleep during the conversion for the lowest noise ... I'd look elsewhere first.

Good luck

:smiley_cat:

The schematic is very simple. Three wires from Arduino (GND, A0, and 5V) are connected to a potentiometer through a breadboard. Could you please explain a bit more about the noise reduction through this sleep mode? I have never heard of it.
Please see this video at the selected moment. There are noises when the pot is static.
https://youtu.be/t9DEAreCD3g?t=265

I guess you were asking @jkwilborn

Yes. You are right. Sorry.

I watched the video, I think you have some kind of mechanical connection issue...

What is the ohm value of the pot ... 10k ... same as the video?

You should not need to do anything with the sleep issue with this setup... However, I'll include the link to my copy of the 328p datasheet. I posted the section previously... 23.6


I think you should check your connections and pot ... something is changing or you wouldn't read different values with it static.

Good luck

:smiley_cat:

The last time I read the long data sheet, that referred to the CPU being stopped for two cycles while the A/D conversion takes place. It is automatically done each time, not a programmed "sleep" mode.

Add a 100nF capacitor from wiper to ground.

From the posted document...


23.6 ADC Noise Canceler

The ADC features a noise canceler that enables conversion during sleep mode to reduce noise
induced from the CPU core and other I/O peripherals. The noise canceler can be used with ADC
Noise Reduction and Idle mode. To make use of this feature, the following procedure should be
used:

  1. Make sure that the ADC is enabled and is not busy converting. Single Conversion
    mode must be selected and the ADC conversion complete interrupt must be enabled.
  2. Enter ADC Noise Reduction mode (or Idle mode). The ADC will start a conversion
    once the CPU has been halted.
  3. If no other interrupts occur before the ADC conversion completes, the ADC interrupt
    will wake up the CPU and execute the ADC Conversion Complete interrupt routine. If
    another interrupt wakes up the CPU before the ADC conversion is complete, that
    interrupt will be executed, and an ADC Conversion Complete interrupt request will be
    generated when the ADC conversion completes. The CPU will remain in active mode
    until a new sleep command is executed.

Note that the ADC will not be automatically turned off when entering other sleep modes than Idle
mode and ADC Noise Reduction mode. The user is advised to write zero to ADEN before entering such sleep modes to avoid excessive power consumption.


I read this as a suggestion to reduce noise during conversion... no?

I don't think they have a need to go this far for such a simple configuration...

:smiley_cat:

My guess is that the root cause of the problem is due to the way that you have wired up the potentiometer. Individual wires will pick up 50Hz or 60Hz (dependent on your territory) mains 'hum'.
This means that the wire from the wiper to the analogue input will have the required signal with a 50Hz/60Hz signal superimposed on it. Because the Arduino's ADC takes an instantaneous reading, then the result will vary depending on where abouts in the mains cycle the conversion takes place.

You can reduce the mains hum by using screened cable or you could twist the three wires together.

You can reduce the noise as suggested.

Another thing to keep in mind is adding some hysteresis to your analog input code, so the reading won't change until the pot has moved a certain amount away from the last reading.

This works better in some cases than simply chopping off the bottom bits, as it would eliminate the fluctuations that would still occur when near a transitions.

    newReading = analogRead(signalPin);
    if (abs(newReading - currentReading) > 15)
      currentReading = newReading;

would stick with the old reading until you'd scootched the pot a bit.

I hope, can't test that code from right here.

Google hysteresis and find @6v6gt's very thorough tutorial:

HTH

a7

Or take an average of multiple readings spread across one full 50 or 60 Hz cycle. .

That should not happen.
+/- one value, yes. But not 10-20.
Hardware problem.
Don't try to fix with software. Find the problem.
Leo..

1 Like

Makes you wonder what ACTUAL code the compiler generates for the analog read.