Home SensorsKit Arduino and KY-013 Analog Temperature Sensor

# Arduino and KY-013 Analog Temperature Sensor

In this article, we connect an KY-013 Analog Temperature Sensor module to an Arduino Uno

The KY-013 Analog Temperature Sensor module can measure ambient temperature based on the resistance of the thermistor on the board.

This module contains a NTC thermistor, which can measure temperatures in the range of -55 °C up to +125 °C.

An NTC Thermistor is a Negative Temperature Coefficient resistor. This means that the resistance is inversely proportional to temperature. The resistance increases when temperature decreases and vice-versa.

 Operating voltage 3,3 V – 5 V Measuring range -55 °C to +125 °C Measurement accuracy ± 0,5 °C Known resistance 10 kΩ Specific resistance of the NTC 3950 Ω

### Parts Required

You can connect to the module using dupont style jumper wire.

This should work with other Arduino board – I have tried an Uno and Mega

 Name Link Arduino Uno 37 in one sensor kit Connecting cables

### Schematic/Connection

The KY-013 module pins are connected to the Arduino Uno board as follows:

COMPONENT PIN ARDUINO UNO BOARD PIN
(-) GND
middle +5V
S A0

## Code Example

The Steinhart and Hart Equation is an empirical expression that has been determined to be the best mathematical expression for resistance temperature relationship of NTC thermistors and NTC probe assemblies.

It is usually found explicit in T where T is expressed in degrees Kelvin.
Where T = Temperature in degrees Kelvin, LnR is the Natural Log of the measured resistance of the thermistor, A, B and C are constants.
The coefficients A, B and C are found by taking the resistance of the thermistor at three temperatures and solving three simultaneous equations.

E.g. T = 0°C when the resistance of a 10kohm thermistor R is 32650 ohms
T = 50°C when the resistance of a 10kohm thermistor R is 3603 ohms
T = 100°C when the resistance of a 10kohm thermistor R is 678.3 ohms

1/T = A + B(LnR ) + C(LnR )
1/T = A + B(LnR ) + C(LnR )
1/T = A + B(LnR ) + C(LnR )

Steinhart – Hart Equation 1/T = A+B(LnR)+C(LnR)

For a 10 kohm thermistor, the value of constants A, B and C are:
A = 0.001125308852122
B = 0.000234711863267
C = 0.000000085663516

```int ntcPin = A0;
int Vo;
float R1 = 10000; // value of R1
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()
{
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);
}```

## Serial Monitor Output

Temperature: 10.99 C
Temperature: 11.08 C
Temperature: 10.99 C
Temperature: 11.17 C
Temperature: 11.26 C
Temperature: 11.35 C
Temperature: 11.17 C
Temperature: 11.26 C
Temperature: 11.26 C
Temperature: 11.35 C