DHT11 Arduino

Viewing a single blog post

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.

 
 
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: DHT-Library

Posted in Arduino on Sep 02, 2018


Comments

Please sign in to comment!