The KY-012 is a temperature and humidity sensor module that integrates the DHT11 sensor. It is designed to provide digital output for both temperature and humidity readings, making it an ideal choice for environmental monitoring applications. The module is widely used in weather stations, home automation systems, and agricultural monitoring setups due to its simplicity and reliability.
The KY-012 module is built around the DHT11 sensor, which offers reliable performance for basic temperature and humidity sensing needs. Below are the key technical details:
The KY-012 module has three pins for easy interfacing with microcontrollers. The pinout is as follows:
Pin | Name | Description |
---|---|---|
1 | VCC | Power supply pin (3.3V to 5.5V) |
2 | DATA | Digital output pin for temperature and humidity data |
3 | GND | Ground connection |
The KY-012 module is straightforward to use and can be easily interfaced with microcontrollers like the Arduino UNO. Below are the steps to use the module in a circuit:
The following code demonstrates how to read temperature and humidity data from the KY-012 module using the DHT library for Arduino:
// Include the DHT library for reading data from the KY-012 module
#include <DHT.h>
// Define the pin connected to the DATA pin of the KY-012
#define DHTPIN 2
// Define the type of DHT sensor (DHT11 in this case)
#define DHTTYPE DHT11
// Initialize the DHT sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// Start the serial communication for debugging
Serial.begin(9600);
Serial.println("KY-012 Temperature and Humidity Sensor Test");
// Initialize the DHT sensor
dht.begin();
}
void loop() {
// Wait a few seconds between readings
delay(2000);
// Read humidity and temperature values
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Check if the readings are valid
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from KY-012 sensor!");
return;
}
// Print the readings to the Serial Monitor
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
}
No data or incorrect readings:
"Failed to read from KY-012 sensor!" message in Serial Monitor:
#define DHTPIN
).Inconsistent or fluctuating readings:
Q: Can the KY-012 module be used outdoors?
A: The KY-012 is not waterproof and should not be exposed to rain or condensation. For outdoor use, consider placing it in a protective enclosure.
Q: How accurate is the KY-012 module?
A: The DHT11 sensor used in the KY-012 provides a temperature accuracy of ±2°C and a humidity accuracy of ±5%.
Q: Can I use the KY-012 with a 3.3V microcontroller?
A: Yes, the KY-012 operates within a voltage range of 3.3V to 5.5V, making it compatible with 3.3V microcontrollers like the ESP8266 or ESP32.
Q: How often can I take readings from the KY-012?
A: The KY-012 has a sampling rate of 1 Hz, meaning you can take one reading per second.
By following the guidelines and troubleshooting tips provided, you can effectively use the KY-012 module in your projects.