Freetronics Temperature and Humidity Sensor (DHT22)

The Sensor

Today I plugged in my new DHT22 temperature and Humidity sensor (buy here).

dht22-sensor

    Features:

  • -4°C to +125°C temperature range with +/-0.5°C accuracy
  • 0-100% relative humidity with 2-5% accuracy
  • 0.5Hz sample rate (one sample every 2 seconds)
  • 3 to 5V operation
  • Power consumption just 4.3mA during reads, even less when idle
  • Blue power LED
  • Dimensions: 31(W) x 23(H) x 4(D)mm

The Wiring

  • VIN: Connect to 5V on your microcontroller.
  • DATA: Connect to a digital I/O line on your microcontroller (e.g Pin 13).
  • GND: Connect to GND (0V) on your microcontroller.

The Code

    >#include
    #include

    #define DHTPIN 13
    #define DHTTYPE DHT22

    DHT dht(DHTPIN, DHTTYPE);

    void setup()
    {
    Serial.begin(115200);
    dht.begin();
    }

    void loop()
    {
    float h = dht.readHumidity();
    float t = dht.readTemperature();

    if (isnan(t) || isnan(h))
    {
    Serial.println("Error reading DHT!");
    }
    else
    {
    Serial.print("Humidity: ");
    Serial.println(h);
    Serial.print("Temp: ");
    Serial.println(t);
    }
    delay(2000);
    }

The Results

Values before and after breathing into the sensor.

    dht22_values

Troubleshooting

I was saving the DHT driver files (DHT.h) to “C:\Program Files (x86)\Arduino\libraries\DHT” and not “%UserProfile%\My Documents\Arduino\libraries”. This is common knowledge but no one says this here, here or here.

One thought on “Freetronics Temperature and Humidity Sensor (DHT22)”

  1. Hi Simon,

    Angus from Freetronics here. Thanks for the gotcha on the library path explanation, I’ve updated the QuickStart guide and the Library home page to link to our Arduino Libraries Howto.

    Hope you enjoy your DHT sensor!

    – Angus

Comments are closed.