Cheap temperature sensing with MCU

I'd say NTC, yes. This one is the cheapest I could find at Digikey. About half a dollar, that's much cheaper than temperature sensor ICs, which have about the same precision. The advantage of an NTC is that it only needs a series resistor and an ADC input on your microcontroller, which most do have nowadays.

The low price has also a disadvantage: NTCs are anything but linear. You either have to use its transfer function (that's with an exponential in it, which you may not like, or use a lookup table, which for the given range may be the best solution.

edit dd. 2012-07-13
Bah, beaten by a miserable LM75. I'm not gonna let this pass. :-)

I'm going to use the *103*MT* from this NTC series. First the transfer function:

\$ R = 10 k\Omega \cdot \large{e^{-13.4096 + \frac{4481.80}T - \frac{150522}{T^2} + \frac{1877103}{T^3}}} \$ ,

where \$T\$ is in Kelvin.

Doesn't look promising, and indeed between 0 °C and 100 °C the curve looks like this:

enter image description here

anything but linear, like I said. We can try to linearize that, but remember that we're going to make a resistor divider with it, and they're not linear either, so any linearization now will be ruined by the series resistor. So let's start with the resistor and see what happens. I have a 3.3 V supply and pick a 5.6 kΩ resistor to Vcc, then the output becomes

enter image description here

Not bad at all! The purple curve is the tangent in our range of interest: 30 °C to 35 °C. I could plot the graph zoomed in on that, but that gives us two coinciding lines, so let's have a look at the error:

enter image description here

Doesn't look nice either, but you have to look at the vertical scale, which gives the relative error of the linear approximation compared to our NTC characteristic between 30 °C to 35 °C. The error is less than 15 ppm, or 0.0015 %.

Mathematica say the equation for our nearly perfect linear approximation is

\$ V_{OUT} = - 0.0308 \text{ }T \text{ }\cdot 1 V/°C + 2.886 \text{ }V \$

This will result in ADC readings of 609 and 561, resp. for a 10-bit ADC. That's a range of 48 for a 5 °C difference, or about 0.1 °C resolution. Just the NTC and a resistor.

Who needs an LM75!?



edit dd. 2012-08-13

Fact: the NTC solution needs calibration.

I promised Arik to get back on the error calculation, but it's a lot more complicated than I thought, and it can't be completed because of incomplete data. For instance, I have very precise numbers for the coefficients in the NTC's transfer function (the 7 significant digits numbers are already rounded!), but no information on their accuracy. A few comments though.

Arik adds errors, like 1% resistance tolerance + 1% on the \$\beta\$ = 2 % error. Well, it's not that easy, and that's part of the complication I referred to. A 1 % tolerance on the \$\beta\$ results in a 0.1 % error in the result, for instance.

Errors are not always expressed the same. Maxim's LM75 datasheet, for instance, doesn't mention minimum and maximum errors, but three-sigma and six-sigma values. On the other hand the Vishay NTC datasheet speaks of \$\pm\$ 1 % error. Is that six-sigma? Seven-sigma? Then it may turn out to be more accurate than the LM75, which is 2 °C accurate six-sigma, even 3 °C over temperature range. That's nothing to be ashamed of; few sensors will do much better without calibration. Question: how do you compare tolerance figures? And another one: how do you combine several bell curve functions to get a total error?

The PIC's ADC reference has a pretty bad 6 % tolerance. Arik says An uncertainty of 6% at 300 kelvin is equivalent to an temperature error of 18 K, which of course is preposterous and utterly absurd. I made a quick check: calculated the voltage divider's output for a temperature of 20 °C. Added 6 % to that, and calculated back to the NTC's resistance value, and the temperature that would be. The error is not 18 °C, but 1 °C, or less than 0.5 %, referred to 0 K.

Even so, the 6 % error is completely irrelevant! If you use the ADC's reference voltage for the resistor divider that voltage doesn't even appear in the calculations. I wouldn't care if the error was 50 %. Use another reference if the bad internal reference isn't available outside the controller. Like the 3.3 V power supply, or just any other DC voltage you have laying around.

The calibration is not what you want for a one-off project, but for mass-production it's no worry at all, and especially in consumer electronics, where every cent counts, you'll more likely find the NTC than an expensive LM75.


1-2 degrees is an easy resolution (even when you mean accuracy, which is not the same!). I would consider LM75 and it various clones, or a DS1820/18S20/18B20/1822. Microchip has a lot of temperature sensors, including LM75 clones for < $1. The voltage output versions are cheap, but I would prefer a digital one.


This sounds like a job for a thermistors, or two thermistors to be more precise. Since you only need to distinguish three different temperature states and you are only looking for relative temperature, you can connect the two thermistors together to make a single analog signal. That can then be measured with a A/D built into the micro. Most micros have A/Ds, so this won't cost anything more. I'd probably add a couple resistors and capacitors as a low pass filters to reduce noise.

One thermistor goes from ground to the analog signal and the other from power to the analog signal. You may need to do some calibration, but with your narrow temperature range and low resolution you don't need to get fancy. Probably just saving the zero-difference voltage and subtracting that from future reading is enough.