How to use DHT11 sensor - Simple Tutorial

Friday, April 21, 2017

Arduino DHT11 sensor tutorial

This is a simple, brief  guide to use or test your DHT11 temperature and humidity sensor with arduino for first time.

By using below sketch you can see the real time reading of DHT11 sensor in your aruino IDE serial monitor. 


Parts required 

  • Arduino UNO/Nano (any arduino board)
  • DHT11 sensor module
  • Jumper cables 
  • LED bulb

Steps

  1.  Connect VCC of DHT11 sensor to Arduino pin 5V
  2.  Connect OUT of  DHT11 sensor to Arduino pin 9
  3.  Connect GND of  DHT11 sensor to Arduino pin GND

Circuit diagram of DHT11 with arduino.

Arduino DHT11 sensor circuit diagram

Source code for DHT11 with arduino.

First download the library and paste in your arduino library folder.

 //   
 //  FILE: dht11_test1.pde  
 // PURPOSE: DHT11 library test sketch for Arduino  
 //  
 #include <dht11.h>  
 dht11 DHT;  
 #define DHT11_PIN 9  
   
 void setup(){  
  Serial.begin(9600);  
  Serial.println("DHT TEST PROGRAM ");  
  Serial.print("LIBRARY VERSION: ");  
  Serial.println(DHT11LIB_VERSION);  
  Serial.println();  
  Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");  
 }  
   
 void loop(){  
  int chk;  
  Serial.print("DHT11, \t");  
  chk = DHT.read(DHT11_PIN);  // READ DATA  
  switch (chk){  
   case DHTLIB_OK:   
         Serial.print("OK,\t");   
         break;  
   case DHTLIB_ERROR_CHECKSUM:   
         Serial.print("Checksum error,\t");   
         break;  
   case DHTLIB_ERROR_TIMEOUT:   
         Serial.print("Time out error,\t");   
         break;  
   default:   
         Serial.print("Unknown error,\t");   
         break;  
  }  
  // DISPLAT DATA  
  Serial.print(DHT.humidity);  
  Serial.print(",\t");  
  Serial.println(DHT.temperature);  
   
  delay(1000);  
 }  
   

Click here to download the code

You Might Also Like

0 comments

Click on 'Notify me' to get replies of your comment.

Popular Posts

Like us on Facebook

Contact Form

Name

Email *

Message *