DHT11 Sensor With Arduino To Find Humidity And Temperature

Introduction
 
In this article I'll let you know how to use DHT11 Sensor with the Arduino Uno to find humidity and temperature
 
Requirements
  • Arduino Uno
  • DHT11 Sensor
  • Bread Board
  • Led
  • Jumper Wires  
Connection
  • Vcc to Arduino 5v
  • Data Out to Arduino Digital Pin 7
  • Gnd to Arduino Gnd
Led
  • Anode pin to the Arduino digital pin 13
  • Cathode pin to the Arduino Gnd 
DHT11 Sensor
 
 

Programming
 

Please download the DHT library from the following link.

Go to Sketch, Include Library, then add Zip File. 
  1. #include<dht.h>  
  2. dht DHT;  
  3. #define DHT11_PIN 7
  4. int led=13;  
  5. int temperature;
  6. void setup()  
  7. {  
  8.   Serial.begin(9600);  
  9.   pinMode(led,OUTPUT);
  10.   Serial.println("TESTER PROGRAM HUMIDITY SENSOR");  
  11.     
  12. }  
  13. void loop()  
  14. {  
  15.   int chk=DHT.read7(DHT11_PIN);  
  16.   Serial.println("Humidity"); 
  17.   Serial.println(DHT.humidity,1);  
  18.   Serial.println("Temperature"); 
  19.   if(temperature>20)
  20.   {
  21.    digitalWrite(led,HIGH);
  22.    }
  23.   else{
  24.    digitalWrite(led,LOW);
  25.   }
  26.   Serial.println(DHT.temperature,1);  
  27.   delay(1000);  
  28. }  
Explanation
  • Include the library first before you code set DHT11 sensor PIN as 7 and led as 13.
  • In the setup function set the pinMode led as OUTPUT and set the baudrate as 9600.
  • In the loop function we want to give the condition for DHT11 sensor DHT. Read the sensor value from the Arduino board.
  • And print the value in the serial monitor for humidity and temperature.
  • The led is HIGH if temperature is greater than 20, else the led is LOW. 
Output
 
 
 
Read more articles on Arduino:

Up Next
    Ebook Download
    View all
    Learn
    View all