Help please - Thermistors without a maths lesson?

Hello all
I'm trying to find a short (one line?) piece of code to convert the analog reading on a pin (the divider is a thermistor to ground, resistor to positive) to temperature in Celcius (rounded to no decimal places)

I've searched several times and keep getting lectured in maths, with several lines of code that I really don't want or need. I've tried to combine them and get a wildly inaccurate reading.
Does anyone have a one liner for the Steinhart equation.... that I can put values in for the thermistor, resistor and Vcc etc?

Very surprised there isn't one that I can find?


If you want any accuracy at all, you need the maths.

Each thermistor is different and one example equation simply doesn't cover it.

What accuracy do you need -- there are many other options than thermistors.

The calculation will be done as several steps, why not just code it that way to make it clear what is going on?

What is the resistance of the thermistor at 25C (10k is common).
What is the value of the pull up resistor.
What is the temp range you want to measure.
What do you want to measure (air, water, heatsink).

Perhaps I was a bit economical with my situation...
I'm happy with the workings of a thermistor, just wanted a simplified piece of code... eg

J = 3977 /(or whatever the manufacturer states for his particular thermistor)
R1 = 9980 / (or whatever the resistor measures)
Rt = 10000 /(at 25 C, 298.15 K if you prefer, as stated by the manufacturer)
Vcc = 5.1 / (I'd rather not use the 3.3v internal so it will be measured from the 7805 driving it)
T = some function of J, R1, Rt and Vcc?

After trawling through so many search engine results it seemed everyone was just copy/pasting the code from the same guy... who was doing a fair job of explaining all the maths. Nothing wrong in that but its just not what I wanted and at my age I really cant be bothered with a maths lesson, or multiple formulae spanning several lines of code, taking up memory I haven't got to spare (both my own and that of the chipset (which is running several other tasks poor thing) ;0)

To answer the questions I've had so far - for which I'm truly grateful, from memory I think the component I was going to use this time had a constant of 3977, 10k resistance at 25 degrees C and must be grounded rather than coupled to the Vcc rail, the other resistor taking the analog pin up to the Vcc rail will be around 10K but components vary so I'm happy with having to measure them and declare them as constants etc. Although I might make R1 a fixed (5k?) resistor and a centrered (10k) preset so I can trim it more easily than rewriting/uploading the code while the sensor is sitting in a mug of melting ice.

Basically I am looking at the UK weather, measuring internal/external air temperatures every minute or so, not that this affects the line of code I was hoping for above? As described I'll be calibrating to zero C. Doesn't need to be desperately accurate - to a whole degree is fine.
Sorry to have to add so much blurb - I was just hoping someone had developed a one-liner from the multiple formula examples widely posted, they could share?
Might be a rather boring little post, this one, but it might also help others whose brains cant/don't want/need to be on Steinhart's level.


Examples in the Playground: Arduino Playground - Thermistor2

If you're still not clear on how to implement the examples then you need to post your FULL code and we can provide advice on any mistakes you made.

In the future you would probably find it simpler to implement a digital sensor like a DS18B20 for temperature reading.

In my book thermistors are for things like thermostats.
Semiconductor solutions are more predictable, and have a constant resolution over a wide temp range.
Try the (waterproof) DS18B20.

Accurate thermistor equation for a real device are fairly complex - the physics is not straightforward as
with a diode temperature sensor. Device variation is large too.

If you want good accuracy (standard deviation I measured between many devices around 0.1C),
the DS18B20 is excellent. And the only maths is multiplying by 1/16th of a degree C
(value * 0.0625)

For good accuracy in measuring air temperature you need to use a sensor in a plain metal can, not black epoxy,
not painted or anodized metal, bare metal. Far infra-red heat radiation is absorbed strongly by most organic
materials like plastics and glass, and can cause a degree or two of error.

I considered but rejected several temp senders, preferring the simpler route.
Except the maths lessons weren't simple.

If anyone has used a digital and so called 'one wire' sensor an automotive application do let me know?
( I wondered if car road-surface temperature sensors are digital or analog ? )

I'm worried about the interference you get from very noisy environments, from experience it would need considerable suppression, screened (2 core?) cable etc and end up being far more complex and costing at least ten times that of a thermistor at the end of a length of cheap speaker cable?

Then theres the poor installation techniques I can expect from the end-users twisting wires together or earthing via a literally rusty chassis (but a high impedance thermistor would barely notice that) or worse still coiling the extra length of spare cable around in a nicely inductive loop as they are too scared to cut and solder the connections... you will be amazed what end users actually do to your lovely circuits.

I appreciate all the help though.
It looks like I'll have to stick with a dozen or more formulae, or get a maths tutor ... LOL line

// 10k NTC serial 2k7 resistor.  Beta 3950
float tempc , s ;  // deg Celsius
void setup()
void loop()
  tempc = 1/(log(0.27*(1023-s)/s)/3950.0+(1/298.15))-273.15;    // calc. temp
  Serial.println(tempc); //  deg  C