Background:
I am using an Arduino Mega connected to a RoboClaw 2x60A motor driver. I asked this question about the system, but I have since narrowed the scope of the problem. I tried adding a bunch of different size capacitor between the 5v and gnd, when the RoboClaw is switched off then a 470 micro farad capacitor seems to eliminate all noise but when I turn on the RoboClaw no capacitance valued I tried, (4.7,10,100,220,320,470,540,690,1000,1100)microfarads seems to eliminate any noise. I even tried hooking up a 12v battery with a 5v regulator to the logic battery on the RoboClaw and connecting it to the ground on the Arduino. Then I tried using a separate battery for the pots and connecting the AREF to the +5v on the battery.
No matter what I try when the roboclaw is on the potentiometer value will vary as much as +-6 degrees. I found the degrees using:
map(analogRead(A0),0,1023,0,300)
In addition I took a bunch of data and graphed it and found that if I took 25 instantaneous data points and averaged them together it would help significantly reduce the variance. I chose 25 because it take 2.9 ms, 100 worked really well but it took 11 ms. To help explain the averageing of analog read, here is my code:
unsigned int num = 0;
for (int i = 0; i<25; i++){
num+=analogRead(A0);
}
potReading = num/25;
My Question:
What is my next step in eliminating this noise? Is there a formula I can use to find a better capacitance value? Should I try putting capacitors on each potentiometer between 5V and gnd? Any other IC I should try to help with this? On my previous question someone mentioned optocouplers, what size would work best and where in the circuit do they go? Is there code I can write to help eliminate the size of the variance beyond what I have written?
Thanks so much for any help, Joel