Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Muhammad Afzal
Published © Apache-2.0

Temperature Monitoring With DHT22 & Arduino

Simple Temperature Monitoring with DHT22 & Arduino.

BeginnerProtip1 hour375,523
Temperature Monitoring With DHT22 & Arduino

Things used in this project

Story

Read more

Schematics

DHT22 Code

Arduino Code For DHT22

Code

Arduino DHT22 Code

C/C++
DHT22 Code for Arduino
/* How to use the DHT-22 sensor with Arduino uno
   Temperature and humidity sensor
*/

//Libraries
#include <DHT.h>;

//Constants
#define DHTPIN 7     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino


//Variables
int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature value

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

void loop()
{
    delay(2000);
    //Read data and store it to variables hum and temp
    hum = dht.readHumidity();
    temp= dht.readTemperature();
    //Print temp and humidity values to serial monitor
    Serial.print("Humidity: ");
    Serial.print(hum);
    Serial.print(" %, Temp: ");
    Serial.print(temp);
    Serial.println(" Celsius");
    delay(10000); //Delay 2 sec.
}

   

Credits

Muhammad Afzal
25 projects • 117 followers
I am Software Eng having 13+ Years of experience. Hackster.io & Cayenne Mydevices Ambassador in Pakistan.
Thanks to Michalis Vasilakis.

Comments