Remarks

Dht12
Status
Source code GitHub
NuGet package

The DHT12 is a low-cost humidity and temperature sensor that communicates over the I2C bus. It measures humidity from 20 to 95% with an accuracy of +/- 5% relative humidity with a resolution of 0.1%. Temperature range is from -20 to 60 degrees celcius with an accuracy of +/- 0.5 degrees and a resolution of 0.1.

Code Example

public class MeadowApp : App<F7Micro, MeadowApp>
{
    Dht12 sensor;

    public MeadowApp()
    {
        sensor = new Dht12(Device.CreateI2cBus());
        sensor.StartUpdating();
        sensor.Updated += SensorUpdated;
    }

    void SensorUpdated(object sender, Meadow.Peripherals.Sensors.Atmospheric.AtmosphericConditionChangeResult e)
    {
        Console.WriteLine($"Humidity: {e.New.Humidity}%, Temperature: {e.New.Temperature}°C");
    }
}

Sample projects available on GitHub

Wiring Example

To wire a DHT12 to your Meadow board, connect the following:

DHT12 Meadow Pin
GND GND
VCC 3V3
SCL D08 (SCL Pin)
SDA D07 (SDA Pin)

Characteristic Locus
Inheritance System.Object DhtBase > Dht12
Implements IAtmosphericSensor ITemperatureSensor IHumiditySensor
Inherited Members DhtBase._sensor DhtBase._readBuffer DhtBase.Temperature DhtBase.Humidity DhtBase.Conditions DhtBase.IsSampling DhtBase.WasLastReadSuccessful DhtBase.Updated DhtBase.Read() DhtBase.StartUpdating(Int32) DhtBase.RaiseChangedAndNotify(AtmosphericConditionChangeResult) DhtBase.StopUpdating() DhtBase.Update()
Namespace Meadow.Foundation.Sensors.Atmospheric
Assembly Dhtxx.dll

Syntax

public class Dht12 : DhtBase, IAtmosphericSensor, ITemperatureSensor, IHumiditySensor

Constructors

Dht12(II2cBus, Byte)

Create a new Dht12 object.

Declaration
public Dht12(II2cBus i2cBus, byte address = 92)

Parameters

Type Name Description
II2cBus i2cBus

I2C bus (default = 100 KHz).

System.Byte address

Address of the Dht12 (default = 0x27).