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 22: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
2025/05/31 21:56, , , , , , ,
2025/09/23 21:03, , , , , , , , ,
2025/09/23 19:25, , , , , ,
2026/03/21 19:20, , , , , , ,
2026/02/15 20:33, , , , , , , , ,
2026/02/14 22:24, , , , , , , , , , , , ,
2026/02/15 20:40, , , , , , , , , , , , , ,
2026/02/14 23:37, , , , , , , , , , ,
2026/02/14 22:40, , , , , , , , , ,
2026/03/21 22:25, , , , , , , , , , ,
2026/02/14 18:19, , , , , , , , , , ,
2026/02/15 20:42, , , , , , , , ,
2026/02/14 18:11, , , , , , , ,
2026/02/15 20:44, , , , , ,
2025/05/31 21:32, , , , , , , ,
2026/02/14 19:29, , , , , , , , , , , , , ,
2025/11/21 23:07, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
2023/07/01 15:29, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
2026/03/22 00:26, , , , , , , , ,
2026/02/14 22:45, , , , , , , , ,
2026/02/14 22:09, , , , , , , , , , , , , , , ,
2026/02/14 17:26, , , ,
2026/02/14 21:54, , , , , , , , , , , , , , , , , , , , , , , , ,
2026/02/14 23:58, , , , , , , , , , ,
2026/02/14 17:27, , , , , , , , , ,
2026/02/14 23:38, , , , , , ,
2026/02/14 22:52, , , , , , , ,
2026/02/14 22:23, , , , , , , ,
2026/02/14 22:53, , , , , , , , , , , , ,
2026/02/15 20:27, , , , , , , , , , , , , , , ,
2026/02/15 20:29, , , , , , , , , , , , , ,
2026/02/14 22:47, , , ,
2026/02/14 22:51, , , , , ,
2026/02/14 17:26, , , ,
2026/02/14 22:22, , , , , , , , , , , , ,
2026/02/14 22:21, , , , , , , , , , ,
2026/02/14 22:22, , , , , , , ,
2026/03/05 20:19, , , , , , , , , , , , , , , , ,
2026/02/14 17:27, , , , , , ,



This page has been accessed for: Today: 1, Until now: 36