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.
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.
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
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 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.
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.
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:
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.
Enter ADC Noise Reduction mode (or Idle mode). The ADC will start a conversion
once the CPU has been halted.
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...
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.
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.