Temperature & Humidity Monitoring

One of the earliest projects many people build is temperature & humidity measurement, which is a fun project because it is somewhat interactive and useful, and also very simple to wire up.

Many of the Arduino starter-kits will come with a DHT11 sensor, which can measure both humidity and temperature. If you want to build something more accurate though you'll need to look at getting yourself a DHT22 sensor.


DHT113/4-pin, measures integer values only. e.g. 20°C.
DHT223/4-pin, measures floags. e.g. e.g. 20.3°C


The will vary depending on whether you have the raw device, which has 4 pins, or you've got it hooked up to a simple circuit board.




The DHTLib library can be used to read the output of both devices, but you'll need to invoke the correct method.

The following will show the temperature/humidity for a DHT11:

#include <dht.h>

#define DHT11_PIN D2

void setup()

  dht DHT;
  int chk = DHT.read11(DHT11_PIN);
  if (chk == DHTLIB_OK )
     // Show the result on the serial console.
     Serial.print("Humidity:" );
     Serial.print(DHT.humidity, 1);
     Serial.print(" Temperature");
     Serial.println(DHT.temperature, 1);

To work with a DHT22 instead you'd change the code to read:

#include <dht.h>

#define DHT22_PIN D2

void setup()
  int chk = DHT.read22(DHT22_PIN);

I put together a simple project, including the library, which will send the current temperature & humidity values to a local MQQ-queue. You can find this project in my git repository, you can access all the source by cloning the repo involved, and then looking at the project:

Advanced Projects

I now have a more advanced version of this project, which allows for a number of devices to send their data over a central message-bus. When the data is received it is recorded in a local SQLite database, and can then be graphed.

See the advanced project here.