This example demonstrates how to measure temperature using a 10k NTC thermistor with a B-parameter of 3950. The thermistor forms a voltage divider with a 10kΩ resistor, and the Arduino reads the midpoint voltage. Using the Steinhart-Hart equation, the thermistor’s resistance is converted into temperature in:
/*
* © 2024 Copyright Peter I. Dunne, all rights reserved.
* Prepared for educational use.
* The ADC is 10 bit, this is of relatively low accuracy, use professional test equipment for accuracy.
* Released under the Mozilla Public License
* Arduino UNO with 10k NTC Thermistor and B-parameter of 3950
* Measures temperature and converts it to Kelvin, Celsius, and Fahrenheit.
*/
const int thermistorPin = A0;
const int referenceResistor = 10000;
const float B_coefficient = 3950;
const float nominalTemperature = 298.15; // 25°C in Kelvin
const float nominalResistance = 10000;
const float VRef = 5.0;
const int maxADCValue = 1023;
void setup() {
Serial.begin(115200);
Serial.println("Arduino NTC temperature measurement, by Peter Ivan Dunne, ©2024, all rights reserved");
Serial.println("Released under the Mozilla Public License");
Serial.println("https://jazenga.com/educational");
}
void loop() {
int adcValue = analogRead(thermistorPin);
float voltage = (adcValue / float(maxADCValue)) * VRef;
float thermistorResistance = referenceResistor * ((VRef / voltage) - 1);
float steinhart;
steinhart = thermistorResistance / nominalResistance;
steinhart = log(steinhart);
steinhart /= B_coefficient;
steinhart += 1.0 / nominalTemperature;
steinhart = 1.0 / steinhart;
float temperatureC = steinhart - 273.15;
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print("Temperature: ");
Serial.print(steinhart, 2);
Serial.print(" K, ");
Serial.print(temperatureC, 2);
Serial.print(" °C, ");
Serial.print(temperatureF, 2);
Serial.println(" °F");
delay(1000);
}
thermistorResistance = referenceResistor * ((VRef / voltage) - 1);
steinhart = thermistorResistance / nominalResistance;
steinhart = log(steinhart);
steinhart /= B_coefficient;
steinhart += 1.0 / nominalTemperature;
steinhart = 1.0 / steinhart;
temperatureC = steinhart - 273.15;
temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;