CYTHEIA AIOpen the editor

Thermistor Thermometer

A thermistor and a fixed resistor form a divider the Arduino reads. The sketch turns the voltage back into degrees Celsius.

Open this circuit and run it

Opens in your browser with the parts, wiring and code already in place. Press Run to watch it work, then change anything you like.

How it works

A thermistor is a resistor whose resistance changes with temperature. This one is an NTC (negative temperature coefficient) type: 10 kilohms at 25 degrees Celsius, and less as it warms. An Arduino cannot measure resistance, only voltage, so the thermistor is put in a divider with a fixed 10 kilohm resistor: 5 volts, then R1, then the thermistor to ground, with A0 on the point between them. At 25 degrees the two are equal and A0 sits at half the supply, about 512. Warm it up and its resistance falls, so less of the 5 volts is across it and the reading drops.

The sketch works backwards. From the reading it finds the thermistor’s resistance with ohms = 10000 × raw ÷ (1023 − raw), which is the divider equation turned round. Then the beta equation turns resistance into temperature: kelvin = 1 ÷ (1 ÷ 298.15 + log(ohms ÷ 10000) ÷ 3950), and subtracting 273.15 gives Celsius. The number 3950 is the thermistor’s beta, a figure from its datasheet. The Serial tab shows the resistance and the temperature twice a second. The reading comes from the circuit solver, so it follows the real wiring: swap the two parts round and the reading goes the other way.

Parts

Wiring

Arduino code

// Thermistor Thermometer
// 5 V - R1 - A0 - thermistor - GND. A0 reads the voltage across the thermistor.
const float SERIES_OHMS = 10000.0;   // the fixed resistor, R1
const float NOMINAL_OHMS = 10000.0;  // the thermistor's resistance at 25 C
const float BETA = 3950.0;           // how steeply its resistance changes with temperature

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

void loop() {
  int raw = analogRead(A0);
  if (raw <= 0 || raw >= 1023) {
    Serial.println("Check the wiring: A0 should sit between R1 and the thermistor");
  } else {
    float ohms = SERIES_OHMS * raw / (1023.0 - raw);
    float kelvin = 1.0 / (1.0 / 298.15 + log(ohms / NOMINAL_OHMS) / BETA);
    float celsius = kelvin - 273.15;
    Serial.print("Thermistor: ");
    Serial.print(ohms);
    Serial.print(" ohms   ");
    Serial.print(celsius);
    Serial.println(" C");
  }
  delay(500);
}

Try changing it

Open this circuit and run it

Next challenge

More projects in Analog Electronics