# Adventures In Precision: Dirty Thermistor Secrets

August 6, 2020
Posted in Guides
August 6, 2020

## Lets Dive In

Thermistors, to the uninitiated, are simple. They’re a resistive element that either increases or decreases in resistance based on their temperature. NTC (Negative Temperature Coefficient) resistors are more common in sensing circuits and their resistance decreases as temperature increases. Positive Temperature Coefficient (PTC) devices do just the opposite and are often used as re-settable fuses, but that’s another story. The beta value on the datasheet is used to figure out temperature curves. Boom, now you know about thermistors, simple right? Well, almost.

NTC resistors would be easy if they were linear, but they’re not so we have to math them into submission in order to get good readings.  Today we’re going to go over why a NTC based temperature sensor needs logarithms, coefficients, and exponents to be reasonably useful. You’re going to be a pro if you hang with it. I promise.

# Problem: Datasheets Are Garbage

## The Beta value is pedestrian, and you’re better than that

Beta is a coefficient used to describe how much the resistance changes over a temperature range. It’s also unfortunately a lie of omission.  The problem is that the range where this value is stated is often much narrower than the operating range of the device. One of the consequences of working in the electronics industry for any substantial period of time is that eventually you realize that datasheets are marketing materials disguised as a technical reference. If a specific operating point is stated on its own, its pretty safe to assume that its the best case scenario for the part.  Take a look at a sample thermistor specification below:

See the problem? B25/85 refers to a coefficient of resistivity change between 25-85 C (50 degree window). The operating range of the part is -40 – 150C though (190 degree range!)

“So I can just apply that same beta value over the whole range and call it good right?  – Any reasonable person

## NOPE

Datasheets are misleading. Don’t get catfished by a PDF. If you only use the thermistor in the range where Beta is defined, and use the Beta equation for temperature/resistivity you’ll get pretty good results, but you’re cheating yourself. For a wide range (like…you know…the whole operating range) this equation is more error prone than your drunk uncle at Thanksgiving. Manufactures like it because it limits the range where devices have to be in spec and opens up their manufacturing tolerances. So they mislead you by stating a narrow range for accuracy and a wide range for operation.

Cowards.

# Steinhart and Hart Save The Day (with slide rules)

In 1968, Dr. John S. Steinhart and Dr. Stanley R Hart published a much more accurate equation called the Steinhart-Hart equation. This equation is going to beef up your accuracy, and it’s barely a footnote in their impressive histories. They did it before spreadsheets, so no excuses not to use it today. All the cool engineers are doing it.

There’s a little bit of math that goes into calculating the coefficients, but plenty of calculators available if you just want to get going quickly. What makes this equation beautiful is that it more closely models the material properties of thermistors, and only requires taking measurements at 3 points across the whole temperature range to be really accurate. You can expand out the original infinite series as far as you’d like, but this form is the most common and practical.

Check it out:

# Determine A,B, and C

“Okay, sweet equation, but dude what happens now? You cant just screenshot Wikipedia and put gifs on it.” – My editor, if I had one

# How To Actually Use This Equation

As a design engineer, you need to turn this equation into hardware, so lets get after it. The thermistor changes resistance in a known way now, but we actually need the inverse of the Steinhart-Hart equation to make it useful.

If we put the thermistor in a voltage divider, we’ll get a voltage proportional to temperature, which an ADC can work with. Use this equation to find resistance. (excel helps)

There are a couple steps to set up your voltage divider.

In Arduino land, the ADC spans 0 to 3.3V or 5V by default depending on your flavor. Any error in the power supply can then get mixed in with your measurement system. Protip though, it’s pretty common for micro controllers to have internal precision voltage references, though they’re usually at a lower voltage than the supply voltage. The Arduino Uno (ATmega328P) has an internal 1.1V reference, so I suggest pulling a fast one and using the free precision reference like the professional you are.

The bottom end of an ADC isn’t always the most reliable either, so as a rule of thumb I suggest shaving off the bottom 100mV of ADC range. That leaves us with an actual desired voltage range of 100mV to 1V in this scenario. Your results may be different, but just use 80% of the ADC between ground and whatever reference voltage you have available and you’ll be good. Some ADCs are decent and don’t require this. I’ve been burned before by bad ADCs though so healthy skepticism is encouraged.

# Step 2: Choose the other resistor to get your desired range

I generally put the NTC thermistor in the top half of the voltage divider so that voltage increases with temperature, though there’s nothing wrong with it being in the bottom. Plug in your maximum temperature to the equation above to determine your lowest thermistor resistance. Using this resistance and your supply voltage, you can size the other resistor so the output voltage is at the high end of your ADC (1V in our case) at the highest temperature.

# Step 3: Check your cold resistance voltage

Plug in the lowest temperature you’re expecting and see what voltage your divider is going to spit out. The closer it is to the bottom end of your ADC range, the better. The goal here is to match the ADC range to the temperature range we care about. It’s going to take some tuning, but if you made it this far, you’re already committed.

# How we do this at Velocity Research

We use these enough that its worthwhile for us to automate a bit of it. There’s two parts that really matter in designing an effective system.

1. How well does the ADC range match the temperature range?
2. How much resolution does the ADC have in the most important sub range?

The voltage output of the thermistor/resistor divider is non linear, so the voltage sensitivity to temperature is not uniform. In ADC land, this means that even though the Steinhart-Hart equation can give us an accurate temperature based on the voltage, in certain areas of the temperature range we cant resolve as many discrete temperature levels. Accuracy and precision are different things.

## Accuracy

Here you can see the nonlinear equation in practice. I block out the bottom and top ends of the ADC and make sure the voltage divider output is in the right voltage and temperature ranges. We have a few different sensors in this system, with different ranges of interest.

## Precision

Here we take a look at how many ADC counts/degree Celcius our system has and apply some conditional formatting to visualize it. Notice how the water sensors have a different range than the heater? That’s because in the application, those sensors see a smaller temperature range, so we designed the circuit to be more sensitive in the ranges we care about. The heater has to cover a broader temperature range, but uses the same ADC. We tuned it for a wider range, at the expense of some precision.

# Moral of the Story: Thermistor’s aren’t simple if you care about accuracy (and precision)

Most times when using a thermistor, engineers just run with the Beta value, because that’s in the datasheet and the math is easy. If your application is important though, the Steinhart-Hart equation is the way to go. The hardware is exactly the same, its just a matter of writing your software to use this fit instead. Math coming to save the day is one of my favorite parts of being an engineer.

# Do the right thing, and use Steinhart-Hart for all of your thermistor curve fitting.

## Stay Plugged In

Be the first to hear what’s new at Velocity

(We’ll never share or sell it)

Contact

## Let's start the conversation.

Whenever you’re ready, feel free to reach out. We’re here to help!

### Coffee

We love to host, and are excited to hear about your project! Join us for a cup of coffee in our new space and we’ll take an hour to brainstorm.

### Email

If you’d like to put more of your thoughts down, email us directly at info@velocityr.com, and we’ll get back to you within 24 hours.

### Call

We’re ready to answer any of your questions! Call (616) 607-6357 to connect to a team member. If you’re in a hurry, we’ve got a chat icon that connects you directly to a representative.

Contact