====== LamaPLC: DHT Temperature /Humidity sensors with 1-wire / I²C communication ====== The DHT is a popular, low-cost digital sensor that measures both temperature and humidity. DHT22 offers higher accuracy than its predecessor, the DHT11. It is suitable for a wide range of applications, including weather stations and smart home systems. ^Type of \\ measurement ^Model^Power \\ voltage ^Measurement, range, accuracy^Communication^Note| |{{anchor:dht11}}{{:sensor:t.png|Temperature measuring}}{{:sensor:h.png|Humidity measuring}} \\ Temperature \\ Humidity |**DHT11** {{ :sensor:dht_11.png?100 |DHT11}}|**3.3 / 5 V** \\ (3.3 .. 5.5V)|Temperature measurement range: 0 .. +50 °C\\ Temperature measurement accuracy: ±2°C\\ Humidity measurement range: 20..90% RH\\ Humidity measurement accuracy: ±5%|[[com:basic_1wire|1-Wire]]|8 bit resolution, response time 10 sec| |{{anchor:dht20}}{{:sensor:t.png|Temperature measuring}}{{:sensor:h.png|Humidity measuring}} \\ Temperature \\ Humidity |**DHT20** {{ :sensor:dht_20.png?100 |DHT20}}|**3.3 / 5 V** \\ (2.2 .. 5.5V)|Temperature measurement range: -40 .. +80 °C\\ Temperature measurement accuracy: ±0.5°C (-40..80)\\ Humidity measurement range: 0..100% RH\\ Humidity measurement accuracy: ±3%|[[com:basic_i2c|I²C]] \\ default addr.: **0x38**|-| |{{anchor:dht22}}{{anchor:am2302}}{{:sensor:t.png|Temperature measuring}}{{:sensor:h.png|Humidity measuring}} \\ Temperature \\ Humidity |**DHT22 \\ AM2302** {{ :sensor:dht_22.png?100 |DHT22}}|**3.3 / 5 V** \\ (2.2 .. 5.5V)|Temperature measurement range: -40 .. +80 °C\\ Temperature measurement accuracy: ±0.5°C (-40..80)\\ Humidity measurement range: 0..100% RH\\ Humidity measurement accuracy: ±2%|single-bus|-| **Operation and Usage** The DHTs use a single bus for communication, which requires careful timing; this is typically handled by libraries in microcontroller environments. A 4.7kΩ to 10kΩ pull-up resistor is needed between the data line and VCC for proper communication. The sensors are available in two main forms: a 4-pin bare sensor and a 3-pin module with the pull-up resistor integrated. The BME/BMP sensors can be integrated with the [[https://tasmota.github.io/docs/About/|Tasmota]] system. For more details, see here: * DHT11 sensors: https://tasmota.github.io/docs/DHT11/ {{page>:tarhal}} ==== Arduino & DHT22 ==== To read a DHT22 sensor with an Arduino, you typically use the **Adafruit DHT Sensor Library** along with the Adafruit Unified Sensor Library. **Wiring Details** The wiring depends on whether you have a bare sensor or a module: * **VCC:** 3.3V to 5V. * **GND:** Ground. * **Data (DQ):** Digital pin (e.g., Pin 2). * **Pull-up Resistor:** Bare 4-pin sensors require a 4.7kΩ to 10kΩ pull-up resistor from VCC to Data. Modules with 3 pins usually have this resistor built-in. **Arduino Example Code** This sketch reads temperature (in Celsius) and humidity every 2 seconds. #include "DHT.h" #define DHTPIN 2 // Digital pin connected to the DHT sensor #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 // Initialize DHT sensor. DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); Serial.println(F("DHT22 test!")); dht.begin(); } void loop() { delay(2000); // Wait 2 seconds between measurements // Read humidity and temperature float h = dht.readHumidity(); float t = dht.readTemperature(); float f = dht.readTemperature(true); // Temperature in Fahrenheit // Check for read failures if (isnan(h) || isnan(t) || isnan(f)) { Serial.println(F("Failed to read from DHT sensor!")); return; } // Print results Serial.print(F("Humidity: ")); Serial.print(h); Serial.print(F("% Temperature: ")); Serial.print(t); Serial.print(F("°C ")); Serial.print(f); Serial.println(F("°F")); } ===== 1-wire, I2C topics on lamaPLC ===== {{topic>1-wire, i2c}} \\ \\ {{tag>DHT11 DHT20 DHT22 temperature humidity pressure sensor 1-wire arduino code}} This page has been accessed for: Today: {{counter|today}}, Until now: {{counter|total}}