// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
#include "DHT.h"
#define DHTPIN 2 //Digitla pIns connected to DHT Sensor
#define DHTTYPE DHT11 //using DHT11
DHT dht(DHTPIN, DHTTYPE);//interface with a DHT sensor
void setup(){
Serial.begin(9600);
Serial.println(F("DHTxx Test!"));;
dht.begin();
}
void loop(){
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();//function communicates with the DHT11 sensor through the pin
//Reads temp. in celcius(default)
float t = dht.readTemperature();
//reads tempeerature as fahrenheit
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
//standard function that checks if the value passed
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
//The given code snippets demonstrate how to compute the
// heat index using the DHT library for a DHT sensor.
//The heat index is a measure that combines air temperature
// and relative humidity to determine the perceived temperature
//(how hot it feels).
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h); //compute the heat index
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("Humidity: ")); //storing the string in Flash Memory
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat Index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
//println() method ensures cursor moves to next line after printing
// Wait a few seconds between measurements.
delay(2000);
}