Thermistor, Keyes KY-013


I must admit that if I am going to want to use temperature in a project then I would normally use the output from a BMP 180, real time clock or a digital sensor like the TMP 36. However, I decided to purchase a thermistor and found the KY-013. This tiny board has a thermistor and resisistor mounted on it and there are three pins Gnd, Vcc and Sensor, although my board only showed ‘-‘ and ‘S’.

Trawling around the internet I found that the thermistor needed some complicated formula to get the best results. The Adafruit site had a good tutorial, but the code was a little complicated. The best tutorial, in my opinion, was on the Arduino Playground here. I have included the code, stripped of all the comments, below but I recommend you visit the Arduino playground.

A thermistor is a resistor that has a value that changes with the temperature. The Arduino cannot measure resistance directly, but if a potential divider is made by connecting a resistor equal to the thermistor’s resistance (at about 25 degrees centigrade), voltage can be measured. A normal value for the resistor is about 10k.

Connect the thermistor and resistor together and the common point to Arduino A0, connect the free end of the thermistor to Vcc and the free end of the resistor to Gnd. Upload the sketch and open the Serial Monitor set to 115200, the temperature will be shown. Hold the thermistor, if the displayed temperature goes down then reverse the connections to the thermistor and resistor free ends.

I found that I had to connect the ‘-‘ on the Keyes board to Vcc, the unmarked centre pin to Gnd and the pin marked ‘S’ to Arduino A0. To get the best accuracy you will need to measure the resistor and enter the value into the code below. However, I got good results using the code without any modification.

I found the sensor to be slow, taking almost 30 seconds to return from 32C to 25C.

* Inputs ADC Value from Thermistor and outputs Temperature in Celsius
* requires: include
* Utilizes the Steinhart-Hart Thermistor Equation:
* Schematic:
* [Ground] -- [10k-pad-resistor] -- | -- [thermistor] --[Vcc (5 or 3.3v)]
* |
* Analog Pin 0

#include <Math.h>
#define ThermistorPIN 0 // Analog Pin 0

float vcc = 4.91; // only used for display purposes, if used
// set to the measured Vcc.
float pad = 9850; // balance/pad resistor value, set this to
// the measured resistance of your pad resistor
float thermr = 10000; // thermistor nominal resistance

float Thermistor(int RawADC) {
long Resistance;
float Temp; // Dual-Purpose variable to save space.

Resistance=pad*((1024.0 / RawADC) - 1);
Temp = log(Resistance); // Saving the Log(resistance) so not to calculate it 4 times later
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15; // Convert Kelvin to Celsius

// Uncomment this line for the function to return Fahrenheit instead.
//temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert to Fahrenheit
return Temp; // Return the Temperature

void setup() {

void loop() {
float temp;
temp=Thermistor(analogRead(ThermistorPIN)); // read ADC and convert it to Celsius
Serial.print("Celsius: ");
Serial.print(temp,1); // display Celsius
//temp = (temp * 9.0)/ 5.0 + 32.0; // converts to Fahrenheit
//Serial.print(", Fahrenheit: ");
//Serial.print(temp,1); // display Fahrenheit
delay(5000); // Delay a bit...


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: