Arduino and the Digital Temperature and Humidity Sensor Module

This project aims to get the room temperature and humidity using a digital humidity sensor. We will be using a DHT22 sensor for this project.

On the DHT22, I connected the red cable to positive [+], then connected the orange cable to “out”, and brown cable to [-].

On the Arduino Uno, I connected the red cable to the 3.3V pin, then the brown cable to the ground pin, and then the orange cable to the no. 5 digital pin.

This is how it looks how I connected the DHT22 to Arduino Uno.

Connect your Arduino to your computer and upload the sketch. Below is the sketch to upload to your Arduino.

#include <DHTStable.h>

DHTStable DHT;

#define DHT22_PIN 5

void setup()
{
  Serial.begin(9600);
}


void loop()
{ 
  
  Serial.print("DHT22, \t");
  int chk = DHT.read22(DHT22_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;
    default: 
      Serial.print("Unknown error,\t"); 
      break;
  }

  Serial.print(DHT.getHumidity(),1);
  Serial.print(",\t");
  Serial.println(DHT.getTemperature(), 1);
  Serial.print(DHT.getTemperature(), 1);
  Serial.println("C \t");

  delay(5000);
}

We will be using the DHStable library for this project and you can get it by going to Tools then Manage Libraries and just search it and install. I also added the link under references.

This is what the serial monitor will look like after the sketch is uploaded to the Arduino Uno.

If you have any questions, feedback, or comments, feel free to leave me a message in the comment section below.

List of Material

  • Arduino Uno R3
  • DHT22 Digital Temperature and Humidity Sensor Module
  • Male-to-female breadboard jumper ribbon cables

References

Notes

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.