void setup(){
#include <DHT.h> // include adafruit library unified sensor
#define DHTPIN 2 // Set DHT pin:
#define DHTTYPE DHT22 // Set DHT type, DHT 22
DHT dht = DHT(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal 16mhz Arduino:
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 I”}