#include <DHT.h> // include adafruit library unified sensor
#define DHTPIN A2 // 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 celcius
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.println("%"); // serial monitor to display "%"
Serial.print("Temperature: "); // serial monitor to display the work "Temperature"
Serial.print(t); // serial monitor to display the value of temperature in the sensor
Serial.println("°C"); // serial monitor in line format to display the word "C |"
}