Arduino and DHT11

A simple project using Arduino and DHT11 Temperature and Humidity sensor.

I bought this sensor at Dht-11

The DHT11 is a simple Humidity and temperature sensor, with 8 bits of resolution. The precision is really poor, of 1 degree celcius and 1-2% for relative humidity. But is good for a quick start.

The circuit is simple:


The DHT11 pins are, from left to right ( frontview ) , S, Vcc and Gnd.

The program is also simple, and you can find the library at Arduino site,

Install the library at Arduino libraries directory:

And compile the program:

// Example testing sketch for various DHT humidity/temperature sensors

#include “DHT.h”
// include the library code:

#define DHTPIN 5 // what pin we’re connected to

// Uncomment whatever type you’re using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin 1 of the sensor to whatever your DHTPIN is
// Connect pin 2 (on the left) of the sensor to +5V
// Connect pin 3 (on the right) of the sensor to GROUND


void setup() {
Serial.println(“DHTxx test!”);


void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
float t = dht.readTemperature();

// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
Serial.println(“Failed to read from DHT”);
} else {
Serial.print(“Humidity: “);
Serial.print(” %\t”);
Serial.print(“Temperature: “);
Serial.println(” *C”);
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(” – “);

Compile and upload at Arduino interface, and see the results at your Serial monitor!