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.

BMP085 Temperature/Pressure Sensor

I am able to get live temperature and pressure readings from the BMP085 sensor (purchased from here)

Wiring

I have a strange 6 pin BMP085 with a the following BMP085pins (VCC, SDA, SDL, XCLR, EDC, GND).

I connected the VCC to 3.3v, GND to GND, SDA to Adriano Analog 4 and SDL to Adriano Analog 5.

Code

First I used code from here but ended up using code from here to get better decimal formatting.

My Pressure hPa values were of so I added a bias.

    Serial.print("Pressure Hpa: ");
    Serial.print(pressure / 95.2, 0); //whole number only.
    Serial.println(" hPa");

    The standard atmosphere value is

    float atm = pressure / 101325; // "standard atmosphere"

    Values

    Temperature: 23.50 c
    Pressure Hpa: 1009 hPa
    Altitude: 448.75 M

    Temperature: 23.40 c
    Pressure Hpa: 1009 hPa
    Altitude: 449.27 M

    Temperature: 23.40 c
    Pressure Hpa: 1009 hPa
    Altitude: 448.75 M

    Temperature: 23.40 c
    Pressure Hpa: 1009 hPa
    Altitude: 449.01 M

    Temperature: 24.20 c
    Pressure Hpa: 1009 hPa
    Altitude: 449.09 M

    Temperature: 25.10 c
    Pressure Hpa: 1009 hPa
    Altitude: 448.92 M

    Temperature: 26.70 c
    Pressure Hpa: 1009 hPa
    Altitude: 450.05 M

    Temperature: 27.20 c
    Pressure Hpa: 1009 hPa
    Altitude: 451.18 M

    Temperature: 26.90 c
    Pressure Hpa: 1008 hPa
    Altitude: 452.31 M

    Temperature: 27.30 c
    Pressure Hpa: 1009 hPa
    Altitude: 449.44 M

    Temperature: 26.60 c
    Pressure Hpa: 1009 hPa
    Altitude: 450.49 M

Reading’s match: http://www.bom.gov.au/products/IDN60801/IDN60801.95762.shtml

Next

Humidity, Water and Light Sensors.