Created
November 5, 2017 14:15
-
-
Save mims92/6aa160dc35076e05107feeb3d3fcdd53 to your computer and use it in GitHub Desktop.
ESP8266 - C - DHT11 Temperature and humidity sensor
This file contains 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
/** | |
* You need to include SimpleDHT library to Arduino IDE (or whatever IDE you are using). | |
* https://github.com/mims92/SimpleDHT (fork) | |
* https://github.com/winlinvip/SimpleDHT (official) | |
* Please it in the library folder of Arduino. | |
*/ | |
#include "ESP8266WiFi.h" | |
#include "SimpleDHT.h" | |
#define DHTTYPE DHT22 | |
#define DHTPIN 5 | |
SimpleDHT11 dht11; | |
float humidity, temp_c; | |
void setup() { | |
Serial.begin(115200); | |
getTemperature(); | |
} | |
void loop() {} | |
void getTemperature() { | |
dht11.read2(DHTPIN, &temp_c, &humidity, NULL); | |
Serial.print(temp_c); | |
Serial.println("C°"); | |
Serial.print(humidity); | |
Serial.println("%"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment