Temperature and Humidity Sensor(DHT11)

아두위키 : Arduwiki
ArduWiki (토론 | 기여)님의 2024년 3월 23일 (토) 17:13 판 (Created page with "center|class=coders100 This sensor measures ambient temperature and humidity, outputting the data as a digital signal. It utilizes a capacitive humidity sensor and a thermistor for measurements. == '''Specifications''' == * Operating Voltage: 3.3V ~ 5V * Measurement Range: Temperature (0°C ~ 50°C) / Humidity (20% ~ 90%) * Error Range: Temperature (±2°C) / Humidity (±5%) == '''Required Hardware''' == * DHT11 * Arduino == '''...")
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

This sensor measures ambient temperature and humidity, outputting the data as a digital signal. It utilizes a capacitive humidity sensor and a thermistor for measurements.

Specifications

  • Operating Voltage: 3.3V ~ 5V
  • Measurement Range: Temperature (0°C ~ 50°C) / Humidity (20% ~ 90%)
  • Error Range: Temperature (±2°C) / Humidity (±5%)

Required Hardware

  • DHT11
  • Arduino

Connection

DHT11 Arduino
+ 5V
OUT D2
- GND

Library


Example Code

#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
    Serial.begin(9600);
    Serial.println("DHT11 test!");

    dht.begin();
}

void loop() {
    delay(2000);

    float h = dht.readHumidity();
    float t = dht.readTemperature();
    float f = dht.readTemperature(true);

    if (isnan(h) || isnan(t) || isnan(f)) {
        Serial.println("Failed to read from DHT sensor!");
        return;
    }

    float hif = dht.computeHeatIndex(f, h);
    float hic = dht.computeHeatIndex(t, h, false);

    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.print(" *C ");
    Serial.print(f);
    Serial.print(" *F\t");
    Serial.print("Heat index: ");
    Serial.print(hic);
    Serial.print(" *C ");
    Serial.print(hif);
    Serial.println(" *F");
}

Execution Result