The DHT21 digital temperature sensor is one of the commonest from the range of DHT temperature sensors and boasts a relatively high temperature measurement accuracy of 0.5oC in 0.1oC steps with a relative humidity accuracy of +/- 3%. It has only 3 wires, including power and ground, meaning only one digital pin is required to interface it to a microcontroller. For Arduino development platforms the sensor is very well supported by the DHT library available from the Arduino Playground website.
Specification:
Product Code: HCSENS0026
Model: AM2301
Power supply: 3.3-5V DC
Output signal: digital signal via single-bus
Sensing element: Polymer humidity capacitor
Measuring range: humidity 0-100%RH; temperature -40~80Celsius
Accuracy: humidity +-3%RH(Max +-5%RH); temperature <+-1Celsius
Resolution or sensitivity: humidity 0.1%RH; temperature 0.1Celsius
Repeatability: humidity +-1%RH; temperature +-0.2Celsius
Humidity hysteresis: +-0.3%RH
Long-term Stability: +-0.5%RH/year
Sensing period: Average: 2s
Dimensions size 59*27*13.5mm
Example Arduino Sketch:
Code: Select all
/* FILE: DHT21_Example
DATE: 06/10/16
VERSION: 0.1
AUTHOR: Andrew Davies
This example sketch uses the DHT library available from the Arduino playground here:
http://playground.arduino.cc//Main/DHTLib
Simply connect your DHT21 sensor to the Arduino digital pin 5, upload this sketch
and then open a the serial monitor window with a BAUD rate of 9600.
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 "dht.h"
dht DHT21;
#define DATA_PIN 5 // Digital pin connected the DHT21 data pin.
void setup()
{
Serial.begin(9600);
}
void loop()
{
/* Take a reading from the sensor */
int State = DHT21.read21(DATA_PIN);
/* If reading was successful then output the results to the serial port */
if(State == DHTLIB_OK)
{
Serial.print("Temperature: ");
Serial.println(DHT21.temperature, 1);
Serial.print("Humidity: ");
Serial.println(DHT21.humidity, 1);
Serial.println("");
}
/* Wait a second before looping back */
delay(1000);
}
DHT library:
Please note that this version of library is not compatible with ARM based devices such as the ESP8266. If you wish to use the sensor with an ESP8266 then please check out the following library:
https://github.com/RobTillaart/Arduino/ ... /DHTstable
Please note that the above url links to an external library which not maintained by Hobby Components. Use of this library is therefore at your own risk.
Datasheet:
Disclaimer: Libraries, example code, and diagrams are provided as an additional free service by Hobby Components and are not sold as part of this product. We do not provide any guarantees or warranties as to their accuracy or fitness for purpose.
Descriptions and diagrams on this page are copyright Hobby Components Ltd and may not be reproduced without permission.