Temperature Measurement using Arduino and a Thermistor

17 07 2009


  • Arduino Duemilanove Board, a USB cable and of course a PC/Mac
  • A 10kOhm thermistor
  • A 10kOhm resistor
  • A breadboard wires

Hot topic

It’g getting hotter and hotter. Is it due to global warming? Who knows, but in the meanwhile we can measure the temperature with our Arduino board and a thermistor. A thermistor is simply a type of resistor whose resistance varies with temperature. If we knew how it varies, we could extract the temperature from the measurement of the resistance (or, better, the voltage across its ends).

The Steinhart-Hart equation

In first approximation, the resistance is proportional to the temperature:

R = k(T-T0)

This can work for a narrow temperature range, but we can figure out something more accurate, up to the third order:

1/T = A + B logR + C ( logR )^3

The temperature T is expressed in Kelvin, the resistance R in Ohm and the parameters A, B and C must be determined experimentally, or taken from the datasheet.

If you want to be even more rigorous, you have to include a self-heating effect in the picture. I’ll give it as a black-box formula:

T = T(steinhart-hart) – V^2 / k*R

Where k is the dissipation constant, usually given in units of mW/degree C.

Setting things up

In this case the setup is really simple. First of all, connect the Arduino board to the computer (in my case, it’s a Mac) via the USB cable. Now, connect the GND terminal to the B line of the breadbord (use a black wire), and Arduino’s +5V output to the A line (use a red wire). Now, put the 10kOhm resistance between the (+) bus and a horizontal line. Now, connect the thermistor between the horizontal line you chose and the (-) bus, the common ground. Last but not least, connect Arduino’s Analog Input #0 to the horizontal line (X).

(+5V) —- R —- X —- Th — GND

Programme Arduino

Now, the geek part. We have to teach Arduino how to calculate the temperature and give us the answer.

#include <math.h>
#define READING_PIN 0

double R1 = 10000.0; //resistance put in parallel
double V_IN = 5.0;

double A = 1.129148e-3;
double B = 2.34125e-4;
double C = 8.76741e-8;
double K = 9.5; // mW/dec C – dissipation factor

double SteinhartHart(double R)
// calculate temperature
double logR  = log(R);
double logR3 = logR * logR * logR;

return 1.0 / (A + B * logR + C * logR3 );


void setup() {

void loop() {
double adc_raw = analogRead(READING_PIN);
double V =  adc_raw / 1024 * V_IN;
Serial.print(“V =”);

//calculate resistance
double R_th = (R1 * V ) / (V_IN – V);
Serial.print(“V   R_th = “);

double kelvin = SteinhartHart(R_th) – V*V/(K * R_th);
double celsius = kelvin – 273.15;
Serial.print(“Ohm  —   T = “);

Compile it and send it to Arduino. Open up the Serial Terminal, and enjoy the output stream.

Now it’s up to you

Probably, the temperature you’re measuring is quite unconvincing. You have to set up the coefficient according to you thermistor. This will be covered in a following post…



20 responses

26 10 2009
Temperature Measurement | Engineer Sphere

[…] Temperature Measurement using Arduino and a Thermistor « Beyond … […]

19 11 2009

Thanks dude! Exactly what I needed. As you said for me the values are a little off, still great work! :D

12 02 2010
Johannes Findorf

Nice post. Got it working in minutes. However my measurings are like this:
V =4.21V R_th = 53602.48Ohm – T = 7.32C
The temperature should be about 20C, so I guess that I might have a Th with some other characteristics.
I believe that it is a NTC like the one at page 10 in this pdf http://www.seeedstudio.com/depot/datasheet/catalyst.pdf, but I’m not entirely sure. I brought a “Arduino kit” with some diffrents parts, though there was no partlist other than the one found here http://www.makershed.com/ProductDetails.asp?ProductCode=MSAPK2

But hey, thank for your post!

12 07 2010

Thank ya buddy! :)

11 09 2010

GREAT !!! You solved my thermistor problem, many thanks !
What I do not understand is:
You write:
1/T = A + B logR + C ( logR )^3
and later in the code:
return 1.0 / (A + B * logR – C * logR3 );
so first it is + C… and in the second formula it is – C…
I’m using + C… in the code too and get the correct results.

19 10 2010
Riccardo Di Sipio

I guess it’s a typo ;) thx

