Is this a good averaging method ?

I am trying to average out my voltmeter so my screen is somewhat stable, but all i see is a delay in response. is it ok ? or any other idea ?

{for (int i = 0; i < 10; i++)
{
  V1 = ((ads.readADC_SingleEnded(0)) * 0.0001875) * 7;
  V2 = (((ads.readADC_SingleEnded(1)) * 0.0001875) - 0.588) * 20;
  V3 = (((ads.readADC_SingleEnded(2)) * 0.0001875) - 0.588) * 10;
  V4 = ((ads.readADC_SingleEnded(3)) * 0.0001875) * 8;
  delay(1);
}
{
  V1 = V1;
  V2 = V2;
  V3 = V3;
  V4 = V4;

bogdan666:
is it ok ?

No

you are not averaging anything, just overwriting 10 times the same readings into the same variables and this is totally useless

  V1 = V1;
  V2 = V2;
  V3 = V3;
  V4 = V4;

(the compiler will likely get rid of it)

an average is the sum of some data divided by the number of data elements

V1 = 0;
V2 = 0;
V3 = 0;
V4 = 0;
for (int i = 0; i < 10; i++)
{
  V1 += ads.readADC_SingleEnded(0) * 0.0001875 * 7.0;
  V2 += (ads.readADC_SingleEnded(1) * 0.0001875 - 0.588) * 20;
  V3 += (ads.readADC_SingleEnded(2) * 0.0001875 - 0.588) * 10;
  V4 += ads.readADC_SingleEnded(3) * 0.0001875 * 8.0;
  delay(1);
}
V1 /= 10;
V2 /= 10;
V3 /= 10;
V4 /= 10;

I had hoped @bogdan666 would come back with some updated code of his own.

but hey, here you go full solution curtesy of @pcbbc :wink:
(just make sure to have the right type for V1, V2, V3 and V4)

an alternative is keeping the previous value and merging it with the new reading with some coefficient, for example 90% of the previous value plus 10% of the new reading if you want to smooth out changes or if you want fast reaction to change increase the %age for the new reading.

Wouldn't it be easier to sum the raw readings, and do the conversion arithmetic on the averaged values?

Are you sure you really need it?...
A RC at the input could be a simpler solution. You could also make a 2nd order filter, using a 10x resistor in the second filter.
You also have to make sure that the ground circuit is correct, otherwise it adds noise to the reading.

Thank you for the answers, the code works ok. As if i really need it, it looks like the simplest solution at the time.

unsigned int smooth(unsigned int newVal) {
  static unsigned int oldVal = 0;
  unsigned long sum;
    //  optimize sum = (oldVal * 3 + newVal) / 4;
    sum = ( (oldVal << 1) + oldVal + newVal) >> 2;
  }
  oldVal = sum;
  return oldVal;
}
...
  V1 = smooth( ads.readADC_SingleEnded(0) );
  V2 = smooth( ads.readADC_SingleEnded(1) );
...