This module contains a NTC thermistor which can measure temperatures in the range of -55°C up to +125°C. This has a decreasing resistance value at higher temperature.

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

This resistance can be determined with the help of a voltage divider, where 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

Includes an NTC
Measuring range -55°C to +125°C
Known resistance 10kΩ
Specific resistance of the NTC 3950Ω

Known resistance: 10kΩ

Specific resistance of the NTC: 3950Ω

Pin assignment

Code example Arduino

Pin assignment Arduino

Arduino Sensor
A0 (KY-053 ADC) Signal
5V +V
Masse GND
Arduino KY-053
5V +V
Masse 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 said library - for this we recommend downloading it from Github, unzipping it and copying it in the Arduino library folder, which by default is located 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_ADS1015.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);
  
  // This value is needed for the conversion to a voltage - this depends on the set gain.
  // The appropriate value for the gain should be taken from the table shown above
  gain_conversion_factor = 0.125;
  // Conversion of the recorded values into a voltage.
  voltage1 = (adc1 * gain_conversion_factor);
  
  // Output the values to the serial interface
  Serial.print("Analog input 1: "); Serial.print(voltage1); Serial.println("mV");
 
  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.3V [Pin 1] +V
Ground [Pin 6] GND
Sensor KY-053
Signal A0
+V 3.3V [Pin 1]
GND Ground [Pin 6]
Raspberry Pi KY-053
GPIO 3 [Pin 5] SCL
Gpio 2 [Pin 3] SDA

This is a similar example program with the difference that here no LED is lit but something is output to the console when a signal is detected.

Analog sensor, therefore the following must be considered.

In contrast to the Arduino, the Raspberry Pi has no analog inputs and no ADC (analog digital converter) is integrated in the chip of the Raspberry Pi. This limits the Raspberry Pi, if you want to use sensors, where not digital values are output [voltage value exceeded -> digital ON | voltage value undercut -> digital OFF | example: button pressed [ON] button released [OFF]], but it should be a continuous variable value (example: potentiometer -> other position = other voltage value).

To avoid this problem, our sensor kit X40 has the KY-053, a module with 16 bit accurate 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 passes 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 information page for the KY-053 Analog Digital Converter.

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.

The program uses the ADS1115 ADC to measure the current voltage value at the ADC, uses this to calculate the current resistance of the NTC, uses values determined in advance for this sensor to calculate the temperature, and outputs this to the console.

#!/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 = 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-with-KY053.py

Code example Micro:Bit

Pinout Micro:Bit:

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

This is a MakeCode example for Micro:Bit which essentially does the same as the examples of the other two variants. However, this example is closer to the Raspberry Pi example than the Arduino example.

Sample program download

microbit-KY-013.zip