Skip to content

Instantly share code, notes, and snippets.

@Hugoyhu
Created February 28, 2021 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hugoyhu/52f0bd641f70be9736182677ed994fe1 to your computer and use it in GitHub Desktop.
Save Hugoyhu/52f0bd641f70be9736182677ed994fe1 to your computer and use it in GitHub Desktop.
#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