Easier and better example with the DHT library: #include "DHT.h" #define DHTPIN 2 // what pin we're connected to #define DHTTYPE DHT11 // DHT 11 #define fan 4 int maxHum = 60; int maxTemp = 40; DHT dht(DHTPIN, DHTTYPE); void setup() { pinMode(fan, OUTPUT); Serial.begin(9600); 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 float t = dht.readTemperature(false); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } if(h > maxHum || t > maxTemp) { digitalWrite(fan, HIGH); } else { digitalWrite(fan, LOW); } Serial.print("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature: "); Serial.print(t); Serial.println(" *C "); }
I am trying to get this to work with the supplied example, but I only bget 63,5 127 or 255,5 degrees (and the same humidity) which doesnt make sense. The code also gets stuck and only runs once, so I think some timing is off - but I canot seem to find any documentation on this ?
I am trying to get this to work with the supplied example, but I only bget 63,5 127 or 255,5 degrees (and the same humidity) which doesnt make sense. The code also gets stuck and only runs once, so I think some timing is off - but I canot seem to find any documentation on this ?
Hi there, I'd like to know if there is any Document showing like exact timing Diagrams and the meanings of the four Bytes transferred. In my Project using an Atmega, I want to approach efficient Interrupt-based Program Cycles without delays that keep the Processor busy with no Operation. This would save me a lot of time if I didn't have to revers-engineer your copy/paste code solution, wich is surely great for normal Arduino applications.