Skip to content

Instantly share code, notes, and snippets.

@kmcallister
Created November 12, 2020 04:07
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 kmcallister/54432e0328d8fb0444f77b3cef6c5882 to your computer and use it in GitHub Desktop.
Save kmcallister/54432e0328d8fb0444f77b3cef6c5882 to your computer and use it in GitHub Desktop.
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
#define PERIOD 5000
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
Serial.println(F("# READY"));
}
void loop() {
delay(PERIOD);
float h = dht.readHumidity();
float t = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
Serial.println(F("# ERROR"));
return;
}
Serial.print(t);
Serial.print(' ');
Serial.println(h);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment