Loading... Please wait...

Thermistor

Thermistor

This example shows how to use a thermistor to tell the temperature in Fahrenheit and Celsius.

Hardware Required

  • Arduino Board
  • NTCLE100 thermistor supplied in the oddWires kit
  • 10K ohm resistor (one of the 10 supplied in the oddWires kit)

Circuit

To build the circuit, attach one end of a 10k-ohm resistor to GND and connect the other to thermistor. Then attach the other end of the thermistor to Vcc (+5V). Connect the center of the resistor/thermistor join to Analog pin A0. The ambient temperature is proprtional to the analog voltage measured.

 

arduino-thermistor-voltage-divider-bb.png

Code

/*
 * Inputs ADC Value from Thermistor/pad resistor voltage divider and outputs Temperature in Celsius and Fahrenheit
 *
 * Utilizes the Steinhart-Hart Thermistor Equation:
 *
 *    Temperature in Kelvin = 1 / (A + B[ln(R)] + C[ln(R)^2 + D[ln(R)]^3)
 *
 *    where R = ratio of the measured resistance to the reference resistance (R25)
 *
 *    and A, B, C, D are the Steinhart & Hart parameters for the thermistor
 *
 */

#include

#define thermistorPin A0                // Analog Pin 0

#define A 3.354016e-03                  // For NTCLE100 10k thermistor
#define B 2.569850e-04                  // For NTCLE100 10k thermistor
#define C 2.620131e-06                  // For NTCLE100 10k thermistor
#define D 6.383091e-08                  // For NTCLE100 10k thermistor

#define thermistorR25 10000             // R25 value for your thermistor (nominal value)

float padResistance = 9982;             // the measured resistance of your pad resistor                                      

float steinhartAndHart(int rawADC) {
  float resistance = padResistance*((1024.0 / rawADC) - 1);
  float LnRes = log(resistance/thermistorR25);
  float temp = 1 / (A + (B * LnRes) + (C* pow(LnRes, 2)) + (D * pow(LnRes, 3))); //
  return temp - 273.15;  // Convert Kelvin to Celsius                      
}

void setup() {
  Serial.begin(9600);
}

void loop() {
 
  float temp = steinhartAndHart(analogRead(thermistorPin));       // read ADC and  convert it to Celsius
  Serial.print("Celsius: ");
  Serial.print(temp, 1);                          // display Celsius
  temp = (temp * 9.0)/ 5.0 + 32.0;                // convert to  Fahrenheit
  Serial.print(", Fahrenheit: ");
  Serial.println(temp , 1);                       // display  Fahrenheit
  delay(5000);                                    // Delay 5 seconds
}

 

What's News

newsletter

Copyright 2019 oddWires. All Rights Reserved.
 Sitemap | oddWires