A thermistor is a special type of resistor whose resistance changes significantly with the temperature.
Typical Operating Temperature Range: -67 to 490F (-55C - 250C)
If we connect this junction to a microcontroller’s analog input we can read this voltage and run a formula to convert that reading into a temperature…
then we send that reading to a display.
I added a button and additional code to switch between Celsius and Fahrenheit.
Because of the tolerance in the various components, we can’t expect this to be 100% accurate straight away. So I’m going to replace the other 10K resistor with a potentiometer so we can have a way to calibrate it.
A thermistor is another highly valuable sensor you can add to your DIY toolkit. You can buy a pack of 50 for like $7 on Amazon!
This project is more than a practical tool, it’s an excellent introduction to the world of electronics and Arduino.
Arduino Code:
// HackMakeMod - Thermometer with 10K Thermistor
// https://youtube.com/shorts/shXfHpf59CE?si=CbEWt4HFmbot9977
// Code: Chad Kapper
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBold18pt7b.h> // Sweet fonts!
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);
const int thermistorPin = A0;
const float seriesResistor = 10000; // Resistance of the series resistor (10k Ohm)
const int buttonPin = 2; // Pin (default HIGH) for the button to switch from Fahrenheit to Celsius
bool displayTemp = false; // Initial display mode (Fahrenheit=false) (Celsius=true)
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP); // Enable internal pull-up resistor for the button
// Initialize the OLED display
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Infinite loop
}
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
Serial.println("Setup complete.");
display.display();
delay(10);
}
void loop() {
int reading = digitalRead(buttonPin);
if (reading == LOW) { // Button pressed
displayTemp = !displayTemp; // Toggle display mode
Serial.println(displayTemp ? "Displaying Celsius" : "Displaying Fahrenheit");
while (digitalRead(buttonPin) == LOW) {
delay(10); // Debounce delay
}
}
float temperature = readThermistor();
displayTemperature(temperature, displayTemp);
Serial.print("Current Temperature: ");
Serial.print(displayTemp ? temperature : (temperature * 9.0 / 5.0 + 32));
Serial.println(displayTemp ? " °C" : " °F");
delay(100); // Sampling delay
}
void displayTemperature(float temperature, bool displayTemp) {
float temperatureF = (temperature * 9.0 / 5.0) + 32.0; // Calculate Fahrenheit
display.clearDisplay();
display.setTextSize(1);
display.setFont(&FreeMonoBold18pt7b);
String tempStr = String(displayTemp ? temperature : temperatureF, 1);
String unitStr = displayTemp ? "C" : "F";
int16_t x1, y1;
uint16_t w, h;
display.getTextBounds(tempStr, 0, 0, &x1, &y1, &w, &h);
int16_t tempXPos = 128 - w - 30;
display.setCursor(tempXPos, (64 + h) / 2);
display.print(tempStr);
int16_t degreeRadius = 3;
int16_t degreeOffsetX = 10;
int16_t degreeOffsetY = 18;
display.drawCircle(tempXPos + w + degreeOffsetX, (64 + h) / 2 - degreeOffsetY, degreeRadius, SSD1306_WHITE);
display.setFont(&FreeMonoBold9pt7b);
display.setCursor(tempXPos + w + degreeOffsetX + degreeRadius + 3, (64 + h) / 2 - h / 2);
display.print(unitStr);
display.display();
}
float readThermistor() {
float ADCvalue = analogRead(thermistorPin);
float voltage = ADCvalue * 5.0 / 1023.0;
float resistance = (5.0 - voltage) * seriesResistor / voltage;
float temperature = 1 / (log(resistance / 10000) / 3950 + 1 / (273.15 + 25));
temperature -= 273.15; // Convert from Kelvin to Celsius
return temperature;
}