KY-015 Temperature and Humidity Sensor Module

The KY-015 Temperature and Humidity Sensor module provides a digital serial interface to measure environment humidity and temperature. Compatible with various microcontrollers like Arduino, Raspberry Pi and ESP32.

KY-015 Fritzing part image
Arduino KY-015 temperature and humidity sensor module

KY-015 Specifications

This module consist of a DHT11 digital humidity and temperature sensor, a 1 kΩ resistor and 3 male header pins. The DHT11 uses an internal thermistor and a capacitive humidity sensor to determine the surrounding conditions, an internal chip is responsible for converting the readings to a serial digital signal.

Operating Voltage3.3V to 5.5V
Humidity measurement range20% to 90% RH
Humidity measurement accuracy±5% RH
Humidity measurement resolution1% RH
Temperature measurement range0ºC to 50ºC [32ºF to 122ºF]
Temperature measurement accuracy±2ºC
Temperature measurement resolution1ºC
Signal transmission range20m

Connection Diagram

Connect the Power line (middle) and ground (-) to +5 and GND respectively. Connect signal (S) to pin 8 on the Arduino.

SPin 8
Temperature and humidity sensor KY-022 Arduino connection diagram

KY-015 Arduino Code

The following sketch uses pin 8 on the Arduino to serially send and receive data from the KY-015 sensor. Serial communication is archived by sending specific series of high/low signals to the sensor and waiting for a response. Temperature and humidity data is read bit by bit and returned as an array of bytes.

int DHpin = 8; // input/output pin
byte dat[5];   

byte read_data()
  byte i = 0;
  byte result = 0;
  for (i = 0; i < 8; i++) {
      while (digitalRead(DHpin) == LOW); // wait 50us
      delayMicroseconds(30); //The duration of the high level is judged to determine whether the data is '0' or '1'
      if (digitalRead(DHpin) == HIGH)
        result |= (1 << (8 - i)); //High in the former, low in the post
    while (digitalRead(DHpin) == HIGH); //Data '1', waiting for the next bit of reception
  return result;

void start_test()
  digitalWrite(DHpin, LOW); //Pull down the bus to send the start signal
  delay(30); //The delay is greater than 18 ms so that DHT 11 can detect the start signal
  digitalWrite(DHpin, HIGH);
  delayMicroseconds(40); //Wait for DHT11 to respond
  pinMode(DHpin, INPUT);
  while(digitalRead(DHpin) == HIGH);
  delayMicroseconds(80); //The DHT11 responds by pulling the bus low for 80us;
  if(digitalRead(DHpin) == LOW)
    delayMicroseconds(80); //DHT11 pulled up after the bus 80us to start sending data;
  for(int i = 0; i < 5; i++) //Receiving temperature and humidity data, check bits are not considered;
    dat[i] = read_data();
  pinMode(DHpin, OUTPUT);
  digitalWrite(DHpin, HIGH); //After the completion of a release of data bus, waiting for the host to start the next signal

void setup()
  pinMode(DHpin, OUTPUT);

void loop()
  Serial.print("Humdity = ");
  Serial.print(dat[0], DEC); //Displays the integer bits of humidity;
  Serial.print(dat[1], DEC); //Displays the decimal places of the humidity;
  Serial.print("Temperature = ");
  Serial.print(dat[2], DEC); //Displays the integer bits of temperature;
  Serial.print(dat[3], DEC); //Displays the decimal places of the temperature;

  byte checksum = dat[0] + dat[1] + dat[2] + dat[3];
  if (dat[4] != checksum) 
    Serial.println("-- Checksum Error!");
    Serial.println("-- OK");


Leave a Comment

11 thoughts on “KY-015 Temperature and Humidity Sensor Module”

  1. I think this really needs “dht.begin();” somewhere in the setup block.

  2. Strange, it outputs the values once (sometimes even with correct checksum) but then nothing happens until reboot.

  3. BUG with extra semicolon?
    in start_test() lines 30-31:
    if(digitalRead(DHpin) == LOW);
    delayMicroseconds(80); //DHT11 pulled up after the bus 80us to start sending data;

    • Hi, thanks for reporting the bug! I updated the code and it should work now.