Newbie with a thermistor

Hi everyone. I’ve just got my first electric imp and also bought a thermsitor off ebay.
I’m having trouble getting some sensible readings out of it.
I have the thermistor connected as per the attached image. However, I have used a 100K thermistor (i think?) and a 100K resistor.

Heres my device code which is giving me readings around -273 degrees C. I have also tried setting the t0 constant as 25 but that doesn’t change much.

#require "Thermistor.class.nut:1.0.0"
const b = 3950.0;
const t0 = 298.15;
const r = 100000.0;
NTC <- Thermistor(hardware.pin5, b, t0, r);
local temp = NTC.readC();

And the specs from the ebay listing for the thermistor:

NTC Thin Film Thermistor Cable 
Nominal value: R25 (25 ℃) : (common) 1.5K, 2K, 5K, 10K, 20K, 30K, 47K, 50K, 100K, 200K, 500K, etc
Resistance precision: ± 1%, ± 2%, ± 3%
B value R25/50 (common) 3435k, 3600k, 3950k, 3990k, 4100k, 4200k, etc
B value accuracy: ± 1%
Temperature range of use: - 40 ℃ ~ + 300 ℃
Dissipation power factor: ≥5 mW / ℃ (static in the air)
Biggest power rating: 45 mw
Hot time constant: ≤7 s(in the air)
Temperature coefficient of resistance: - 2 ~ 5% / ℃
Recommend the use of parameters: R25℃ = 100 k B25/50 = 3950 k ± 1%)

Any ideas?

I’m not too familiar with thermistor use, and haven’t used the thermistor.nut class yet … but your diagram appears to show a 10k resistor in the divider, not 100k as you indicate.

First thing might be to simply verify the components you’re using to make sure you indeed have a 100k thermistor and matching resistor. (I think you should just be able to measure your part with a multimeter at 25c to verify it’s a 100k device).

Also, just curious, (if I understand the use of r correctly), why are you averaging over 100,000 readings … r = 100000.0 ?

This implies that there’s a bad connection somewhere, got a voltmeter to check? At 25C pin5 should be at about 1/2 VCC (1.65v).

Having 100,000 readings may well cause a problem too as the calculation may overflow. I’d suggest averaging far fewer readings… like 10 or 100.

Also worth noting that with a 100kΩ NTC we recommend using an Op-Amp to buffer the signal for higher accuracy. This is because a small amount of current is pulled into the ADC when it is sampled (called ADC Charge Injection) which causes the voltage to change which throws off the accuracy of your readings (if I recall it’s about 1.5°C error). If you switch to a 10kΩ NTC and resistor the error is reduced by a factor of 10 so it’s within the accuracy of the NTC.

Thankyou everyone for your help. I incorrectly thought that the r const was meant to be the resistance of my resistor! makes sense now and it seems to have fixed the problem. I am now getting more sensible readings.
brandon, thanks for the heads up regarding the inaccuracies of the 100kΩ thermistors. I will switch to a 10kΩ.
I was also a little confused by all the data on the spec sheet. So you’re telling me that the only value that matters is the B value? Or more specifically, setting the right combination of B value and average operational temperature?
Does it even matter what value resistor i use? I chose a 100kΩ to match the 100kΩ thermistor. Would it change much if I used a 10kΩ resistor instead?

When using the Thermistor Squirrel class it doesn’t matter what the nominal resistance value is assuming that the other half of your resistor divider is the same nominal resistance (ie you must use a 100kΩ resistor with a 100kΩ NTC, 10kΩ with 10kΩ). If you want to use a different value you will need to modify the class. Using a matched value provides the greatest accuracy and dynamic range though, so you want to do it unless you have a really good reason not to.

This also allows us to do something tricky with the math which means we don’t even need to know what the nominal resistance is. This is because if we set up a 10kΩ resistor with 10kΩ NTC divider it behaves identically to 100kΩ/100kΩ, as both will yield 1.65V at t0. This means that the only information you need in software is the B value and the t0.