DHT11 interfacing with arduino and weather station

DHT11 sensor is used to measure the temperature and humidity. It has a resistive humidity sensing component and a negative temperature coefficient (NTC). An 8 bit MCU is also connected in it which is responsible for its fast response. It is very inexpensive but it gives values of both temperature and humidity at a time.DHT11 humifity and temperature sensor with arduino

Specification of DHT11

  • It has humidity range from 20 to 90% RH
  • It has temperature range from 0 – 50 C
  • It has signal transmission range of 20 m
  • It is inexpensive
  • It has fast response and it is also durable

DHT11 Pin out

dht11

  • The first pin of the DHT11 is vcc pin.
  • The second pin of the DHT is Data pin.
  • The third pin is not used.
  • The fourth pin of the DHT sensor is ground.

 

DHT11 interfacing with arduino

First of all connect the ground and the VCC of the DHT11 temperature and humidity sensor to the ground and 5v of the Arduino. Then connect the data pin of the DHT11 sensor to the pin 2 of the Arduino.dht11 interfacing with arduino

Installing the DHT11 Library 

To run the following code in Arduino IDE you will first have to install the DHT library in you Arduino directory.

Download the zip file from here and place it in your Arduino library folder. The path to Arduino library folder for my computer is

Documents/ Arduino/ Libraries

Unzip the downloaded file and place it in this folder.

After copying the files, the Arduino library folder should have a new folder named DHT containing the dht.h and dht.cpp. After that copy the following code in the Arduino IDE and upload the code.

Code of  DHT11 interfacing with arduino

// Code for DHT11 Temperature and humidity sensor.
 #include " DHT.h "    // including the library of DHT11 temperature and humidity sensor
 #define DHTPIN 2      // Selecting the pin at which we have connected DHT11
 #define DHTTYPE DHT11 // Selecting the type of DHT sensors
 DHT dht ( DHTPIN, DHTTYPE ) ;
 void setup ( ) {
   Serial.begin ( 9600 ) ;
   dht.begin (  ) ;    // The sensor will start working
 }
 void loop ( ) {
   // Reading temperature or humidity may take about 2 seconds because it is a very slow sensor.

float humidity = dht.readHumidity ( ) ;  // Declaring h a variable and storing the humidity in it.
  float temp = dht.readTemperature ( ) ; // Declaring t a variable and storing the temperature in it.
  // Checking if the output is correct. If these are NaN, then there is something in it.
   if ( isnan ( t ) || isnan ( h ) ) {
     Serial.println ( " Sensor not working " ) ;
   }

 else

{

Serial.print ( " Temp is " ) ;  
     Serial.print ( temp ) ;         // Printing the temperature on display.
     Serial.println ( " *C " ) ;     // Printing “ *C ”  on display.
     Serial.print ( " Humidity in % is : " ) ;                    
     Serial.print ( humidity ) ;     // Printing the humidity on display
     Serial.print ( " % \t " ) ;     // Printing “%” on display
                                                           
   }
 }

Weather Station using DHT11 and arduino

In this example we will make a weather station that will sense the humidity and temperature and will show it on the lcd attached to the Arduino. Make the circuit as shown in the diagram. The resistor in the circuit will make the black light darker. We have used the 220 ohm resistor but you can use any resistor having value near to that. The potentiometer we used in the circuit is used to set the screen contrast. We have used the 10 K ohm value but you can choose any value relative to that one.dht11 based weather station

Components Required 

  • Arduino Uno (you can use any)
  • 16 x 2 LCD
  • DHT11 Temperature and humidity sensor
  • 10 K ohm potentiometer
  • 220 ohm resistor

Code of weather station using arduino and DHT11

// This code is for the weather station using the DHT11humidity and temperature sensor.

// Install the library of the DHT before uploading the code in the Arduino IDE

#include < dht.h >      // including the DHT library

#include < LiquidCrystal.h >   // including the LCD library

LiquidCrystal lcd ( 12, 11, 5, 4, 3, 2 ) ;  // initializing the lcd pins

dht DHT ;                       // declaring dht a variable

#define DHT11_PIN 8             // initializing pin 8 for dht

void setup ( ) {                                                

  lcd.begin ( 16, 2 ) ;       // starting the 16 x 2 lcd

}

void loop ( )

{

  int chk = DHT.read11(DHT11_PIN ) ;         // Checking that either the dht is working or not

  lcd.setCursor ( 0, 0 ) ;                   //  starting the cursor from  top left

  lcd.print ( " Temperature is : " ) ;       // printing the “ Temperature is : ” on the lcd 

  lcd.print ( DHT.temperature ) ;            // printing the temperature on the lcd

  lcd.print ( ( char ) 223 ) ;                  

  lcd.print ( " C " ) ;                     // Printing “ C “ on the display

  lcd.setCursor ( 0 , 1 );                       

  lcd.print ( " Humidity is : " ) ;         // printing “ humidity is : ” on the display

  lcd.print ( DHT.humidity ) ;              // printing humidity on the display

  lcd.print ( " % " ) ;                     // printing “ % ” on display

  delay ( 1000 ) ;                          // Giving delay of 1 second.

}

So this is all about DHT11 sensor, you can use it to wireless weather station also by adding internet of things concepts. I will also post project on wireless weather station using ESP8266 module.

6 thoughts on “DHT11 interfacing with arduino and weather station”

  1. Arduino: 1.8.0 (Windows 8.1), Board: “Arduino/Genuino Uno”

    C:\Users\Ram\Documents\Arduino\LCD\DGT11LCD\DGT11LCD.ino:3:88: fatal error: DHT.h : No such file or directory

    #include ” DHT.h ” // including the library of DHT11 temperature and humidity sensor

    ^

    compilation terminated.

    exit status 1
    Error compiling for board Arduino/Genuino Uno.

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

    I m getting like this what i have to do now

    Reply
  2. dear sir,
    this error show in many time pls tell me how clear this error.

    sketch_sep11j.ino:2:89: fatal error: DHT.h : No such file or directory
    compilation terminated.
    Error compiling.

    Reply
  3. The zip file you download is going to be referred to as “\Library/”.

    in Arduino, go to Sketch>Include Library>”Add .ZIP Library…”.
    Then navigate to your “\Library/” save location click on it once, then click open.

    Reply

Leave a Comment