#dht22 #temperature-sensor #embedded-hal

no-std dht22-sensor

A no_std driver for the DHT22 (AM2302) temperature and humidity sensor

1 unstable release

Uses new Rust 2024

0.1.0 Jul 23, 2025

#1896 in Hardware support

MIT license

20KB
322 lines

DHT22 Sensor Driver

A platform-agnostic driver for the DHT22 (AM2302) temperature and humidity sensor using embedded-hal traits.
Designed for use in no_std embedded environments.


Features

  • Supports blocking reads from the DHT22 sensor.
  • Compatible with any platform that implements embedded-hal traits.
  • no_std support.
  • Tested using embedded-hal-mock.

Usage

Add this to your Cargo.toml:

[dependencies]
# dht22-sensor = "0.1" 
dht22-sensor = { git = "https://github.com/implferris/dht22-sensor" }

Example

use dht22_sensor::Dht22;
use embedded_hal::digital::{InputPin, OutputPin};
use embedded_hal::delay::DelayNs;

// `pin` must support switching between input/output modes.
// `delay` should implement DelayNs for microsecond delays.

let mut dht = Dht22::new(pin, delay);
match dht.read() {
    Ok(reading) => {
        info!("Temperature: {:.1} °C", reading.temperature);
        info!("Humidity: {:.1} %", reading.humidity);
    }
    Err(e) => {
        error!("DHT22 read error: {:?}", e);
    }
}

License

MIT

Dependencies

~200KB