So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Raj_Srikar
#82391 Hi!
I'm completely new to this platform. I've just tested my NodeMCU if it can read sensor data or not. I've used DHT11 Humidity and Temperature sensor for this. After uploading the following basic code to my NodeMCU board, it shows 0 values for both Temperature and Humidity.

Code: Select all#include "DHT.h"
#define DHTTYPE DHT11

#define dht_dpin 2
DHT dht(dht_dpin, DHTTYPE);

void setup(void) {
dht.begin();
Serial.begin(9600);
Serial.println("humidity and Temperature/n/n");
delay(700);

}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  Serial.print("H = ");
  Serial.print(h);
  Serial.print("%  ");
  Serial.print("T = ");
  Serial.print(t);
  Serial.println("C   ");
  delay(800);

}


I've uploaded the same code for Arduino Uno and it shows values for Temperature and Humidity.
Do I have to conclude that my board is not working? Or is there any other way to fix this?
Please Help me out!
Thank you!
(and sorry for my bad english)
User avatar
By schufti
#82423 if you just write #define dht_dpin 2
it is not the pin marked "D2" on your nodemcu board, ist is gpio2 of esp8266 named D4 on your board.
To use the names printed on your board:
a) set boardtype to NodeMCU 1.0
b) use the pinnames according to the ones used on your module
e.g. #define dht_dpin D2
User avatar
By Raj_Srikar
#82425
schufti wrote:if you just write #define dht_dpin 2
it is not the pin marked "D2" on your nodemcu board, ist is gpio2 of esp8266 named D4 on your board.
To use the names printed on your board:
a) set boardtype to NodeMCU 1.0
b) use the pinnames according to the ones used on your module
e.g. #define dht_dpin D2

I have actually connected to D4 pin while using the above code. It just shows 0.00's only.