electronicsfan123
Published © GPL3+

Interfacing DHT22/DHT11 with Arduino uno

In this tutorial we are going to see how to interface DHT22 and DHT11 with Arduino uno.

BeginnerFull instructions provided5,501
Interfacing DHT22/DHT11 with Arduino uno

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Coe3

C/C++
This is the code for the project.
#include <DHT.h> 
 #define DHTPIN 9 // The data pin of DHT11/DHT22 should be connected to the digtal pin 9 of Arduino.   
 #define DHTTYPE DHT22
 DHT dht ( DHTPIN, DHTTYPE ) ;
 void setup ( ) { // Void setup is the function which technically created at the top of the program. It is used to initialize variables, pin modes, start using libraries, etc. 
   Serial.begin ( 9600 ) ;
   dht.begin (  ) ;    
 }
 void loop ( ) { // The loop is ran again and again and consists the main code.

float humidity = dht.readHumidity ( ) ;  
  float Temprature = dht.readTemperature ( ) ; 
   if ( isnan ( Temprature ) || isnan ( humidity ) ) {
     Serial.println ( " Sensor is not avaliable right now " ) ;  }

 else

{

Serial.print ( " Temprature is " ) ;  
     Serial.print ( Temprature ) ;         
     Serial.println ( " *C " ) ;      
     Serial.print ( " Humidity in % is : " ) ;                    
     Serial.print ( humidity ) ;   
     Serial.print ( " % \t " ) ;     
                                                           
   }
 }

Credits

electronicsfan123
5 projects • 9 followers
Contact

Comments

Please log in or sign up to comment.