Built-in project · Arduino Uno R3

Thermistor thermometer on an LCD (pins 7 to 12), on an Arduino Uno

A 10k thermistor from 5 V to A0 over a 10k resistor to ground, and the beta equation turns the reading into degrees on a 16x2 LCD wired to pins 7 to 12. The whole build, an Arduino Uno and 3 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Intermediate About 25 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $35. On Mokxi they're free.

Thermistor thermometer on an LCD (pins 7 to 12) · Arduino Uno R3live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

What you'll learn

  • Reading a thermistor in a voltage divider
  • Converting a reading to resistance
  • The beta equation for temperature
  • Wiring a 16x2 LCD in 4 bit mode
  • Difficulty: Intermediate
  • Time: About 25 minutes
  • Board: Arduino Uno R3
  • Parts: 5

How it works

A 10k NTC thermistor and a 10k resistor form a voltage divider between 5 V and ground. The middle point goes to A0. As the thermistor warms, its resistance falls and A0 reads higher.

The sketch turns the reading back into the thermistor's resistance, then uses the beta equation, with 10k at 25 C and a beta of 3950, to get kelvin and then Celsius and Fahrenheit. The 16x2 LCD on pins 7 to 12 shows both, and the serial monitor shows Celsius. It updates every 500 ms.

Parts list

5 parts, plus the jumper wires. They retail for about $35; on Mokxi they're free.

Kits that can build it

These 4 starter kits have every part in the circuit. Each kit's page lists what else it can build.

Wiring table

Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.

Part and pinConnects to
Character LCD, 16x2 pin D7Arduino Uno R3 pin 12
Character LCD, 16x2 pin D6Arduino Uno R3 pin 11
Character LCD, 16x2 pin D5Arduino Uno R3 pin 10
Character LCD, 16x2 pin D4Arduino Uno R3 pin 9
Character LCD, 16x2 pin EArduino Uno R3 pin 8
Character LCD, 16x2 pin RSArduino Uno R3 pin 7
Thermistor, 10k NTC pin 1Arduino Uno R3 pin 5V
Character LCD, 16x2 pin VDDArduino Uno R3 pin 5V
Character LCD, 16x2 pin AArduino Uno R3 pin 5V
Resistor, 10k Ω pin 2Arduino Uno R3 pin GND
Character LCD, 16x2 pin VSSArduino Uno R3 pin GND
Character LCD, 16x2 pin V0Arduino Uno R3 pin GND
Character LCD, 16x2 pin RWArduino Uno R3 pin GND
Character LCD, 16x2 pin KArduino Uno R3 pin GND
Thermistor, 10k NTC pin 2Arduino Uno R3 pin A0
Resistor, 10k Ω pin 1Arduino Uno R3 pin A0

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// Thermometer: a thermistor on A0, the temperature on a 16x2 LCD.
//
//   5V -> thermistor -> A0 -> 10k resistor -> GND
//   LCD RS -> 7, E -> 8, D4 -> 9, D5 -> 10, D6 -> 11, D7 -> 12
//   LCD RW, VSS, K, V0 -> GND     LCD VDD, A -> 5V
//
// A thermistor's resistance falls as it warms. With it on top of a 10k
// resistor, A0 reads more when it is warm and less when it is cold. From the
// reading the sketch works out the thermistor's resistance:
//
//   R = 10000 * (1023 / reading - 1)
//
// and the beta equation turns that into kelvin, using the part's two numbers
// from its datasheet: 10k at 25 C, and a beta of 3950.
//
// Click the thermistor and drag its temperature to watch the display follow.

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

const int SENSOR = A0;
const float BETA = 3950.0;
const float R25 = 10000.0;
const float T25 = 298.15;  // 25 C in kelvin

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);
  Serial.println("Mokxi Uno: thermistor on A0, LCD on pins 7 to 12");
}

void loop() {
  int reading = analogRead(SENSOR);
  if (reading < 1) reading = 1;
  if (reading > 1022) reading = 1022;
  float resistance = R25 * (1023.0 / reading - 1.0);
  float kelvin = 1.0 / (1.0 / T25 + log(resistance / R25) / BETA);
  float celsius = kelvin - 273.15;
  float fahrenheit = celsius * 9.0 / 5.0 + 32.0;

  lcd.setCursor(0, 0);
  lcd.print("Temp     C  ");
  lcd.setCursor(6, 0);
  lcd.print(celsius, 1);
  lcd.setCursor(0, 1);
  lcd.print("Temp     F  ");
  lcd.setCursor(6, 1);
  lcd.print(fahrenheit, 1);

  Serial.print(celsius, 1);
  Serial.println(" C");
  delay(500);
}

Code walkthrough

The key functions of the sketch, and what each one does.

setup sketch.ino

Starts the 16 by 2 LCD with lcd.begin and opens the serial monitor. The LCD pins RS, E and D4 to D7 were given to LiquidCrystal when it was created, in pins 7 to 12.

void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);
  Serial.println("Mokxi Uno: thermistor on A0, LCD on pins 7 to 12");
}

loop sketch.ino

Reads A0 and keeps it between 1 and 1022 to avoid dividing by zero. It works out resistance, then kelvin with the beta equation, then Celsius and Fahrenheit. It writes both onto the two LCD lines, prints Celsius to serial and waits 500 ms.

void loop() {
  int reading = analogRead(SENSOR);
  if (reading < 1) reading = 1;
  if (reading > 1022) reading = 1022;
  float resistance = R25 * (1023.0 / reading - 1.0);
  float kelvin = 1.0 / (1.0 / T25 + log(resistance / R25) / BETA);
  float celsius = kelvin - 273.15;
  float fahrenheit = celsius * 9.0 / 5.0 + 32.0;

  lcd.setCursor(0, 0);
  lcd.print("Temp     C  ");
  lcd.setCursor(6, 0);
  lcd.print(celsius, 1);
  lcd.setCursor(0, 1);
  lcd.print("Temp     F  ");
  lcd.setCursor(6, 1);
  lcd.print(fahrenheit, 1);

  Serial.print(celsius, 1);
  Serial.println(" C");
  delay(500);
}

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The LCD shows blocks or nothing This project
    Check V0, RW and VSS are on GND, VDD and A on 5V, and RS, E, D4 to D7 are on pins 7 to 12 in order.
  • The temperature seems off This project
    The sketch assumes a 10k resistor and a 10k thermistor with a beta of 3950. Use matching values in BETA and R25 if yours differ.
  • The reading goes the wrong way This project
    Keep the thermistor on the 5V side and the 10k on the ground side, with A0 between them.
  • The temperature reads far off or jumps around. Thermistor
    Use a fixed resistor equal to the thermistor's 10k at 25 C in the divider. Convert with the Steinhart-Hart or Beta equation (Beta is about 3950 for common parts), not a straight line.
  • The reading goes the wrong way, or self-heating shifts it. Thermistor
    An NTC lowers its resistance as it warms, so the divider voltage moves with the wiring side. Check which side the thermistor is on. Keep current small, with 3.3 V or 5 V through 10k, so it does not self-heat.
  • The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
    Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure.
  • A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
    Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground.
  • The screen lights up but shows only a row of solid boxes, or nothing at all. Character LCD
    Contrast pin V0 needs a voltage. Connect the middle pin of a 10 k pot to V0, with its ends on 5 V and GND. Also confirm that the code calls lcd.begin(16, 2).

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.