Authorized Online Retailer

Description

DHT-22 (also known by RHT03) is a low-cost humidity and temperature sensor with a single wire digital interface. The sensor is calibrated and doesn’t require extra components, so you can get right to measuring relative humidity and temperature. DHT22 is more accurate and has more dynamic range than DHT11 sensors.

Technical Specifications

Documents and Downloads

Connection with Arduino

DHT22 Arduino
GND GND
VCC 5V
DATA D8

 

Source Code


First we need to include the DHT library which can be found from the Arduino official website, then define the pin number to which our sensor is connected and create a DHT object. In the setup section, we need to initiate the serial communication because we will use the serial monitor to print the results. Using the read22() function, we will read the data from the sensor and put the values of the temperature and the humidity into the t and h variables. If you use the DHT11 sensor, you will need to you the read11() function. At the end, we will print the temperature and the humidity values on the serial monitor.

  1. /* DHT11/ DHT22 Sensor Temperature and Humidity Tutorial
  2. * Program made by Dejan Nedelkovski,
  3. * www.HowToMechatronics.com
  4. */
  5. /*
  6. * You can find the DHT Library from Arduino official website
  7. * https://playground.arduino.cc/Main/DHTLib
  8. */
  9. #include
  10. #define dataPin 8 // Defines pin number to which the sensor is connected
  11. dht DHT; // Creats a DHT object
  12. void setup() {
  13. Serial.begin(9600);
  14. }
  15. void loop() {
  16. int readData = DHT.read22(dataPin); // Reads the data from the sensor
  17. float t = DHT.temperature; // Gets the values of the temperature
  18. float h = DHT.humidity; // Gets the values of the humidity
  19. // Printing the results on the serial monitor
  20. Serial.print(“Temperature = “);
  21. Serial.print(t);
  22. Serial.print(” *C “);
  23. Serial.print(” Humidity = “);
  24. Serial.print(h);
  25. Serial.println(” % “);
  26. delay(2000); // Delays 2 secods, as the DHT22 sampling rate is 0.5Hz
  27. }