DHT11 Digital Temperature & Humidity Module (HCARDU0020)

Modules for various types of sensors including accelerometers. gyro's, IR motion, etc
Post Reply
admin
Site Admin
Posts: 866
Joined: Sun Aug 05, 2012 4:02 pm

DHT11 Digital Temperature & Humidity Module (HCARDU0020)

Post by admin » Mon Aug 20, 2012 5:23 pm

Image

- Sensor including resistive humidity sensing component
- Fast response, great anti-interference ability and durable
- Power: 3.5-5V
- Temperature range: 0-50'C
- Humidity range: 20-90%RH

  • PINOUT
    1.....DATA
    2.....VCC (+5V)
    3.....GND

Example Arduino Sketch

ARD_DHT11_HCARDU0020_Example.pde

Code: Select all

/* FILE:    ARD_DHT11_HCARDU0020_Example
   DATE:    02/07/12
   VERSION: 0.1

This is a simple example of how to use the Hobby Components DHT11 module
(HCARDU0020). The module will work with the Arduino DHT11 library available at 
http://arduino.cc/playground/Main/DHT11Lib without any modification. This code 
demonstrates the use of this library to output the current temperature and humidity
measured by the sensor.

SENSOR PINOUT:

PIN 1: Data out
PIN 2: +5V
PIN 3: GND

You may copy, alter and reuse this code in any way you like, but please leave 
reference to HobbyComponents.com in your comments if you redistribute this code. 
This software may not be used directly for the purpose of selling products that 
directly compete with Hobby Components Ltd's own range of products. 

THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER 
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES, 
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY 
REASON WHATSOEVER.

*/


/* Include the DHT11 library available at http://arduino.cc/playground/Main/DHT11Lib */
#include <dht11.h>

dht11 DHT11;

/* Define the DIO pin that will be used to communicate with the sensor */
#define DHT11_DIO 2


void setup()
{
  /* Setup the serial port for displaying the output of the sensor */
  Serial.begin(9600);
}

/* Main program loop */
void loop()
{
  /* Perform a read of the sensor and check if data was read OK */
  if (DHT11.read(DHT11_DIO) == DHTLIB_OK)
  {
    /* If so then output the current temperature and humidity to 
    the serial port */
    Serial.print("Temperature: ");
    Serial.print((float)DHT11.temperature, 2);
    Serial.print("oC\t");
    Serial.print("Humidity: ");
    Serial.print((float)DHT11.humidity, 2);
    Serial.println("%");
  }else
  {
    /* If there was a problem reading from then sensor then output 
    an error */
    Serial.println("ERROR");
  }
  
  delay(500);
}

Image


Library for DHT11 temperature/humidity sensor module can be found on the Arduino website here:
http://playground.arduino.cc/main/DHT11Lib

You can also download a snapshot (known working version) of this library below (please log in to download):
DHT11.zip
You do not have the required permissions to view the files attached to this post.

Bigdog1981
Posts: 1
Joined: Fri Oct 25, 2013 11:59 am

Re: DHT11 Digital Temperature & Humidity Module (HCARDU0020)

Post by Bigdog1981 » Fri Oct 25, 2013 12:20 pm

Hi, this is only my second project and im having trouble. Basically im trying to control a relay using the code above by adding an "if" statement like this to the end of the code.
if (Temperature < 20)
{
digitalWrite ( relay,HIGH);
}
if (Temperature > 24)
{
digitalWrite (relay, LOW);

delay (500);
}
but just get the error messeage Temerature was not declared in the scope

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: DHT11 Digital Temperature & Humidity Module (HCARDU0020)

Post by andrew » Fri Oct 25, 2013 1:33 pm

Try replacing each reference to Temperature with DHT11.temperature

Note that it is case sensitive so don't capitalise the T. If this doesn't work please post your whole program.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply

Return to “Sensors”