# Averaging Thermistors from Raw values

I have 2 thermistors connected to my mega. Right now, The thermistor library dumps degrees in F for each. What I have done is for a "rate" of 1000 millis I add each reading and then increment a counter so I know 1. the total all of those temperature and 2. the amount of readings that make up that sum. I then divide the total by the readings number to get an average over about one second. This means that each reading requires math to come up with the values (all of them) and then more math to computer the average. What I would like to do is take the raw read from each, add THAT then divide by the number of readings THEN convert to a temperature one time. I believe that this would further streamline the sketch. I have checked online, but to no avail. I am calling on the wisdom of this forum to see if this is possible to do.

here is the way I average the temperatures:

``````temperature = temp.getTemp();
tempTotal = tempTotal + temperature;

gtemperature = gtemp.getTemp();
gtempTotal = gtempTotal + gtemperature;
//////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////CALCULATE TEMERATURE AVERAGES///////////////////////////////////////////
if ((currentRate - previousRate) > rate) {
tempAverage = 0;
rounded_up = ceilf(tempAverage * 100) / 100;

float avgForpH = ((rounded_up - 32) / 1.8);
gtempAverage = 0;
float grounded_up = ceilf(gtempAverage * 100) / 100;
``````

Sure, you could average the raw reads. I can't think of any obvious problem with that, except that averaging depends on a linear reading, and the raw thermistor response is non linear. So the accuracy would suffer.

I havent the slights clue how to do that and since I cant find an example, not too sure what to do.

So don’t do it. The first method you explained should work fine.

Puzzled that you say that you don’t know how to do it since you did explain your proposal. I assumed that you understood your own proposal.

Love it when I answer my own questions... Thanks for letting me know it is possible.

``````tempTotal = tempTotal + wRawADC;

//////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////CALCULATE TEMERATURE AVERAGES///////////////////////////////////////////
if ((currentRate - previousRate) > rate) {
wtemp = log(Resistance);
wtemp = 1 / (0.001129148 + (0.000234125 * wtemp) + (0.0000000876741 * wtemp * wtemp * wtemp));
wtemp = wtemp - 273.15;  // Convert Kelvin to Celsius

wtempA = (wtemp * 1.8) + 32.0; // Convert to Fahrenheit
roundedforph = ceilf(wtemp * 100) / 100;
rounded_up = ceilf(wtempA * 100) / 100;
////////////////////////////////////////////////////////////////////////////////////////////////////////////