DHT11-Humidity-TempSensor

From ArduinoInfo
Jump to navigation Jump to search
Digital output temperature and humidity sensor DHT11 - DHT22
DHT11-HumidityTempVSG.jpg
NOTE: Available as both a plain component, or as an Electronic Brick. (Available here: )

See photos at right: Connections are (V)oltage, (S)ignal, (G)round. On the Electronic Brick: (S)Signal, (V)Voltage,(G)Ground

NOTE: Needs 4.7K to 10K pullup resistor from +5 to Signal pin (Electronic Brick version has it built-in). Connect to Arduino Digital pin, not Analog pin. (Manufacturer says this about distance/pullup): When the connecting cable is shorter than 20 metres, a 5K pull-up resistor is recommended; when the connecting cable is longer than 20 metres, choose a appropriate pull-up resistor as needed.

Specifications:

Humidity measuring range: 20% ~ 9 0% RH (0-50 ? temperature compensation)
- Temperature measuring range: 0 ~ +50 ?C ;

Temperature-Humidity-DHT11.jpg

- Humidity measuring accuracy: 5.0% RH
- Temperature measurement accuracy: 2.0 C
- Response time: (Updated by Rob Tillaart: now < 50 ms)
- Low power consumption
Features
.. single wire digital interface ( the most simple system integration, ultra-low prices )
.. ultra-small size ( 12X15.5X5.5 mm )
.. high reliability
.. optimized long-term stability

Test Software Sketch for DHT11 (Credits: THANKS to Rob Tillaart)


DETAILS: Before you can use an "Arduino Software Library", you must make it available by copying it into the correct "libraries" folder. See Libraries HowTo HERE

Here is a .ZIP file for the newest Rob Tillaart version (recommended):

media:DHTNEW.zip


NOTE: Lots of good information about the DHT software library on the Arduino "Playground" site HERE.
NOTE: After you install the DHTLIB Library, look in EXAMPLES for similar test sketches for DHT21, DHT22
NOTE: Set your Serial Monitor(click for Info) to 115200 (Lower right of window)


//
//    FILE: dht11_test.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.01
// PURPOSE: DHT library test sketch for DHT11 && Arduino
//     URL:
//
// Released to the public domain
//

#include <dht.h>

dht DHT;

#define DHT11_PIN 5

void setup()
{
  Serial.begin(115200);
  Serial.println("DHT TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT_LIB_VERSION);
  Serial.println();
  Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}

void loop()
{
  // READ DATA
  Serial.print("DHT11, \t");
  int chk = DHT.read11(DHT11_PIN);
  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;
    case DHTLIB_ERROR_CONNECT:
        Serial.print("Connect error,\t");
        break;
    case DHTLIB_ERROR_ACK_L:
        Serial.print("Ack Low error,\t");
        break;
    case DHTLIB_ERROR_ACK_H:
        Serial.print("Ack High error,\t");
        break;
    default:
                Serial.print("Unknown error,\t");
                break;
  }
  // DISPLAY DATA
  Serial.print(DHT.humidity, 1);
  Serial.print(",\t");
  Serial.println(DHT.temperature, 1);

  delay(2000);
}
//
// END OF FILE
//



The output from this program to the Serial Monitor will be something like this:


DHT TEST PROGRAM
LIBRARY VERSION: 0.1.20

Type,    status,    Humidity (%),    Temperature (C)
DHT11,     OK,    32.0,    29.0
DHT11,     OK,    33.0,    28.0
DHT11,     OK,    33.0,    28.0
DHT11,     OK,    33.0,    28.0  (BREATHE On Sensor ! )
DHT11,     OK,    75.0,    30.0
DHT11,     OK,    75.0,    29.0
DHT11,     OK,    75.0,    29.0

 


To get ALL of Rob Tillaart's libraries download HERE


For an example of a Web Server that displays DHT11 sensor values, [/ethernet-temp-humidity see THIS:]

EXAMPLE SKETCH: DHT11, Temp, Humidity, Time (from RTC) [Connection Diagram Below]
THANKS to David Loveridge
Note: Not Tested by Terry yet...

//
// AUTHOR: Rob Tillaart, Terry King, David Loveridge
// VERSION:
// PURPOSE: DHT, RTC and LCD display Arduino
//     URL:
// Three examples brought together to create a temp / humidity and time display on a 16/2 LCD.
// RTC and LCD use i2c port (i2c Gnd 5V and pins a4 sda, a5 scl) DHT-11 BRICK unit uses Gnd 5V and pin 2
// Released to the public domain
//
/*-----( Import needed libraries )-----*/
#include <Wire.h>              // In standard library
#include <dht.h>               // https://https://arduinoinfo.mywikis.net/wiki/TemperatureHumidity
#include <LiquidCrystal_I2C.h> // https://https://arduinoinfo.mywikis.net/wiki/LCD-Blue-I2C
#include "RTClib.h"            // https://https://arduinoinfo.mywikis.net/wiki/DS1307_RealTime_Clock_Brick
/*-----( Declare Constants )-----*/

/*-----( Declare objects )-----*/
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address Ox3F (Check yours)
RTC_DS1307 rtc;    // Create a RealTimeClock object (I set the time in another sketch)
/*-----( Declare Variables )-----*/
dht DHT;
#define DHT11_PIN 2 // use pin 2 on UNO to sample data from DHT module

void setup()
{
    Serial.begin(9600);
    Serial.println("DHT TEST PROGRAM ");
    Serial.print("DHT LIBRARY VERSION: ");
    Serial.println(DHT_LIB_VERSION);
    Serial.println();
    Serial.println("Humidity % \tTemperature (C) \tTime \tDate");
    lcd.begin(16,2); // defines it is a 16 character two line display
    rtc.begin(); // Start the RTC library code
    }

void loop()
{
    // READ DATA
    DateTime now = rtc.now();
    int chk = DHT.read11(DHT11_PIN);
    Serial.print(DHT.humidity, 1);
    Serial.print(",\t");
    Serial.print("\t");
    Serial.print(DHT.temperature, 1);
    Serial.print(",\t");
    Serial.print("\t");
    Serial.print("\t");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.print(' ');
    Serial.print(now.day(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.println(now.year(), DEC);
    lcd.setCursor(0,0); // start postion of Humidity text on LCD
    lcd.print(DHT.humidity, 0); // 0 creates whole number, 1 two decimal
    lcd.print("% Humidity ");
    lcd.setCursor(0,1);  // start postion of temperature text on LCD
    lcd.print(DHT.temperature, 0);
    lcd.print(" C");
    lcd.setCursor(6,1); // start postion of time text on LCD
    lcd.print(now.hour(), DEC);
    lcd.print(':');
    lcd.print(now.minute(), DEC);
    lcd.print('.');
    lcd.print(now.second(), DEC);
    // You can display in lcd by changing Serial to lcd I have only used time above not date
    //Serial.print(now.year(), DEC);
    //Serial.print('/');
    //Serial.print(now.month(), DEC);
    //Serial.print('/');
    //Serial.print(now.day(), DEC);
    //Serial.print(' ');
    //Serial.print(now.hour(), DEC);
    //Serial.print(':');
    //Serial.print(now.minute(), DEC);
    //Serial.print(':');
    //Serial.print(now.second(), DEC);
    //Serial.println();
    delay(1000); // screen - sample & LCD refresh time 1 second although DHT say min 2 seconds but works ok.
}
//
// END OF FILE
//



UNO_to_LCD_RTC_ TEMP.jpg