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 ); | |
} |
oh ok. thanks about that
i want ask one question, should i use a resistor for dht11 sensor?
should i use a resistor for dht11 sensor
If you are using 7805 IC with battery then no need to use resistor.
Else you can use battery and two resistors as voltage divider (or use rheostat).
In any case make sure to not feed digital IC's (including some sensors) more than 5v.
ok, i was search a scematic design and i found it use resistor in data pin. so should i doing this?
You can use it.
oke thank you so much
Welcome :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
oh ok. Try with +5v, it will work.
For without battery, refer this:-
NodeMCU Amica model
https://github.com/TrickSumo/water-level-indicator-controller/blob/master/Circuit%20Diagram%20For%20NodeMCU%20ESP8266%20Amica%20Model.JPG
NodeMCU Lolin model
https://github.com/TrickSumo/water-level-indicator-controller/blob/master/Circuit%20Diagram%20For%20NodeMCU%20ESP8266%20LoLin%20Model.jpg
If your NodeMCU do not have VV or Vin (or sensor not working even with those). Then using battery with voltage regulator is best solution.