Skip to content

Instantly share code, notes, and snippets.

@apocas
Created May 6, 2015 02:48
Show Gist options
  • Save apocas/a17a28e24b31c0405862 to your computer and use it in GitHub Desktop.
Save apocas/a17a28e24b31c0405862 to your computer and use it in GitHub Desktop.
dht11
#include "DHT.h"
#define DHTPIN 8
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHT11 Sensor");
dht.begin();
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment