The DHT11 is a widely used sensor for measuring temperature and humidity. It is commonly used in weather stations, IoT projects, and environmental monitoring systems.
1234
Downloads
567
Likes
VCC | Power supply (3.3V or 5V, depending on the module) |
GND | Ground (-) |
DATA | Data communication pin |
1#include <DHT.h>
2
3#define DHTPIN 2 // Pin where the DHT11 is connected
4#define DHTTYPE DHT11 // DHT 11
5
6DHT dht(DHTPIN, DHTTYPE);
7
8void setup() {
9 Serial.begin(9600);
10 dht.begin();
11}
12
13void loop() {
14 // Reading temperature or humidity takes about 250 milliseconds!
15 // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
16 float h = dht.readHumidity();
17 // Read temperature as Celsius (the default)
18 float t = dht.readTemperature();
19
20 // Check if any reads failed and exit early (to try again)
21 if (isnan(h) || isnan(t)) {
22 Serial.println("Failed to read from DHT sensor!");
23 return;
24 }
25
26 // Compute heat index in Celsius (isFahreheit = false)
27 float hic = dht.computeHeatIndex(t, h, false);
28
29 Serial.print("Humidity: ");
30 Serial.print(h);
31 Serial.print(" % ");
32 Serial.print("Temperature: ");
33 Serial.print(t);
34 Serial.print(" *C ");
35 Serial.print("Heat index: ");
36 Serial.print(hic);
37 Serial.println(" *C");
38
39 delay(2000);
40}
Description of application 1.
Description of application 2.
Description of application 3.