Sketches: DHT11 Digital Temperature and Humidity Module

Digital Temperature and Humidity Sensor Module
Digital Temperature and Humidity Sensor Module

Items you will need:

Arduino development board such as this one

Male to female dupont cables

DHT11 Module

 

 

 

Pinout: 

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

What does it do?

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.

Code:

/* 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);
}

Add a Comment

Your email address will not be published.