KY-013 Temperature-Sensor module

From SensorKit X40 Wiki

Revision as of 17:43, 20 February 2017 by Webmaster Wiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Pictures

none

Technical data / Short description

Temperaturemeasuring range: -55°C / +125°C


This module provides a NTC thermistor - it will have a lower resistant on higher temperatures.


none

You can draw near to the resistant change via maths and convert it into a linear course. With that you can determine the temperature coefficient (addicted from resistant change to temperature change). With it you can determine actual temperature if you know current resistance.

This resistor can be determinded via voltage devider, where a known voltage split up between a known resistor and an unknown (variable) resistor.

With that Voltage you can determine the resistance of the resistor - you can see the full calculation in the example below.


none

Pinout

none

Code example Arduino

The program measures the actual voltage from the NTC, calculate the temperature and translates the result to °C for the serial output.

#include 

int sensorPin = A5; // Declaration of the input pin

// These function translates the recorded analog measurement 
// into the right temperature in °C and gives it out.
double Thermistor(int RawADC)
{
	double Temp;
	Temp = log(10000.0 * ((1024.0 / RawADC - 1)));
	Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp )) * Temp );
	Temp = Temp - 273.15;            // convert from Kelvin to Celsius
	return Temp;
}

// Serial output in 9600 Baud
void setup()
{
	Serial.begin(9600);
}

// The program measures the current voltage value on the NTC
// and translates it intp °C for the serial output
void loop()
{
	int readVal = analogRead(sensorPin);
	double temp =  Thermistor(readVal);

	// Output on the serial interface
	Serial.print("Current temperature is:");
	Serial.print(temp); 
        Serial.print(char(186)); //Output <°> Symbol
	Serial.println("C");
	Serial.println("---------------------------------------");

	delay(500);
}

Connections Arduino:

Sensor +V = [Pin 5V]
Sensor GND = [Pin GND]
Sensor Signal = [Pin A5]

Example program Download

KY-013_TemperaturSensor.zip

Code example Raspberry Pi

!! Attention !! Analog Sensor  !! Attention !!

Unlike the Arduino, the Raspberry Pi don't provide an ADC ( analog digital converters ) on its Chip. This gives the Raspbery Pi limits if you want to use a non digital Sensor [ voltage value exceeded -> digital ON | voltage value deceeded -> digital OFF | example : button pushed [ON] button realeased [OFF]], but rather its a continous changleable value ( example: Potentiometer -> other position = other voltage value).

To evade this, use our Sensorkit X40 with the KY-053 module which provides a 16 Bit ADC, which can be used  with the Raspberry Pi, to upgrade it with 4 additional analog input pins. This will be connected via I2C from the Raspberry Pi, it takes the analog measurment and gives the digital value to the Raspberry Pi. 

So we recommend for analog sensors from this set, to interpose the KY-053 module with the ADC. For more information please look at the infosite: KY-053 Analog Digital Converter

!! Attention !! Analog Sensor  !! Attention !!

The program uses the specific ADS1x15 and I2C python-libraries from the company Adafruit to control the ADS1115 ADC. You will find these on the link: [https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code] published under the  BSD-License [Link]. You can find the needed libraries in the lower download package.


The program measures with help of the ADS1115 ADC the current voltage from the ADC, calculate the current resistance value of the NTC, calculates with help of pre-measurements for this sensor the temperature and shows it on the terminal.


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


#############################################################################################################
### Copyright by Joy-IT
### Published under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
### Commercial use only after permission is requested and granted
###
### KY-013 Temperatur Sensor - Raspberry Pi Python Code Example
###
#############################################################################################################

# This code is using the ADS1115 and the I2C python library for the Rasperry Pi
# These is published by BSD Licence under the following link
# [https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code]
from Adafruit_ADS1x15 import ADS1x15
from time import sleep

# Additional needed modules will be imported and configured
import time, signal, sys, os, math
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

# Used variables will be initialized
delayTime = 0.2

# Address allocation ADS1x15 ADC

ADS1015 = 0x00  # 12-bit ADC
ADS1115 = 0x01  # 16-bit

# Amplification (Gain) will be picked
gain = 4096  # +/- 4.096V
# gain = 2048  # +/- 2.048V
# gain = 1024  # +/- 1.024V
# gain = 512   # +/- 0.512V
# gain = 256   # +/- 0.256V

# Sampling rate of the ADC (SampleRate) will be picked
# sps = 8    # 8 Samples per second
# sps = 16   # 16 Samples per second
# sps = 32   # 32 Samples per second
# sps = 64   # 64 Samples per second
# sps = 128  # 128 Samples per second
# sps = 250  # 250 Samples per second
# sps = 475  # 475 Samples per second
sps = 860  # 860 Samples per second

# ADC-Channel (1-4) will be picked
adc_channel = 0    # Channel 0
# adc_channel = 1    # Channel 1
# adc_channel = 2    # Channel 2
# adc_channel = 3    # Channel 3

# Here the ADC will be initialized - the ADC which is used by the KY-053 is an ADS1115 Chipset
adc = ADS1x15(ic=ADS1115)

#############################################################################################################

# ########
# Main program loop
# ########
# The program measures the current voltage at the ADC with the help of the ADS1115 ADC,
# with that it calculates the current resistance of the NTC, calculates, with help of pre-measurements for this sensor,
# the temperature and shows it on the terminal.

try:
        while True:
                #Current values will be recorded...
                voltage = adc.readADCSingleEnded(adc_channel, gain, sps)
                #... converted ...
                temperature = math.log((10000/voltage)*(3300-voltage))
                temperature = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * temperature * temperature)) * temperature);
                temperature = temperature - 273.15;
                # ... and displayed
                print "Temperature:", temperature,"°C"
                print "---------------------------------------"

                # Delay
                time.sleep(delayTime)



except KeyboardInterrupt:
        GPIO.cleanup()

Connections Raspberry Pi:

Sensor

+V = 3,3V [Pin 1 (RPi)]
GND = GND [Pin 06 (RPi)]
analog Signal = Analog 0 [Pin A0 (ADS1115 - KY-053)]

ADS1115 - KY-053:

VDD = 3,3V [Pin 17]
GND = GND [Pin 09]
SCL = GPIO03 / SCL [Pin 05]
SDA = GPIO02 / SDA [Pin 03]
A0 = s.o. [Sensor: analog Signal]

Example program download

KY-013_RPi_TemperaturSensor.zip

To start with the command:

sudo python KY-013_RPi_TemperaturSensor.py