This is probably a simple problem with an easy solution:
I've built a voltage divider circuit, running through a potentiometer with power from the board into one of the analog pins. I'm sending this direct into Max/MSP (since I'm unfamiliar with the Arduino language, and it would get sent to Max anyway).
The problem is that the reading is jittery, bouncing up and down by 5-8 values in either direction. I've tried methods of programming this out, but I feel like the problem might be more easily solved with a hardware modification.
One thing suggested, which I haven't yet tried, is that an external (non-USB) power supply might be better - though a bummer because then the device isn't self-contained.
Thanks! Any suggestions would be greatly appreciated.
Maybe your pot is dirty ?
A variation of 5 to 8 values out of 1024 is not very much (relatively speaking) if the little slide contact inside the pot is dirty it might touch the carbon track of the pot at different places causing the jitter.
Try another pot or try to clean the one you are using with a suitable cleaning spray.
what value pot do you have?
One thing you might try is using a local regulator for the pot… You could use a 3 terminal 3.3 volt linear regulator which should remove most disturbances on the 5V from the USB connector.
This will mean you don’t get the full range of values from the ADC. If this is important, you could connect the VRef pin to the 3.3V (and configuring it in code). This should give you the full adc range.
Something else you might try is a little cap to ground from the slider of the pot…
To rule out slider noise, as suggested by MikMo, you could wire up the equivalent of the pot at midrange using two resistors each half the value of the pot’s value. If you still get the variation, you know it isn’t the pot…
five values either direction is to be expected with an adc of this type I believe.
If you look at many peoples code they do things in comparisons like not switching values until the change is greater than five to take this into account.
Microcontroller ADCs are very sensitive to the output impedance of the analog circuit that is feeding the ADC port... internally has an RC circuit, so "charging time" is what determines the value of the analog input, converted to a digital value. If impedances do not match, you get inconsistent readings. But +-5 is not bad... you can use averaging method to smooth the result of the ADC.