Monday, August 4, 2014

Humidity Sensor DHT21

The Humidity Sensor, DHT21, was the permanent humidity sensor embedded into the payload of the Mt. SAC High Altitude Balloon Project (Mt. SAC HAB). Operational from 80 to -20 Celsius, the sensor was capable to produce accurate data while on the weather balloon as well as in the pretest with other sensors in a vacuum sealed bell jar. This time, the sensor was powered by a 5V line, though it is operational at 3.3V-5.2V. Three wires connected to the arduino nano - VDD (red), SDA (yellow), GND (black). SDA, or serial data is the only line that communicates with the nano via digital port. Arduino website had a great library.





#include <dht.h>

dht DHT;

#define DHT21_PIN 5

void setup()
{
  Serial.begin(115200);
  Serial.println("DHT TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT_LIB_VERSION);
  Serial.println();
  Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}

void loop()
{
  // READ DATA
  Serial.print("DHT21, \t");
  int chk = DHT.read21(DHT21_PIN);
  switch (chk)
  {
    case DHTLIB_OK:  
Serial.print("OK,\t"); 
break;
    case DHTLIB_ERROR_CHECKSUM: 
Serial.print("Checksum error,\t"); 
break;
    case DHTLIB_ERROR_TIMEOUT: 
Serial.print("Time out error,\t"); 
break;
    default: 
Serial.print("Unknown error,\t"); 
break;
  }

  // DISPLAY DATA
  Serial.print(DHT.humidity, 1);
  Serial.print(",\t");
  Serial.println(DHT.temperature, 1);

  delay(2000);
}

No comments:

Post a Comment