top of page

Safari browser sometimes has issues displaying images...

I.e: *you have to click on the images to see them...

For a better browsing experience on Brainy-Bits

Please use Chrome, Edge or Firefox browser.

Writer's pictureBrainy-Bits

How to use the DHT11 Temperature and Humidity Sensor with an Arduino!



OVERVIEW


In this tutorial we will learn how to use a DHT (DHT11 version) Temperature and Humidity Sensor.


It’s accurate enough for most projects that need to keep track of humidity and temperature readings.


Again we will be using a Library specifically designed for these sensors that will make our code short and easy to write.


 

PARTS USED


DHT-11 Temperature sensor


Arduino UNO

Dupont Wires


These are Amazon affiliate links...

They don't cost you anything and it helps me keep the lights on

if you buy something on Amazon. Thank you!

 

CONNECTIONS




As you can see we only need 3 connections to the sensor, since one of the pin is not used.


The connection are : Voltage, Ground and Signal which can be connected to any Analog Pin on our UNO.

 

THE CODE


Since we will be using a Library that is available for this sensor, our code will be very short and simple.


Once you have the library, just go ahead and extract it to the Library folder inside your Arduino IDE software folder.



#include "dht.h"
#define dht_apin A0 // Analog Pin sensor is connected to
 
dht DHT;
 
void setup(){
 
  Serial.begin(9600);
  delay(500);//Delay to let system boot
  Serial.println("DHT11 Humidity & temperature Sensor\n\n");
  delay(1000);//Wait before accessing Sensor
 
}//end "setup()"
 
void loop(){
  //Start of Program 
 
    DHT.read11(dht_apin);
    
    Serial.print("Current humidity = ");
    Serial.print(DHT.humidity);
    Serial.print("%  ");
    Serial.print("temperature = ");
    Serial.print(DHT.temperature); 
    Serial.println("C  ");
    
    delay(5000);//Wait 5 seconds before accessing sensor again.
 
  //Fastest should be once every two seconds.
 
}// end loop() 

 

TUTORIAL VIDEO



 

DOWNLOAD


For the Arduino code, just copy and paste the code above in your Arduino IDE software.


You can download the DHT Library we used here:


78,298 views0 comments

Comments


All my content is and will always be Free.

If you feel that my Videos / Tutorials are helping, and you would like to contribute...

 You can toss some coins in the Tip Jar via PayPal.

Select amount then click the “Donate” button.

bottom of page