KY-015 Combi-Sensor Temperature+Humidity

From SensorKit X40 Wiki

Jump to: navigation, search



Technical data / Short description

Chipset: DHT11 | Communication protocol: 1-wire measuring range Humidity 20-90%RH measuring termperature: 0-50°C

Advantages of the sensor are the combination between temperature measurment and humidity measurements in one compact design - the disadvantage is the low sampling rate of the measurement, you are only able to get a new result every 2 seconds - so thid sensor is better to use for long period measurements.


3 G V S.png

Software example Arduino

This sensor is not sending it's measurements analog.
The measured data is transferred digital.

The best way to use this sensor is with the Adafruit_DHT library from the company Adafruit which is published under the following Link under the OpenSource MIT-Lizenz.

The example below is using this library - for this we advise to download it from Github, to copy and to unzip it in the Arduino-library folder which you can find under the path C:\user\[Username]\documents\arduino\libraries by default. You can use it then for this and the following project examples. It is also included in the download package below.

// Adafruit_DHT library will be included
#include "DHT.h"

// You can declare the input pin here
#define DHTPIN 2     

// The sensor will be initialized here
#define DHTTYPE DHT11   // DHT 11

void setup() 
  Serial.println("KY-015 test - temperature and humidity-test:");

  // Mearsurement will be started

// Main program loop
// The program will be started and the measurements will be read by it.
// It takes a break between every measurement to take new values.
void loop() {

  // Two second break between measurements

  // Measurement of humidity
  float h = dht.readHumidity();
  // Measurement of temperature
  float t = dht.readTemperature();
  // The measurements will be tested of errors here
  // If an error is detected, an error message will be displayed
  if (isnan(h) || isnan(t)) {
    Serial.println("Error while reading the sensor");

  // Output at the serial console
  Serial.print("Humidity: ");
  Serial.print(" %\t");
  Serial.print("temperature: ");
  Serial.print(char(186)); //Output <°> symbol
  Serial.println("C ");
  Serial.println(" ");

Please notice, the sensor will only get a new measurement value after 2 seconds. Because of that it is better to use it for long period measurements.

Example program download:


Connections Arduino:

GND = [Pin GND]
+V = [Pin 5V]
Signal = [Pin D2]

Software example Raspberry Pi

To control the DHT11-sensor, the Adafruit_python_library from the company Adafruit will be used in our example. This library is published under the following Link with the MIT OpenSource-Lizenz.

The library has to be installed before using:

At first, you need to make sure that your system is able to compile Python extensions.

sudo apt-get update
sudo apt-get install build-essential python-dev

Then you have to install the Github-sofware on the Raspberry Pi if it is not already done:

sudo apt-get install git

You can download and unzip the current version of the library with the command...

git clone

After that you need to enter the downloaded folder with...

cd Adafruit_Python_DHT/

... and install the library with ...

sudo python install

In order that the Raspberry Pi can communicate with the sensor via I2C-bus, you have to activate the I2C function from the Raspberry Pi.

For this, you have to append the following line to the end of the file "/boot/config.txt":


You can edit the file with the command:

sudo nano /boot/config.txt

You can save and close the file with the key sequence [ctrl+x -> y -> enter].

Furthermore you need additional libraries to use I2C with python. To install it use the following command:

sudo apt-get install python-smbus i2c-tools -y

You can use the following python code example now. The program starts the measurement at the sensor and shows the measurements of air pressure, temperature and the highness above sea level.

# coding=utf-8

# Needed modules will be imported
import RPi.GPIO as GPIO
import Adafruit_DHT
import time

# The break of 2 seconds will be configured here
sleeptime = 2

# Sensor should be set to Adafruit_DHT.DHT11,
# Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302.
DHTSensor = Adafruit_DHT.DHT11

# The pin which is connected with the sensor will be declared here
GPIO_Pin = 23

print('KY-015 sensortest - temperature and humidity')

        # Measurement will be started and the result will be written into the variables
        humid, temper = Adafruit_DHT.read_retry(DHTSensor, GPIO_Pin)

        if humid is not None and temper is not None:

            # The result will be shown at the console
            print('temperature = {0:0.1f}°C  | rel. humidity = {1:0.1f}%'.format(temper, humid))
        # Because of the linux OS, the Raspberry Pi has problems with realtime measurements.
        # It is possible that, because of timing problems, the communication fails.
        # In that case, an error message will be displayed - the result should be shown at the next try.
            print('Error while reading - please wait for the next try!')

# Scavenging work after the end of the program
except KeyboardInterrupt:

Please notice, the sensor will only get a new measurement value after 2 seconds. Because of that it is better to use it for long period measurements.

Connections Raspberry Pi:

GND = GND [Pin 06]
+V = 3,3V [Pin 01]
Signal = GPIO23 [Pin 16]

Example download


To start with the command:

sudo python