Here I will show how to build a Digital Thermometer based on an Arduino Uno that uses a KTY81 Silicon PTC (Positive Temperature Coefficient) sensor to measure ambient temperature and display it on an I2C OLED screen.
Hardware & Circuit Diagram
Below is the circuit diagram of the KTY81 Digital Thermometer with Arduino for accurate temperature measurement.
Here is a breakdown of how it works:
1. The Sensing Circuit (Voltage Divider)
The heart of the measurement is the voltage divider on the left. It consists of a $1\text{k}\Omega$ fixed resistor ($R_1$) and the KTY81 sensor.
The Physics: The KTY81 is a PTC sensor, meaning its resistance increases as the temperature rises.
The Signal: By connecting $R_1$ to $+3.3\text{V}$ and the KTY81 to Ground, a variable voltage is created at the center point (connected to A0). As the temperature goes up, the sensor's resistance increases, which causes the voltage at A0 to increase.
2. High-Precision Reference (AREF)
A key feature of this specific circuit is the yellow wire connecting the $+3.3\text{V}$ rail to the AREF pin.
Standard Arduinos use the $+5\text{V}$ rail as a reference, but $+5\text{V}$ can be "noisy."
By using the stable $+3.3\text{V}$ regulator as an External Reference, the Arduino can measure the sensor much more accurately, preventing the temperature reading from jumping around.
3. Data Processing (Arduino Uno)
The Arduino Uno performs three main tasks:
Analog-to-Digital Conversion: It converts the analog voltage at A0 into a digital number ($0$ to $1023$).
Resistance Calculation: Using Ohm's Law in the code, it calculates the exact resistance of the KTY81 based on that voltage.
Linear Translation: It converts that resistance into Celsius. Since the KTY81 is $1000\Omega$ at $25^\circ\text{C}$, the code calculates the "offset" from that point to determine the current temperature.
4. The Output (OLED Display)
The processed temperature is sent via the I2C bus (using pins A4/SDA and A5/SCL) to the SSD1306 OLED display.
The display shows the word "Temperature" as a header.
The large numbers show the live reading (e.g., $17.1^\circ\text{C}$) in the center of the screen for high visibility.
Programming & Coding
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const int sensorPin = A0;
const float R_FIXED = 1000.0; // 1k resistor
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.setTextColor(WHITE);
// --- Initial Message ---
display.clearDisplay();
// Line 1: Main Title
display.setTextSize(1);
display.setCursor(15, 6);
display.print(F("KTY81 THERMOMETER"));
// Line 2: Smaller Website Name
display.setTextSize(1);
display.setCursor(30, 18);
display.print(F("ee-diary.net"));
display.display();
delay(3000);
analogReference(EXTERNAL);
}
void loop() {
int rawADC = analogRead(sensorPin);
// 1. Calculate Voltage (3.3V AREF)
float vOut = rawADC * (3.3 / 1023.0);
// 2. Calculate actual Resistance of KTY81
float rKTY = R_FIXED * (vOut / (3.3 - vOut));
// 3. KTY81 Temperature Calculation
float temperatureC = 25.0 + (rKTY - 1000.0) / 7.9;
display.clearDisplay();
// Header: Just "Temperature"
display.setTextSize(1);
display.setCursor(30, 0);
display.print(F("Temperature"));
// Centering Logic
display.setTextSize(2);
// Estimate text width for centering:
// (Digits + Decimal + Space + 'C')
int textWidth;
if (temperatureC >= 100 || temperatureC <= -10) textWidth = 84;
else if (temperatureC < 0 || temperatureC >= 10) textWidth = 72;
else textWidth = 60;
int xPos = (SCREEN_WIDTH - textWidth) / 2;
display.setCursor(xPos, 14);
display.print(temperatureC, 1);
display.print(F(" C"));
// --- Draw Degree Symbol ---
// We place a small circle before the 'C'
// x position is adjusted based on text length
int degreeX = xPos + textWidth - 21;
display.drawCircle(degreeX, 16, 2, WHITE);
display.display();
delay(500);
}
In the measurement phase, the code reads the voltage from a divider circuit containing the KTY81 sensor. It mathematically reverses the voltage divider formula to find the sensor's exact resistance in Ohms. Since the KTY81 is a Positive Temperature Coefficient (PTC) sensor, the code uses a linear scaling factor—specifically accounting for the fact that the sensor is 1000 Ohms at 25°C—to translate that resistance into a Celsius temperature.
Finally, in the display phase, the code focuses on a professional user interface. It calculates the width of the temperature string in real-time to ensure the value is always perfectly centered on the 128x32 pixel screen. To overcome the limitation of standard fonts, it uses a geometric circle-drawing function to manually render a degree symbol, resulting in a clean, polished visual display on the OLED LCD.
Video demonstration
Related Tutorial
