Created
April 17, 2019 16:35
-
-
Save TrickSumo/f1aecd17972aa3b6c0668750c3309714 to your computer and use it in GitHub Desktop.
Interface DHT11 temperature sensor with NodeMCU ESP8266
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
/* By TrickSumo.com | |
Libraries used:- | |
https://github.com/adafruit/DHT-sensor-library | |
https://github.com/adafruit/DHT-sensor-library | |
*/ | |
#include <DHT.h> | |
#define DHTTYPE DHT11 | |
#define dht_dpin D1 | |
DHT dht(dht_dpin, DHTTYPE); | |
void setup() { | |
dht.begin(); | |
Serial.begin(9600); | |
Serial.println("Serial Communication Started\n"); | |
} | |
void loop() { | |
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("\n "); | |
Serial.print("Temperature = "); | |
Serial.print(t); | |
Serial.println("C \n \n \n "); | |
delay(2000 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Welcome :)