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
ModelPower
voltage
Measurement, range, accuracyCommunicationNote
Temperature measuringHumidity measuring
Temperature
Humidity
DHT11 DHT113.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%
1-Wire8 bit resolution, response time 10 sec
Temperature measuringHumidity measuring
Temperature
Humidity
DHT20 DHT203.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%
I²C
default addr.: 0x38
-
Temperature measuringHumidity measuring
Temperature
Humidity
DHT22
AM2302
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 Tasmota system. For more details, see here:

If you'd like to support the development of the site with the price of a coffee — or a few — please do so here.

Here's a handy tip: you can quickly save this page as a PDF by clicking “export to PDF” in the menu on the right side of the screen.

2026/02/14 23:38

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

PageDateTags
2026/04/23 21:51, , , , , , ,
2026/04/23 21:51, , , , , , , , ,
2025/09/23 21:25, , , , , ,
2026/03/22 03:14, , , , , , ,
2026/04/23 21:52, , , , , , , , ,
2026/04/23 21:52, , , , , , , , , , , , ,
2026/03/28 23:50, , , , , , ,
2026/04/12 00:34, , , ,
2026/04/23 21:52, , , , , , , , , , , , , ,
2026/04/23 21:52, , , , , , , , , , ,
2026/04/23 21:52, , , , , , , , , ,
2026/03/22 00:08, , , , , , , , , , ,
2026/04/23 21:52, , , , , , , , , , ,
2026/04/23 21:52, , , , , , , , ,
2026/04/23 21:52, , , , , , , ,
2026/04/23 21:52, , , , , ,
2025/05/31 23:32, , , , , , , ,
2026/04/23 21:52, , , , , , , , , , , , , ,
2025/11/22 00:07, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
2023/07/01 17:29, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
2026/03/22 01:44, , , , , , , , ,
2026/04/23 21:52, , , , , , , , ,
2026/04/23 21:52, , , , , , , , , , , , , , , ,
2026/04/23 21:51, , , ,
2026/04/23 21:52, , , , , , , , , , , , , , , , , , , , , , , , ,
2026/04/11 19:54, , , , , , , , , , , , , , , , , , ,
2026/04/23 21:52, , , , , , , , , , ,
2026/02/14 18:27, , , , , , , , , ,
2026/04/23 21:52, , , , , , ,
2026/04/23 21:52, , , , , , , ,
2026/04/23 21:52, , , , , , , ,
2026/04/23 21:52, , , , , , , , , , , , ,
2026/04/15 19:41, , , , , , , , , , , , , , , ,
2026/04/23 21:52, , , , , , , , , , , , , ,
2026/02/14 23:47, , , ,
2026/02/14 23:51, , , , , ,
2026/02/14 18:26, , , ,
2026/04/23 21:52, , , , , , , , , , , , ,
2026/04/23 21:52, , , , , , , , , , ,
2026/04/23 21:52, , , , , , , ,
2026/03/05 21:19, , , , , , , , , , , , , , , , ,
2026/02/14 18:27, , , , , , ,



This page has been accessed for: Today: 2, Until now: 4