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

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>

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

Serial.println("ADC Range: +/- 4.096V 1 bit = 0.125mV");

// 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.
// -------
// 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

}

void loop(void)
{
float voltage1;
float gain_conversion_factor;

// 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

// 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.

// Output the values to the serial interface

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);
}
``````

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 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 math
# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)

# Create the ADC object using the I2C bus
voltageMax = 3.3
# Create single-ended input on channels

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)
``````

KY013-RPi.zip

``````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. 