Saturday, November 13, 2010

The $2 Thermistor Temperature Sensor

A thermistor makes for a very inexpensive temperature sensor, under $2 for the thermistor and the 10k ohm resistor, not counting the $45 for the Arduino and LCD display:



#include <LiquidCrystal.h>
#include <math.h>

/*
LCD Connections:
rs (LCD pin 4) to Arduino pin 12
rw (LCD pin 5) to Arduino pin 11
enable (LCD pin 6) to Arduino pin 10
LCD pin 15 to Arduino pin 13
LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2

Thermistor Connections:
Thermistor Pin 1 to +5v
Thermistor Pin 2 to Analog Pin 0
10k ohm resistor pin 1 to Analog Pin 0
10k ohm resistor pin 2 to Gnd
*/

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backLight = 13;    // pin 13 will control the backlight



void setup(void) {
  pinMode(backLight, OUTPUT);
  digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
  lcd.begin(20, 4);              // rows, columns.  use 16,2 for a 16x2 LCD, etc.
  lcd.clear();                   // start with a blank screen
  lcd.setCursor(0,0);            // set cursor to column 0, row 0
}

double Thermistor(int RawADC) {
  double Temp;
  // See See http://en.wikipedia.org/wiki/Thermistor for explanation of formula
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
  Temp = Temp - 273.15;           // Convert Kelvin to Celcius
  return Temp;
}

void printTemp(void) {
  double fTemp;
  double temp = Thermistor(analogRead(0));  // Read sensor on Pin 0
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Temperature is:");
  lcd.setCursor(0,1);
  lcd.print(temp);
  lcd.print(" C, ");
  fTemp = (temp * 1.8) + 32.0;    // Convert to Fahrenheit
  lcd.print(fTemp);
  lcd.print(" F");
  if (fTemp > 68 && fTemp < 78) {
    lcd.setCursor(0,3);
    lcd.print("Very comfortable");
  }
}

void loop(void) {
  printTemp();
  delay(1000);
}

5 comments:

  1. Thank you Mark (Hacktronics), for the code and components.

    ReplyDelete
  2. hello, we have NTC 10d-11 thermistor, but we don`t understand formula, which digits to change on it. Now arduino show us 80C instead of 20C :)
    Maybe you can help us ? :)

    ReplyDelete
  3. The piece we used is 10k Ohm resistance at 25C. If yours is different, you will need to change the formula:

    Temp = log(((10240000/RawADC) - 10000));
    Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));

    as described in http://en.wikipedia.org/wiki/Thermistor

    ReplyDelete
  4. our resistance is 10 ohm!
    we used this formula:
    Temp = log(((10240000/RawADC) - 10));
    Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
    now arduino shows room temperature 23 C, when we insert sensor in to cold water it shows: 21 C

    ReplyDelete
    Replies
    1. You probably don't care for this anymore, but just in case someone else comes along wondering about this. I determined the steinhart-hart constants experimentally. For the NTC10D-11, which has a 10 ohm resistance at 25 C, I found a = 2.66*10^-3, b = 3.11*10^-4 and c = 1.2535*10^-6. I wasn't very rigorous in determining these, so they aren't very accurate. My readings are about 5 degrees off.

      Delete