Thermistor on A0, degrees on an LCD (pins 4, 6, 10 to 13), on an Arduino Uno
A 10k pull-up from 5 V to A0 and a thermistor from A0 to ground; the beta equation shows Celsius and Fahrenheit on a 16x2 LCD wired to pins 4, 6 and 10 to 13. 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.
What you'll learn
- A thermistor at the bottom of a divider
- Converting a reading to resistance and then temperature
- Wiring an LCD to any free pins
- Clamping the reading to avoid a divide by zero
- Difficulty: Intermediate
- Time: About 25 minutes
- Board: Arduino Uno R3
- Parts: 5
How it works
This is a thermometer with a different LCD wiring. A 10k pull-up from 5V to A0 and a 10k NTC thermistor from A0 to ground make a voltage divider. When the thermistor warms, its resistance falls and so does the reading on A0.
The sketch finds the resistance, then uses the beta equation (10k at 25 C, beta 3950) to get kelvin, and then Celsius and Fahrenheit.
The 16x2 LCD uses RS on pin 4, E on pin 6 and D4 to D7 on pins 10 to 13. The top row shows Celsius and the bottom shows Fahrenheit, updated every half second.
Parts list
5 parts, plus the jumper wires. They retail for about $35; on Mokxi they're free.
- 1 × Arduino Uno R3In Starter Kit, Claw Machine Kit, Vending Machine Kit.
- 1 × Full-size breadboard
- 1 × Thermistor, 10k NTC
- 1 × Resistor, 10k ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × Character LCD, 16x2
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 pin | Connects to |
|---|---|
| Character LCD, 16x2 pin D7 | Arduino Uno R3 pin 13 |
| Character LCD, 16x2 pin D6 | Arduino Uno R3 pin 12 |
| Character LCD, 16x2 pin D5 | Arduino Uno R3 pin 11 |
| Character LCD, 16x2 pin D4 | Arduino Uno R3 pin 10 |
| Character LCD, 16x2 pin E | Arduino Uno R3 pin 6 |
| Character LCD, 16x2 pin RS | Arduino Uno R3 pin 4 |
| Resistor, 10k Ω pin 2 | Arduino Uno R3 pin 5V |
| Character LCD, 16x2 pin VDD | Arduino Uno R3 pin 5V |
| Character LCD, 16x2 pin A | Arduino Uno R3 pin 5V |
| Thermistor, 10k NTC pin 1 | Arduino Uno R3 pin GND |
| Character LCD, 16x2 pin VSS | Arduino Uno R3 pin GND |
| Character LCD, 16x2 pin V0 | Arduino Uno R3 pin GND |
| Character LCD, 16x2 pin RW | Arduino Uno R3 pin GND |
| Character LCD, 16x2 pin K | Arduino Uno R3 pin GND |
| Thermistor, 10k NTC pin 2 | Arduino Uno R3 pin A0 |
| Resistor, 10k Ω pin 1 | Arduino 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.
// A thermometer: a thermistor on A0, Celsius and Fahrenheit on the LCD.
//
// 5V -> 10k resistor -> A0 -> thermistor -> GND
// LCD RS -> pin 4 LCD E -> pin 6
// LCD D4 -> pin 10 D5 -> pin 11 D6 -> pin 12 D7 -> pin 13
// LCD RW, VSS, K -> GND VDD, A -> 5V
// LCD V0 (contrast) -> GND here; on the bench, the middle leg of a pot
//
// The thermistor is at the bottom of the divider: as it warms its resistance
// falls, and so does the reading on A0. From the reading the sketch works out
// the thermistor's resistance,
//
// R = 10000 * reading / (1023 - reading)
//
// and the beta equation (10k at 25 C, beta 3950) turns it into kelvin.
//
// Drag the thermistor's temperature and watch the display.
#include <LiquidCrystal.h>
#include <math.h>
const int SENSOR = A0;
const float BETA = 3950.0;
const float R25 = 10000.0;
LiquidCrystal lcd(4, 6, 10, 11, 12, 13);
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
Serial.println("Mokxi Uno: thermistor on A0, LCD on pins 4, 6 and 10 to 13");
}
void loop() {
int reading = analogRead(SENSOR);
if (reading < 1) reading = 1;
if (reading > 1022) reading = 1022;
float resistance = R25 * reading / (1023.0 - reading);
float kelvin = 1.0 / (1.0 / 298.15 + log(resistance / R25) / BETA);
float celsius = kelvin - 273.15;
float fahrenheit = celsius * 1.8 + 32.0;
lcd.setCursor(0, 0);
lcd.print("Temp: C ");
lcd.setCursor(6, 0);
lcd.print(celsius, 1);
lcd.setCursor(0, 1);
lcd.print("Fahr: 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 LCD with lcd.begin(16, 2) and the serial port at 9600 baud. The pins are set by the LiquidCrystal lcd(4, 6, 10, 11, 12, 13) line at the top, in the order RS, E, D4, D5, D6, D7.
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
Serial.println("Mokxi Uno: thermistor on A0, LCD on pins 4, 6 and 10 to 13");
}loop sketch.ino
Reads A0 and clamps it between 1 and 1022, so the math never divides by zero. It works out resistance, kelvin, celsius and fahrenheit. It rewrites the two row labels, then prints each number at column 6. It also 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 * reading / (1023.0 - reading);
float kelvin = 1.0 / (1.0 / 298.15 + log(resistance / R25) / BETA);
float celsius = kelvin - 273.15;
float fahrenheit = celsius * 1.8 + 32.0;
lcd.setCursor(0, 0);
lcd.print("Temp: C ");
lcd.setCursor(6, 0);
lcd.print(celsius, 1);
lcd.setCursor(0, 1);
lcd.print("Fahr: 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 is blank or shows boxes This project
The pin order inLiquidCrystal lcd(4, 6, 10, 11, 12, 13)is RS, E, D4 to D7. It must match your wires. - The temperature goes down when you warm the sensor This project
The thermistor goes between A0 and GND, with the 10k resistor on the 5V side. - 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). - Garbled characters or a blank display even with good contrast. Character LCD
In 4-bit mode only D4 to D7 are used, and D0 to D3 stay unconnected. Tie RW to GND. Match the pins in LiquidCrystal(rs, en, d4, d5, d6, d7) exactly to your wiring.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.