ESP32 KY-015 Temperature and Humidity Sensor Module
Overview
The KY-015 is a temperature and humidity sensor module based on the DHT11 sensor. It provides digital output for temperature and humidity measurements, making it ideal for environmental monitoring applications.
About KY-015 Temperature and Humidity Sensor Module
The KY-015 Temperature and Humidity Sensor Module integrates the DHT11 sensor, capable of measuring temperatures from 0°C to 50°C with an accuracy of ±2°C, and relative humidity levels from 20% to 90% with an accuracy of ±5%. It communicates using a single-wire digital protocol, making it straightforward to interface with microcontrollers like Arduino and ESP32. Due to its low sampling rate, the sensor provides new readings approximately every two seconds, making it suitable for applications such as climate monitoring, greenhouse management, and environmental data logging.
Where to Buy
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
Technical Specifications
Pinout Configuration
The VCC
pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND
pin is the ground connection and must be connected to the ground of your ESP32.
Pin (-):
Ground (GND).Pin (middle):
VCC (3.3V to 5V).Pin (S):
Digital signal output.
Troubleshooting Guide
Common Issues
❌ No Data Output
Issue: The sensor is not providing any data.
Solutions:
- Ensure all connections are secure and correctly placed.
- Verify that the microcontroller pin connected to the sensor's data pin is correctly configured as an input.
- Confirm that the sensor is receiving adequate power (3.3V or 5V).
⚠️ Incorrect or Fluctuating Readings
Issue: The sensor outputs incorrect or unstable temperature and humidity values.
Solutions:
- Check for electromagnetic interference from nearby devices; try to isolate the sensor from potential sources of interference.
- Ensure that the sensor is not exposed to condensation or water droplets, which can affect readings.
- Allow the sensor to stabilize in the environment for a few minutes before taking readings.
Debugging Tips
🔍 Serial Monitor
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
⚡ Voltage Checks
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
Code Examples
Arduino Example
#include <DHT.h>
#define DHTPIN 2 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("KY-015 Test - Temperature and Humidity:");
dht.begin();
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" % ");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" °C");
}
This Arduino code utilizes the DHT library to read temperature and humidity data from the KY-015 sensor. The sensor is connected to digital pin 2, and the readings are displayed on the serial monitor every two seconds.
ESP-IDF Example
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "dht.h"
#define DHT_PIN GPIO_NUM_4
void app_main(void) {
printf("KY-015 Sensor Test\n");
while (1) {
int16_t temperature = 0;
int16_t humidity = 0;
if (dht_read_data(DHT_TYPE_DHT11, DHT_PIN, &humidity, &temperature) == ESP_OK) {
printf("Humidity: %d.%d%% Temperature: %d.%d°C\n", humidity / 10, humidity % 10, temperature / 10, temperature % 10);
} else {
printf("Could not read data from sensor\n");
}
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
This ESP-IDF code reads temperature and humidity data from the KY-015 sensor using the DHT11 library. The sensor is connected to GPIO4, and data is printed to the console every 2 seconds. If the reading fails, an error message is displayed.
ESPHome Example
sensor:
- platform: dht
pin: GPIO4
model: DHT11
temperature:
name: "KY-015 Temperature"
humidity:
name: "KY-015 Humidity"
update_interval: 2s
This ESPHome configuration sets up the KY-015 temperature and humidity sensor using the DHT11 protocol. The sensor is connected to GPIO4, and readings are updated every 2 seconds.
PlatformIO Example
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/DHT sensor library
PlatformIO Example Code
#include <Arduino.h>
#include <DHT.h>
#define DHTPIN 4 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
Serial.println("KY-015 Test - Temperature and Humidity:");
dht.begin();
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" % ");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" °C");
}
This PlatformIO code reads the KY-015 sensor data using the DHT library. It prints temperature and humidity values every 2 seconds, with error handling for failed sensor readings.
MicroPython Example
import dht
import machine
import time
sensor = dht.DHT11(machine.Pin(4))
while True:
try:
sensor.measure()
temp = sensor.temperature()
humidity = sensor.humidity()
print("Temperature:", temp, "°C", " Humidity:", humidity, "%")
except OSError as e:
print("Failed to read sensor.")
time.sleep(2)
This MicroPython script reads temperature and humidity data from the KY-015 sensor connected to GPIO4. It updates readings every 2 seconds and handles errors in case of sensor failure.
Conclusion
The ESP32 KY-015 Temperature and Humidity Sensor Module is a powerful KY-0xx module sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.