#include <DHT.h>//include adafruit library unified sensor
#define DHTPIN A0//set DHT pin:
#define DHTTYPE DHT22 //set DHT type, DHT 22
DHT dht = DHT(DHTPIN, DHTTYPE); //Initialize DHT sensor for normal 16mhz Arduino:
void setup()
{
Serial.begin(9600); //begin serial communication at a band rate of 9600:
dht.begin(); //setup sensor:
}
void loop()
{
delay(2000); //wait a 2 seconds between measurements:
//reading temperature or humidity takes about 250 milliseconds!
//sensor readings may also be up to 2 seconds 'old'
float h = dht.readHumidity();// read the humidity in %:
float t = dht.readTemperature();//read the temperature as celsius:
Serial.print("Humidity: ");//serial monitor to display the word "Humidity"
Serial.print(h);//serial monitor to display the value of humidity in the sensor
Serial.print("%");//serial monitor to display "%"
Serial.print(" Temperature: ");//serial monitor to display the word "Temperature"
Serial.print(t);//serial monitor to display the value of temperature in the sensor
Serial.print("\xC2\xB0");
Serial.println("C |");//serial monitor in line format to display the word "C |"
}