Arduino with DHT11 - ElectroEngineers

Destination to project makers.

Sunday, 20 August 2017

Arduino with DHT11

DHT 11 is a digital temperature humidity sensor. It can be directly interfaced with arduino's digital pins. Dht 11 sensor has four pins out of which one is unused. The other three pins are vcc, ground and dout.

Components required
DHT11
Arduino uno/mega/mini/nano
Connecting wires

Softwares: Arduino IDE, DHT11 library

Step1. Download the DHT11 library from the abouve link
Step2. Connect DHT11 sensor to the Arduino.
             Vcc -- 5v
             Gnd - gnd of arduino
             Dout - any desired digital pin

Step 3. Upload the sketch below.
ARDUIONO CODE


  1. #include <dht.h>

  2. dht DHT;

  3. #define DHT11_PIN 5

  4. void setup()
  5. {
  6.   Serial.begin(115200);
  7.   Serial.println("DHT TEST PROGRAM ");
  8.   Serial.print("LIBRARY VERSION: ");
  9.   Serial.println(DHT_LIB_VERSION);
  10.   Serial.println();
  11.   Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
  12. }

  13. void loop()
  14. {
  15.   // READ DATA
  16.   Serial.print("DHT11, \t");
  17.   int chk = DHT.read11(DHT11_PIN);
  18.   switch (chk)
  19.   {
  20.     case DHTLIB_OK:  
  21.                 Serial.print("OK,\t"); 
  22.                 break;
  23.     case DHTLIB_ERROR_CHECKSUM: 
  24.                 Serial.print("Checksum error,\t"); 
  25.                 break;
  26.     case DHTLIB_ERROR_TIMEOUT: 
  27.                 Serial.print("Time out error,\t"); 
  28.                 break;
  29.     case DHTLIB_ERROR_CONNECT:
  30.         Serial.print("Connect error,\t");
  31.         break;
  32.     case DHTLIB_ERROR_ACK_L:
  33.         Serial.print("Ack Low error,\t");
  34.         break;
  35.     case DHTLIB_ERROR_ACK_H:
  36.         Serial.print("Ack High error,\t");
  37.         break;
  38.     default: 
  39.                 Serial.print("Unknown error,\t"); 
  40.                 break;
  41.   }
  42.   // DISPLAY DATA
  43.   Serial.print(DHT.humidity, 1);
  44.   Serial.print(",\t");
  45.   Serial.println(DHT.temperature, 1);

  46.   delay(2000);
  47. }
The output will be displayed on the serial monitor.
Got any problems? Feel free to contact us.

No comments:

Post a Comment

Followers