-->
Page 1 of 2

Need help with my NodeMCU board

PostPosted: Mon May 20, 2019 4:37 am
by Raj_Srikar
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)

Re: Need help with my NodeMCU board

PostPosted: Wed May 22, 2019 2:18 am
by schufti
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

Re: Need help with my NodeMCU board

PostPosted: Wed May 22, 2019 4:04 am
by Raj_Srikar
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.

Re: Need help with my NodeMCU board

PostPosted: Wed May 22, 2019 3:12 pm
by schufti
there are several libraries for dht, did you make sure that you are using a esp8266 compatible one?