I'm trying to read voltage using Arduino, here's the code:
float r1 = 99700;
float r2 = 10004;
float adc, voltage;
unsigned long analog;
void setup() {
Serial.begin(9600);
analogReference(EXTERNAL);
pinMode(A0, INPUT);
}
void loop() {
for (int i = 0; i < 64; ++i) {
analog += analogRead(A0);
delay(1);
}
analog = analog / 64;
adc = (analog * 2.441) / 1024;
voltage = adc / (r2 / (r1 + r2));
Serial.print(analog);
Serial.print(", ");
Serial.print(adc);
Serial.print(", ");
Serial.print(voltage);
Serial.println(" ");
}
Had a VERY noisy reading and what I did was adding an external voltage reference (TL431) and also connected a 9V switching adapter to Arduino UNO. But I still had some noise in analog readings so as you can see in the code I'm taking 64 sample and averaging them.
After doing all those noise reduced a lot but not completely:
What else should one do to get an steady reading?
By taking 1024 sample noise will be removed but then I'm sacrificing performance...