Created
February 28, 2021 04:51
-
-
Save Hugoyhu/52f0bd641f70be9736182677ed994fe1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DHT.h" | |
#define DHTPIN 2 | |
#define DHTTYPE DHT11 | |
DHT dht(DHTPIN, DHTTYPE); | |
#if defined(ARDUINO_ARCH_AVR) | |
#define debug Serial | |
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) | |
#define debug SerialUSB | |
#else | |
#define debug Serial | |
#endif | |
void setup() { | |
debug.begin(9600); | |
debug.println("DHTxx test!"); | |
Wire.begin(); | |
dht.begin(); | |
} | |
void loop() { | |
float temp_hum_val[2] = {0}; | |
if (!dht.readTempAndHumidity(temp_hum_val)) { | |
debug.print("Humidity: "); | |
debug.print(temp_hum_val[0]); | |
debug.print(" %\t"); | |
debug.print("Temperature: "); | |
debug.print(temp_hum_val[1]); | |
debug.println(" *C"); | |
if(temp_hum_val[0] > 70) | |
{ | |
debug.println("Whoa, the humidity is pretty high!"); | |
} | |
else if(temp_hum_val[0] < 35) | |
{ | |
debug.println("That's way too dry! Maybe use a humidifier."); | |
} | |
} else { | |
debug.println("Failed to get temprature and humidity value."); | |
} | |
delay(1500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment