embedded-dht-rs
Welcome to embedded-dht-rs, a Rust library designed to make working with DHT sensors a breeze!
This library only depends on embedded_hal, making it versatile and compatible with virtually any microcontroller.
Support for DHT11, DHT20, and DHT22 Sensors: All three sensors are fully implemented and ready for use.
We’ve tested it with the ESP32-WROOM, and you can find a detailed example below to help you get started.
Getting Started
Tutorials
Here are some general tutorials that provide brief introductions to embedded programming:
- Part 1 (Introduction) - Introduction to Embedded Systems with Rust: A Beginner's Guide Using ESP32
- Part 2 (LED + Button) - Building a Simple LED and Button Interface with Rust on ESP32
Example - ESP32
use ;
use esp_backtrace as _;
use ;
use HertzU32;
!

Implementation Specification
We have gathered all the information you need to understand in order to implement a library like this. Additionally, we’ve included a few comments in the code for those curious about the details, based on the following specification.
The DHT20 differs from the DHT11 and DHT22 because it uses the I2C communication protocol, while both the DHT11 and DHT22 rely on a single-wire signal for data transmission.
Comparison of DHT11, DHT20, and DHT22 40-Bit Data Formats
| Feature | DHT11 | DHT20 | DHT22 |
|---|---|---|---|
| Data Structure | - Byte 1: Humidity Int- Byte 2: Humidity Dec (0)- Byte 3: Temp Int- Byte 4: Temp Dec (0)- Byte 5: Checksum | - Byte 1: Humidity High- Byte 2: Humidity Low- Byte 3: Temp High- Byte 4: Temp Low- Byte 5: CRC | - Byte 1: Humidity High- Byte 2: Humidity Low- Byte 3: Temp High- Byte 4: Temp Low- Byte 5: Checksum |
| Precision | Integer only | Higher precision with decimals | Higher precision with decimals |
| Example Temp | 25°C | 25.6°C | 25.6°C |
| Example Humidity | 60% | 60.5% | 60.5% |
| Example Data Bytes | 60, 0, 25, 0, 85 |
2, 93, 1, 0, CRC |
2, 93, 1, 0, 96 |
| Range | Temp: 0–50°CHum: 20–90% | Temp: -40–80°CHum: 10–90% | Temp: -40–80°CHum: 0–100% |
Example Schematic

