• Arduino
  • Raspberry Pi
  • Raspberry Pi Pico
  • Micro:Bit

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
- Signal
5 V +V
GND GND
Sensor KY-053
Signal A0
+V -
GND -
Arduino KY-053
5 V VDD
GND GND
Pin A5 SCL
Pin 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

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 Raspberry Pi

Pin assignment Raspberry Pi

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

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.

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 with the I2C bus
ads = ADS.ADS1115(i2c)

# Define maximum possible voltage (depending on your reference voltage)
voltageMax = 3.3

# Create individual inputs on channels
chan0 = AnalogIn(ads, ADS.P0)
chan1 = AnalogIn(ads, ADS.P1)
chan2 = AnalogIn(ads, ADS.P2)
chan3 = AnalogIn(ads, ADS.P3)

# Main program loop
while True:
    # Calculation of the temperature via an NTC resistor
    ntc_resistance = ((chan0.voltage / voltageMax) * 10000) / (1 - (chan0.voltage / voltageMax))
    temperatur = 1 / ((1 / 298.15) + (1 / 3950) * math.log(ntc_resistance / 10000))
    temperatur -= 273.15  # Conversion from Kelvin to Celsius
    print("Temperatur: {:.2f} °C".format(temperatur))
    print("---------------------------------------------------")
    time.sleep(1)

Example program download

KY013-RPi.zip

To start with the command:

sudo python3 KY013-mit-KY053.py

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 Micro:Bit

Pinout Micro:Bit:

Micro:Bit Sensor
- Signal
3 V +V
GND GND
Sensor KY-053
Signal A0
+V -
GND -
Micro:Bit KY-053
Pin 19 SCL
Pin 20 SDA
3 V VDD
GND GND

Analog sensor, therefore the following must be observed: The Micro:Bit has analog inputs or there is an ADC (analog digital converter) integrated in the chip of the Micro:Bit. However, these are only limited to 10-bit and therefore offer only a rather low accuracy for analog measurements.

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 Micro:Bit to expand it by 4 analog inputs. This is connected to the Micro:Bit via I2C, takes over the analog measurement and transfers the value digitally to the Micro:Bit.

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

The program uses the corresponding library from us to control the ADS1115 ADC. This has been published under the following link pxt-ads1115 under the MIT-License.

Sample program download

microbit-KY-013.zip

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 Raspberry Pi Pico

Pin assignment Raspberry Pi Pico

Raspberry Pi Pico Sensor
3,3 V +V
GND GND
- Signal
Sensor KY-053
Signal A0
+V -
GND -
Raspberry Pi Pico KY-053
GPIO 1 SCL
GPIO 0 SDA
3,3 V VDD
GND GND

Analog sensor, therefore the following must be observed

The Raspberry Pi Pico has analog inputs for the internal ADC (analog digital converter) in the chip of the Raspberry Pi Pico, but this ADC has only a resolution of 12-bit.

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

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

The program uses the corresponding ADS1115-Micropython library from Joy-IT to control the ADS1115 ADC. This has been published under the following linkhttps://github.com/joy-it/ADS1115-Micropython under the MIT License. The required library is included in the download package below.

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

# Load libraries
from machine import Pin
from time import sleep
import ADS1115
import math

# Initialization of the ADC
ADS1115.init(0x48, 1, 4, False)

# Endless loop for reading the ADC
while True:
    Volt = ADS1115.raw_to_v(ADS1115.read(0))
    print(str(Volt) + " V")
    # Conversion from voltage to temperature
    temp = ((Volt / 3.3) * 10000) / (1 - (Volt / 3.3))
    temp = 1 / ((1/298.15) + (1 / 3950) * math.log(temp / 10000))
    temp = temp - 273.15

    # Serial output of the calculated temperature
    print("The temperature is: " + str(temp) + " °C")
    print("---------------------------")

    sleep(2)

Example program download

KY013-Pico.zip