I'm using a 5k pot as an angle sensor for a robor arm joint, but I'm getting unstable readings (+- 2)
Software averaging is ok, but I would need to do it in hardware. Is this the best that can be done, or can I improve it somehow, by adding some capacitors (which ones) or perhaps using a lower resistance potentiometer?
The accuracy of the ADC of the ATMega chips is already +- 2. Also, the linearity of an inexpensive potentiometer is around 5%. I don't think you can improve what you have.
If you need more accurate values you would need to move to an optical encoder.
Analog read is 0 to 1023. You can use "map" and convert the reading to 0 to 360 degrees. You would get 3 times the less sensitivity or in a way it would seem like the potentiometer was 3 times more accurate because the noise would not show up as much.
If your scaling was 0 - 180 the effect would be even larger.
Chargin & cyclegadget
Thank you very much for your answers. I'll settle for this accuracy, and will use optical encoders for the next project.
Best
amatic
I'm using a 5k pot as an angle sensor for a robor arm joint, but I'm getting unstable readings (+- 2)
you can use multiple readings and average them
value = 0;
for (int i=0; i< 16; i++) value += analogRead();
value /= 16;
or use a lowpass filter
value = value - 0.1 * (value-analogRead()); // same as value = 0.9 * value + 0.1 * analogRead(); but optimized.
Difference the lowpass filter makes the system less responsive, and only needs one analogRead().
I think Chargin & cyclegadget are confusing accuracy and stability.
The normal stability for any A/D converter can only ever be +/- 1 so at a stability of +/- 2 there is room for improvement.
Yes a capacitor would help damp down any noise pickup. A 0.1uF across the wiper of the pot and ground will help. As will a software solution like that filter above.
@Rob Tillaart
Yes, I am using the lowpass filter as a software stabiliser.
@GrumpyMike
Thank you, I will try the 0.1uF capacitor.