• At first glance, you are overwriting temp each time through the loop, instead of summing it as I think you mean to do. Well-chosen variable names could help you here.

    I would recommend that you only sum together your readings in the for loop, then get the average after the loop finishes and then calculate the temp based on the average, as this could avoid some roundoff error, but it may not matter too much because the sensor isn't very accurate.

    The analogRead() has 10 bits of accuracy, so it should return a number between 0 and 1023 which I don't see you compensating for.

    So I think your calculations would go something like this:

    Ravg = Rsum / numSamples // where Ravg is the average of your Readings. Note that Ravg will be a number between 0 and 1023

    Vavg = (Ravg * E.getAnalogVRef()) / 1023 // This will be the average reading in Volts

    MVavg = Vavg * 1000mV / 1V // convert to millivolts

    Tavg = (MVavg - 400mV) * (1 degree Centigrade) / (19.5 mV) // shift the curve downward and convert to centigrade

    This would make much more sense on a blackboard as it is just basically calculation by keeping track of units or whatever its called. The code obviously would be simpler since you won't be needing to multiply or divide by 1, etc.

    Your Fahrenheit conversion looks fine. No promises that I haven't goofed up somewhere :)
    Keep us posted on progress, thanks!

    P.S. Google says that one guy factored the internal resistance into his calculations, I don't know if E.getAnalogVRef() does that. If not and you did want to factor that in, you would make a change like this:

    Vavg = Ravg * (E.getAnalogVRef() - Vir) / 1023
    where Vir is the voltage drop from internal resistance, in volts

    P.P.S. I guess they call it the factor-label method of dimensional analysis - LOL!

About

Avatar for Manxome @Manxome started