18 10 2010

error: stray ‘\’ in program In function ‘double SteinhartHart(double)':
In function ‘void loop()':

19 10 2010
Riccardo Di Sipio

This problem usually arises when you copy a text from the browser to the source code. It’s a problem with character encodings

10 02 2011

I get really wrong calculations?
I dont understand this code 100% but when i heat up my NTC, the resistance goes up and temperature goes down?
So there gotta be some mistake in it

11 02 2011

i know whats wrong..
the resistance calculate part is wrong
when i type r_th=10000 it says temperature is 25 degree
im noob in elektronics math so im going to figure out how to fix this
can any1 help?

11 02 2011

i found the solution!!!!

//calculate resistance
double R_th =((10240000/adc_raw) – R1);

this is the correct calculation
i checked it with a 90 euro thermometer and its like 100% accurate:D
so im pretty happy to have the solution after some hours googling

16 02 2011

double R_th=((VinxR1/Vout)-R1);

lets say Vin = 5volt(standard on arduino)
R1 = 10k ohm
Vout = 3volt

so the calculation will be:

double R_th=((5×10000/3)-10000);
so R_th = 6666 ohm

Hope this helped clearing this part of the formula up=D

12 03 2011
Ray Perkins

A different approach (may not be better)…
I used the Arduino to output raw data (0 to 1024 read off an AtoD). Grabbed a table of numbers (over a wide temp. range) and their corresponding temperatures as read by another thermometer. Pasted the 2 columns of data into Excel. Plotted a scatter graph. Selected Chart/Add Trendline, with options 2nd order polynomial and to show Display Equation on chart. Select equation on chart and use Format/Select Data Labels to increase accuracy of formula.
Voila! – Excel gives you the equation which you can put into the Arduino, or, in my case, a VB6 app.

1 06 2011

Wow first of all great explanation!
So i’m trying to get a thermistor working, and i read a lot about the steinhart-hart. And everywhere it says you can get values A,B,C either experimentally or from the datasheet.
Not having any thermometer, i would like to use the datasheet values.
But i do not understand which values, and how to use them.

I have an NTC 10D-11:
so at 25c it has a resistance of 10ohm.
From the datasheet(http://simon-jd.com/admin/file_download.asp?table_name=info&table_id=442&table_order=3):
R25±20% (Ω): 10
Max Current (A): 3
Approx. Resistance in Max. Current at 25c (Ω): 0.275
Dissipation Power (mW/c): 14
Time Constant (s): 47
Out of these i can only use the dissipation factor. How do i get A,B,C without measuring a bunch of points?

30 12 2011
PC fan controller | Jeff's projects

[…] for me, instead of having to code this monstrous equation, someone has already done it:  https://disipio.wordpress.com/2009/07/17/temperature-measurement-using-arduino-and-a-thermistor/.  I just enter R1, A, B, and C, and it does all of the […]

15 01 2012
PC fan controller | Jeff's projects

[…] for me, instead of having to code this monstrous equation, someone has already done it: https://disipio.wordpress.com/2009/07/17/temperature-measurement-using-arduino-and-a-thermistor/. I just enter R1, A, B, and C, and it does all of the […]

15 04 2012

mhh when i put my finger on the Thermistor i am getting lower temperature values. Why?

13 11 2012

Can someone suport me the library math.h??? i need him pliss

26 11 2012
Arduino Kegerator « Business Unusual

[…] Also, there’s heat created when voltage is sent through the thermistor, and the datasheet gives a “Thermal Dissipation Constant.”  To account for this I subtracted a few degrees from the measurement based on this constant. […]

27 12 2012
Electronics Club Fans

I might have a Th with some other characteristics.http://www.hqew.net

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 541 other followers

%d bloggers like this: