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 Runs in your browser. Free, and no account needed.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// 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);
}
Parts list
5 parts, plus the jumper wires. Every one is in the editor's parts bin.
How it is wired
9 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Arduino Uno R3 pin 12; Character LCD, 16x2 pin D7
- Arduino Uno R3 pin 11; Character LCD, 16x2 pin D6
- Arduino Uno R3 pin 10; Character LCD, 16x2 pin D5
- Arduino Uno R3 pin 9; Character LCD, 16x2 pin D4
- Arduino Uno R3 pin 8; Character LCD, 16x2 pin E
- Arduino Uno R3 pin 7; Character LCD, 16x2 pin RS
- Arduino Uno R3 pin 5V; Thermistor, 10k NTC pin 1; Character LCD, 16x2 pin VDD; Character LCD, 16x2 pin A
- Ground: Arduino Uno R3 pin GND; Resistor, 10k Ω pin 2; Character LCD, 16x2 pin VSS; Character LCD, 16x2 pin V0; Character LCD, 16x2 pin RW; Character LCD, 16x2 pin K
- Arduino Uno R3 pin A0; Thermistor, 10k NTC pin 2; Resistor, 10k Ω pin 1
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.