This module contains a NTC thermistor, which can measure temperatures in the range of -55 °C up to +125 °C. The resistance value decreases at higher temperatures. This has a lower resistance value at higher temperatures. Based on the resulting resistance curve, the corresponding temperature can be calculated.

The change in resistance can be approximated mathematically, converted into a linear curve and the temperature coefficient (dependence of resistance change on temperature change) determined. Using these, the current temperature can then be calculated.

The resistance can be determined with the aid of a voltage divider, in which a known voltage is divided over a known and an unknown (variable) resistance. Using this measured voltage, the resistance can then be calculated. The exact calculation is included in the code examples below.

Technical data

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 Ω

Pin assignment

Code example Arduino

Pin assignment Arduino

Arduino Sensor
A0 (KY-053 ADC) Signal
5 V +V
Ground GND
Arduino KY-053
5 V +V
Ground GND
A5 SCL
A4 SDA

For the following code example an additional library is needed:

Adafruit_ADS1x15 by Adafruit | published under the BSD License.

The example below uses this library - for this we recommend to download it from Github, unzip it and copy it to the Arduino library folder which is located by default at (C:\User[username]\Documents\Arduino\libraries) so that it is available for this code example and following projects. Alternatively, this is also included in the download package below as well.

The program measures the current voltage value at the NTC, calculates the temperature and translates the result to °C for serial output.

#include <Adafruit_ADS1X15.h>
#include <math.h>

Adafruit_ADS1115 ads;

void setup(void)
{
  Serial.begin(9600);
  
  Serial.println("Values of analog input A1 of ADS1115 are read and output");
  Serial.println("ADC Range: +/- 4.096V 1 bit = 0.125mV");
  
  // This module has signal amplifiers at its analog inputs, whose
  // amplification can be configured via software in the ranges below
  // can be configured.
  // This is desired in case a certain voltage range is expected // as measurement result and
  // range is expected as a measurement result and thus a higher resolution of the signal is
  // is obtained.
  // Gain=[2/3] is selected as default gain and can be changed by commenting out // to another gain.
  // to change to a different gain.
  // ADS1115
  // -------
  // ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 0.1875mV
  // ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 0.125mV
  // ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 0.0625mV
  // ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.03125mV
  // ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.015625mV
  // ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.0078125mV
  
  ads.begin();
}

void loop(void)
{
  uint16_t adc1;
  float voltage1;
  float gain_conversion_factor;
  
  // The "ads.readADC_SingleEnded(0)" command is the actual operation that starts the measurement in the ADC.
  // the "0" as variable for this function defines the used channel which should be measured
  // If e.g. the third channel shall be measured, this variable has to be replaced with "3
  adc1 = ads.readADC_SingleEnded(1);
  
  // Conversion of the recorded values into a voltage.
  voltage1 = ads.computeVolts(adc1);
  
  // Output the values to the serial interface
  Serial.print("Analog input 1: "); Serial.print(voltage1); Serial.println(" V");
 
  double Temp;
  Temp = ((voltage1 / 3300) * 10000) / (1 - (voltage1 / 3300));
  Temp = 1 / ((1/298.15) + (1 / 3950.0) * log(Temp / 10000));
  Temp = Temp - 273.15;
  
  Serial.print("Current temperature is:");
  Serial.print(Temp);
  Serial.println("°C");
  Serial.println("---------------------------------------");

  delay(1000);
}

Sample program download

KY013-Arduino.zip

Code example Raspberry Pi

Pin assignment Raspberry Pi

Raspberry Pi Sensor
KY-053 A0 Signal
3.3 V [Pin 1] +V
Ground [Pin 6] GND
Sensor KY-053
Signal A0
+V 3.3 V [Pin 1]
GND Ground [Pin 6]
Raspberry Pi KY-053
GPIO 3 [Pin 5] SCL
GPIO 2 [Pin 3] SDA

Analog sensor, therefore the following must be considered: The Raspberry Pi has, in contrast to the Arduino, no analog inputs or there is no ADC (analog digital converter) integrated in the chip of the Raspberry Pi. This limits the Raspberry Pi, if you want to use sensors, which do not output digital values, but a continuously changing value (example: potentiometer -> different position = different voltage value).

To avoid this problem, our sensor kit X40 contains the KY-053, a module with a 16-bit ADC, which you can use on the Raspberry to expand it with 4 analog inputs. This module is connected to the Raspberry Pi via I2C, takes over the analog measurement and transfers the value digitally to the Raspberry Pi.

Thus we recommend to connect the KY-053 module with the said ADC in between for analog sensors of this set. More information can be found on the KY-053 Analog Digital Converter information page.

The program uses the corresponding ADS1x15 and I2C Python libraries from Adafruit to drive the ADS1115 ADC. These have been published at the following link https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15 under the MIT license. The required libraries are not included in the download package below.

Please note that you need to enable I2C on your Raspberry Pi before using this example.

#!/usr/bin/python
# coding=utf-8

import time
import board
import busio
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
import math
# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)

# Create the ADC object using the I2C bus
ads = ADS.ADS1115(i2c)
voltageMax = 3.3
# Create single-ended input on channels
chan0 = AnalogIn(ads, ADS.P0)
chan1 = AnalogIn(ads, ADS.P1)
chan2 = AnalogIn(ads, ADS.P2)
chan3 = AnalogIn(ads, ADS.P3)



while True:
    temperature = ((chan0.voltage / 3.3) * 10000) / (1 - (chan0.voltage / 3.3))
    temperature = 1 / ((1 / 298.15) + (1 / 3950) * math.log(temperature / 10000))
    temperature = temperature - 273.15
    print("Temperature: ",'%.2f' % temperature,"°C")
    print("---------------------------------------------------")
    time.sleep(1)

Example program download

KY013-RPi.zip

To start with the command:

sudo python3 KY013-mit-KY053.py

Code example Micro:Bit

Pinout Micro:Bit:

Micro:Bit Sensor
Pin 1 Signal
3 V +V
Ground GND

Sample program download

microbit-KY-013.zip