Thursday 12 December 2013

Temperature & Humidity

Now here's a very neat device. A small unit that measures Temperature (degC) and Humidity (%) directly.

2013 12 12 13 07 36
Communication with the device is tricky, but there is an Arduino Library "dht11.h" which make the whole thing very simple. See Here. You have to copy the ".h" and ".cpp" files one by one to a text editor and save them. Then put them in your Arduino library folder in a sub folder called "dht11"

The connections are (S = Signal, Centre Pin = +5V, - = GND):

2013 12 12 13 09 50
The pull up resistor is essential, otherwise you get wrong readings...

Here's my test bed:

2013 12 12 13 08 12

And the display on the Serial Monoitor of the Arduino IDE:

Screen Shot 2013 12 12 at 13 05 34 The code

#include "dht11.h"

dht11 DHT11;

#define DHT11PIN 2

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  delay(2000);
}

void loop()
{
  Serial.println("\n");

  int chk = DHT11.read(DHT11PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case DHTLIB_OK: 
		Serial.println("OK"); 
		break;
    case DHTLIB_ERROR_CHECKSUM: 
		Serial.println("Checksum error"); 
		break;
    case DHTLIB_ERROR_TIMEOUT: 
		Serial.println("Time out error"); 
		break;
    default: 
		Serial.println("Unknown error"); 
		break;
  }

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (C): ");
  Serial.println((float)DHT11.temperature, 2);

  delay(2000);
}

No comments: