Average of a sensor

robtillaart:

Well first any averaging you do should be done with the raw integer values returned by analogRead() statements, not after you convert them (if you indeed do) to floating point numbers like the 125.5 example you posted.

@lefty

I do not agree on this per se. Averaging of integer values have a truncating error that might be greater than when averaging the converted values.
you can minimize this with rounding.

temptot = 0;

for(x = 0; x < 64; x++)
    temptot += analogRead(LM34Pin);
  temp = (temptot + 32) /64;   // rounding iso truncking



the number to add (32) is half the number of samples you take (64)

BTW Averaging floats is definitely slower than averaging integers.

Well I do not agree per se back. I think as a general rule one should avoid using floating point math all together (if at all possible) on micro-controller applications, just too much code bloat and speed penalty to pay. For an applications like reading a load cell and converting to units of measurement it can all be done in integer math.

Lefty