The analog temperature sensor in your Sensor Kit (the KY-013) doesn't know anything about degrees. Inside it is a thermistor: a resistor whose resistance changes with temperature. The UNO can only measure a voltage, so getting from that voltage to "21.4 °C" takes three steps, and that's exactly what you'll program in this lesson. On the way you'll meet the voltage divider again, a real formula engineers use for thermistors, and a simple way to check that your thermometer tells the truth.
What you'll learn
- What an NTC thermistor is, and how its resistance changes with temperature
- How the module turns a resistance into a voltage with a voltage divider
- How to work back from the UNO's reading to the thermistor's resistance
- How the B-parameter equation turns resistance into degrees
- How to check and calibrate a home-made thermometer
What you need
- UNO R3 board and USB cable (UNO R3 Starter Kit)
- Analog temperature sensor module KY-013 (45-in-1 Sensor Kit)
- Breadboard and jumper wires (UNO R3 Starter Kit)
- The free Arduino IDE
Wiring
The module has three pins: S (signal), the middle pin (power) and − (GND). The middle pin is power on every version of this module. Follow the labels printed on your board.

| From | To |
|---|---|
| KY-013 S | UNO A0 |
| KY-013 middle pin (+) | UNO 5V |
| KY-013 − | UNO GND |
Build this circuit in EEMENTOR Lab
Wire it yourself in your browser before you touch a real wire. No sign-up, nothing to install.
Build it yourself
- The UNO and this lesson’s parts are already placed. Wire them using the wiring table above. Pins with no wire show red.
- Missing a part? Add it from the parts list on the left.
- Press Run, then try the inputs: click, hold or slide them under Selected.
- Then try this lesson’s sketch: paste it into the Code tab and press Compile & Run.
EEMENTOR Lab is free and in beta. Results are a guide; a real build can differ slightly. About the Lab
The sketch
Copy the sketch into the Arduino IDE, choose Arduino Uno as the board and the right port, and click Upload. Then open the Serial Monitor at 9600 baud.
// Turn the KY-013 analog temperature sensor into a thermometer
// Step 1: read the voltage. Step 2: work out the thermistor's resistance.
// Step 3: turn the resistance into degrees with the B-parameter equation.
const int SENSOR_PIN = A0;
const float R_FIXED = 10000.0; // the 10 kΩ resistor on the module
const float R_25 = 10000.0; // the thermistor's resistance at 25 °C
const float BETA = 3950.0; // the thermistor's B value
const bool NTC_ON_TOP = false; // true if the temperature goes DOWN when you warm the sensor
const float OFFSET = 0.0; // calibration: add or take away a few tenths of a degree
void setup() {
Serial.begin(9600);
Serial.println("KY-013 thermometer");
}
void loop() {
int raw = analogRead(SENSOR_PIN); // Step 1: 0 to 1023
if (raw <= 0 || raw >= 1023) {
Serial.println("Reading at the end of the range: check the wiring.");
delay(1000);
return;
}
float rNtc; // Step 2: the resistance
if (NTC_ON_TOP) {
rNtc = R_FIXED * (1023.0 / raw - 1.0);
} else {
rNtc = R_FIXED * raw / (1023.0 - raw);
}
float kelvin = 1.0 / (1.0 / 298.15 + log(rNtc / R_25) / BETA); // Step 3
float celsius = kelvin - 273.15 + OFFSET;
Serial.print("reading ");
Serial.print(raw);
Serial.print(" resistance ");
Serial.print(rNtc, 0);
Serial.print(" ohm temperature ");
Serial.print(celsius, 1);
Serial.println(" C");
delay(1000);
}
Try it
- Upload the sketch and open the Serial Monitor. Every second you get a reading, a resistance and a temperature. At room temperature the resistance is close to 10,000 ohms, and the temperature is around 20–25 °C.
- Hold the thermistor (the small black bead) between your fingers. The resistance falls and the temperature climbs towards 30 °C. Let go, and it slowly drops back.
-
Check the direction: if the temperature goes down when you warm the sensor, your module is wired the other way round inside. Change
NTC_ON_TOPtotrueand upload again. -
Calibrate it: put the module next to a thermometer you trust and wait five minutes. If yours reads 0.8 °C too high, set
OFFSETto-0.8. - Open Tools → Serial Plotter and breathe on the sensor to watch the temperature curve.
What you should see

How it works

The thermistor on the KY-013 is an NTC type: Negative Temperature Coefficient. That means its resistance goes down as it gets warmer. It is about 10 kΩ at 25 °C, about 26 kΩ at 5 °C, and only about 3.6 kΩ at 50 °C. The change isn't a straight line, which is why we need a formula rather than a simple multiplication.
Step 1, the voltage: the module puts the thermistor and a fixed 10 kΩ resistor in a row between 5V and GND, a voltage divider. The S pin sits in the middle, so its voltage depends on how the two resistances compare. analogRead() turns 0–5 V into a number from 0 to 1023.
Step 2, the resistance: if the thermistor is the bottom half of the divider, the reading is 1023 × R_ntc ÷ (10 kΩ + R_ntc). Turned round, that gives R_ntc = 10 kΩ × reading ÷ (1023 − reading), the line in the sketch. Some modules have the thermistor on top instead, and then the other formula is the right one; NTC_ON_TOP picks between them.
Step 3, the temperature: the B-parameter equation, a simple form of the Steinhart–Hart equation, links resistance and temperature: 1/T = 1/298.15 + ln(R ÷ 10 kΩ) ÷ B. Temperatures in it are in kelvin (298.15 K is 25 °C), and B, here 3950, describes how strongly this thermistor reacts. Take away 273.15 and you have degrees Celsius. The parts on the module aren't perfect, so a reading a little off is normal; that's what OFFSET is for.
Try this next
- Show the temperature on the 1602 LCD from the LCD lesson.
- Record the highest and lowest temperature since the UNO started, and print them every minute without blocking the loop, using what you learned in Do two things at once with millis().
- Compare it with the DS18B20 digital thermometer: put both side by side and see which reacts faster.
- Average ten readings before you convert them, to make the last digit steadier.
Troubleshooting
- "Reading at the end of the range": the reading is 0 or 1023, so the divider isn't working. Check that the middle pin goes to 5V, − to GND and S to A0. If S and − are swapped, you'll also see this message: swap them back (never move the middle pin).
-
The temperature goes down when you warm the sensor: change
NTC_ON_TOPtotrue. -
The last digit jumps around: that's normal. Near room temperature each step of
analogRead()is less than a tenth of a degree, and electrical noise moves it by a step or two. Average several readings. - It reads a degree or two high near the UNO: the board warms up a little while it works. Use longer wires to keep the sensor away from it.