#include "DHT.h" #define DHTPIN 7 // Digital pin connected to the DHT sensor #define DHTTYPE DHT11 // DHT 11 #define FAN 17 // DHT 11 #define BULB 16 // DHT 11 DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); Serial.println(F("DHTxx test!")); pinMode(FAN, OUTPUT); pinMode(BULB, OUTPUT); dht.begin(); } void loop() { // Wait a few seconds between measurements. delay(2000); // 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(); // Read temperature as Celsius (the default) float t = dht.readTemperature(); // Read temperature as Fahrenheit (isFahrenheit = true) // float f = dht.readTemperature(true); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t)) { Serial.println(F("Failed to read from DHT sensor!")); return; } if(t>30 && t<100) { Serial.print(" Temp above 30, switching FAN "); digitalWrite(BULB, LOW); digitalWrite(FAN, HIGH); } else if (t>0 && t<25) { Serial.print(" Temp below 25, switching bulb "); digitalWrite(BULB, HIGH); digitalWrite(FAN, LOW); } else{ Serial.print(" Temp between 25 and 30, switching both off "); digitalWrite(BULB, LOW); digitalWrite(FAN, LOW); } // Compute heat index in Celsius (isFahreheit = false) float hic = dht.computeHeatIndex(t, h, false); Serial.print(F(" Drugyel Temperature Humidity Readings ")); Serial.print(F(" Humidity: ")); Serial.print(h); Serial.print(F("% Temperature: ")); Serial.print(t); Serial.print(F("F Heat index: ")); Serial.print(hic); Serial.print(F("C ")); }