KY-013 Analog Temperature Sensor Module

Description

Analog Temperature Sensor module KY-013 for Arduino, measures ambient temperature based on resistance of the thermistor.

 

 

KY-013 Specifications

The KY-013 Analog Temperature Sensor module consist of a NTC thermistor and a 10 kΩ resistor. The resistance of the thermistor varies with surrounding temperature, we'll use the Steinhart–Hart equation to derive precise temperature of the thermistor.

Operating Voltage5V
Temperature measurement range-55°C to 125°C [-67°F to 257°F]
Measurement Accuracy±0.5°C

 

KY-013 Connection Diagram

Connect board's power line (middle) and ground (-) to 5V and GND respectively. Connect signal (S) to pin A0 on the Arduino.

KY-013Arduino
S A0
middle 5V
-GND

Some KY-013 boards are labeled incorrectly,  if you are getting inverted readings (temperature drops when sensor is heated) try swapping power(middle) and ground (-).

Arduino KY-013 analog temperature sensor module connection diagramclick to enlarge

KY-013 Example Code

The following Arduino Sketch will derive the temperature of the thermistor using the Steinhart-Hart equation. The code will return temperature in Celcius, uncomment line 17 to get temperature in farenheit.

int ThermistorPin = A0;
int Vo;
float R1 = 10000; // value of R1 on board
float logR2, R2, T;
float c1 = 0.001129148, c2 = 0.000234125, c3 = 0.0000000876741; //steinhart-hart coeficients for thermistor

void setup() {
  Serial.begin(9600);
}

void loop() {
  Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023.0 / (float)Vo - 1.0); //calculate resistance on thermistor
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)); // temperature in Kelvin
  T = T - 273.15; //convert Kelvin to Celcius
 // T = (T * 9.0)/ 5.0 + 32.0; //convert Celcius to Farenheit

  Serial.print("Temperature: "); 
  Serial.print(T);
  Serial.println(" C"); 

  delay(500);
}

The coeficients only apply to boards with a 10KΩ thermistors, some rare boards have 100KΩ thermistors and need different coeficients.
If the displayed temperature drops when heating the thermistor and viceversa a try swapping power and ground, apparently these boards are commonly mislabeled.

guest
16 Comments
Inline Feedbacks
View all comments
Baracchini
Baracchini
2 months ago

Desculpem o erro. Quis dizer:
No meu KY-013 os pinos são + 5V, GND e D. Se você colocar como está no esquema os valores obtidos de temperatura ficam errados.

Baracchini
Baracchini
2 months ago

N0 meu KY-013 os pinos são +5V, GND e D. Se você colocar como está no esquema os temperaturas obtidas ficam completamente díspares.

luberth
luberth
3 months ago

your ntc code example is for pulldown
the ky-013 boards are pullup
switch + and – wire to make this code example to work

tino_moser_999
tino_moser_999
6 months ago

Hey guys i got this sensor to read semi correct. i get a reading of -22°C instead of 22°C how do i get rid of this “-“

tino_moser_999
tino_moser_999
Reply to  tino_moser_999
5 months ago

nevermind, i solved this with simple math… like “(analogRead(TEMP_1)) -40” i have the “math.h” library included nontheless…

HIGUYSS
HIGUYSS
9 months ago

Hi, i copied and pasted to your Arduino code. But the result is not to make any sense. The possible temperature should be between 19-23 C but on the serial port as like: 85-90 C. I try to change the temperature calculation but the problem is not solved. Pls help

l00
l00
2 years ago

Hi,
It’s probably trivial (I’m a total noob), but could you explain the first line of the Thermister function:
Temp = log(((10240000/RawADC) – 10000));
The way I see it, RawADC is a electric tension measure going from 0 to 1023. Therefore, the resistance R in the Steinhart–Hart equation should be proportional to it according to Ohm’s law. I don’t get why you divide by it.

l00
l00
Reply to  l00
2 years ago
lzjwhu
lzjwhu
2 years ago

If the equation on line 5 is to be used (1024 should better be 1023.0), the Vcc and ground connections need to be switched to get the correct thermistor resistance values (i.e., ground connected to the middle pin). After some experimentation, I realized that the A B C values on line 6 are meant for a 10K thermistor. I am not sure if the original KY-013 uses a 10K thermistor. The unit I got from the KUMAN kit uses a 100K thermistor, therefore the confusion (the KUMAN program is also seriously wrong, in multiple places…). If your board also uses a 100K thermistor, the following equations can be used to salvage the situation: //the correct resistance, assuming the center pin being connected to ground and “-” to Vcc: double Rt= 10000 * (1023.0/RawADC-1); //alternatively, if the center pin is connected to Vcc as in the figure above: double Rt= 10000/(1023.0/RawADC-1);… Read more »

Viktor
Viktor
Reply to  lzjwhu
2 years ago

Thank you so much! I have the same kit and the same unnamed thermistor. Your post saved me after hours of bashing my head over negative readings!

Dohn shoot
Dohn shoot
Reply to  lzjwhu
2 years ago

Thanks for sorting that out!

lzjwhu
lzjwhu
2 years ago

The equation on line 5 for the log of thermistor resistance is wrong !!!!!
Should be Temp = log( 10000/(1023.0/RawADC-1) );
The A B C values given on line 6 are all off too.
Please update the ABC values

Kenneth L. Anderson
Kenneth L. Anderson
2 years ago

” if you are getting inverted readings (temperature drops when sensor is heated) try swapping signal (S) and ground (-).” That is a mis-statement. These boards commonly are built with the (-) pin needing to be connected to the positive supply volts and the middle pin to the negative, or reference volts. If the S pin, as you suggest, becomes connected to one or the other excitation supply pins, the circuit ends up no longer being a voltage divider; that is, the two resistive components are no longer in series with each other between the reference and the excitation voltage. You’ll ONLY end up with a valid voltage divider circuit by supplying the excitation voltage right side up or upside down; i.e., the output of the voltage divider always has to be the ‘S’ pin. Leave that pin alone.

Daniel Salazar Dominguez
Daniel Salazar Dominguez
2 years ago

hi, iam using arduino IDE 1.8.5 and I get in the monitor serie a result of nanc (I believe the translation is “not a number” c) whats the problem?
Thanks!

Johan
Johan
Reply to  Daniel Salazar Dominguez
2 years ago

A division by zero is the problem. You are receiving zero from pin A0.