Fluctuating temperature using NTC

Hello!

I'm using a NTC sensor (from Carel). The problem is that the temperature that is reading is fluctuating a lot even if, in reality, is stable.
What can I do to solve this problem? I really need to solve it because is related with my job!
Thank you!

Can you post your code and schematics?

This is the code:

float Vin = 5.0;
float Rfija = 4630.0;
float R25 = 10000.0;
float Beta = 3495.0;
float T0 = 298.15;

float Vout = 0.0;
float Rntc = 0.0;
float TempK = 0.0;
float TempC = 0.0;

(...)

Vout=(Vin/1024)(analogRead(A0));
Rntc=(Vout
Rfija)/(Vin-Vout);
TempK = Beta/(log(Rntc/R25)+(Beta/T0));
TempC = TempK-273.15;

Rfija - the constant resistor from the divider
The thermistor is connected to the ground (to avoid, as more as I can, high current through thermistor) into divider of tension.

Thank you!

If you just print out the raw values of analogRead()
what do you get?

I have just verified this.
It returns ( at a temperature that is about 19 degrees) this:

701, 703, 702, 703, 701, 704, 702.... and so on... :frowning:

So what you see is the natural noise on the analogRead() --> solution make 32 (or more) analogRead's and average them

snippet:

float sum = 0;
for (int i=0; i< 32; i++) sum += analogRead(A0);
sum /= 32;
Vout=(Vin/1024)*(sum);
Rntc=(Vout*Rfija)/(Vin-Vout);
TempK = Beta/(log(Rntc/R25)+(Beta/T0));
TempC = TempK-273.15;

Thank you very much!!!!

It works, but it has a strange behavior; if "i" is 32 then the temperature that is reading, is lower than real (4 degrees!!!!); if I choose 4, then it says that I have -32 degrees (or something like that) in my room!!!!!! :astonished:.
When I boost the value of "i" it shows more and more accurate (referring to the real temp). I really don't understand why the number of readings affect the VALUE of the temperature in such of strange mode!
Could you, please, explain it? I'm doing something wrong?

Sounds like there are readings that return 0 (outlier) which will invalidate teh average

another way that is more robust for outliers is to use a running average. It does react slower on (fast) changes .

something like

float value;

void loop()
{
value = 0.95 * value + 0.05 * analogRead(A0);  // takes only 5% of new reading into account

Vout=(Vin/1024)*(value );
Rntc=(Vout*Rfija)/(Vin-Vout);
TempK = Beta/(log(Rntc/R25)+(Beta/T0));
TempC = TempK-273.15;
Serial.println(TempC);
}

yet another option is to use my running median library - Arduino Playground - RunningMedian - which has of course its own behavior

I'll try this one too (tonight)!
Thank you !

Hello!

I have just tried your last idea. Works good! It's true, it does react slower, even more when you have some delays in your sketch (like me). I think that when I'll replace the delays I will use this version (last one).
For the moment I'm ok with the previous code but with a higher value of " i " (about 2500). With this value everything works fine (with a little blink of the value - till counts 2500) but isn't annoying.

Thank you very much! You helped me a lot!

for removing delays from your code check the blink without delay example on the tutorial section...

Ok. Thank very much you for all the precious advises!

if you want to speed up code try to remove float divisions too

Vout = (Vin/1024)*(value ); ==> Vout = value * Vin * 0.0009765625; // == 1/1024

TempK = Beta/(log(Rntc/R25)+(Beta/T0)); ==> Beta/( log (Rntc * C1) + C2); // C1 = 1/R25; Beta /T0 is probably const

Wow! I didn't knew it!!!
Thank you!
Now I'm trying to build a menu and I have no idea how! Thanks to you I have finished to build the code for the temperature.

check the playground, there might be some menu examples.

I have found a library quite interesting: "MenuBackend". Let's see if it is useful for me. :slight_smile:

Let us know your experiences...

It's quite complicated to work with this library. I didn't find any explications about the commands of the library. It's difficult to understand the functions just looking to other examples. Don't you think?