Last active
May 17, 2018 03:47
-
-
Save junho85/64da9ee985155db7cb6fa051ed6ad5a2 to your computer and use it in GitHub Desktop.
arduino dht11
This file contains hidden or 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 <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; | |
} | |
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