Skip to content

Instantly share code, notes, and snippets.

@junho85
Last active May 17, 2018 03:47
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 junho85/64da9ee985155db7cb6fa051ed6ad5a2 to your computer and use it in GitHub Desktop.
Save junho85/64da9ee985155db7cb6fa051ed6ad5a2 to your computer and use it in GitHub Desktop.
arduino dht11
#include <SimpleDHT.h>
int pinDHT11 = 2;
SimpleDHT11 dht11;
void setup() {
Serial.begin(9600);
}
void loop() {
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT11 failed, err=");
Serial.println(err);
delay(1000);
return;
}
// print
Serial.print("Temperature:");
Serial.print((int)temperature);
Serial.print(" *C, ");
Serial.print("Humidity:");
Serial.print((int)humidity);
Serial.print(" H ");
// Sampling period at intervals should be no less than 1 second.
delay(1500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment