user60784: I am trying to use a NodeMCU like an arduino,trying to read Temperature and Humidity using a DHT11,but when ever I check the serial monitor the it outputs : nan, Can anyone help me find the problem.(The data pin is D4 on NodeMCU)
    #include "DHT.h"

DHT dht2(2,DHT11);

    void setup()
    {
      Serial.begin(9600);

    }


void loop()
{

    Serial.println("Temperature: ");
    Serial.println((dht2.readTemperature( )));
    Serial.println("Humidity");
    Serial.println((dht2.readHumidity( )));
    delay(5000);

}



user37622: The esp8266 boot configuration pins 0, 2, 15 require a pull-up/pull-down  to ensure the required state at boot. The board (NodeMCU in this case) has pull-up resistor on io0 and io2 and a pull-down resistor on pin 15. The MCU pins io0, io2 and io16 are the NodeMCU pin D3, D4 and D8. You can use this pins in the sketch, but only to attach devices which are not in conflict with the required boot state and are not disturbed by the pull-up/pull-down.
NodeMCU and "Wemos D1 R2 and Mini" esp8266 pins and io overview

Serial
RX io1 RX0
TX io3 TX0

boot config pins with pullup or pulldown on board
D3 io0 PULLUP (LOW for boot to flashing mode)
D4 io2 TX1 PULLUP (Serial1 TX. no RX for Serial1)
D8 io15 PULLDOWN (SS pin if esp8266 is SPI slave)

untroubled GPIOs with optional function for I2C or SPI bus:
D1 io5 default pin for I2C SCL
D2 io4 default pin for I2C SCA
D5 io14 SPI CLK
D6 io12 SPI MISO
D7 io13 SPI MOSI

RTC pin for timed deep sleep wake-up (if connected to reset pin)
D0 io16 - optional internal pulldown, internal pullup not available

not useable: Sx pins io 6 to io 11 connect QIO SPI flash memory (in DIO flash mode the 2 QIO pins can be used as gpio) (in a very special setup the SPI bus can be used with other SPI device)
note: most digital IO start as INPUT_PULLUP 

60784: <p>I am trying to use a NodeMCU like an arduino,trying to read Temperature and Humidity using a DHT11,but when ever I check the serial monitor the it outputs : nan, Can anyone help me find the problem.(The data pin is D4 on NodeMCU)</p>

<pre><code>    #include "DHT.h"

DHT dht2(2,DHT11);

    void setup()
    {
      Serial.begin(9600);

    }


void loop()
{

    Serial.println("Temperature: ");
    Serial.println((dht2.readTemperature( )));
    Serial.println("Humidity");
    Serial.println((dht2.readHumidity( )));
    delay(5000);

}
</code></pre>

<p><a href="https://i.stack.imgur.com/DVxXu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DVxXu.png" alt="enter image description here"></a></p>
 37622: <p>The esp8266 boot configuration pins 0, 2, 15 require a pull-up/pull-down  to ensure the required state at boot. The board (NodeMCU in this case) has pull-up resistor on io0 and io2 and a pull-down resistor on pin 15. The MCU pins io0, io2 and io16 are the NodeMCU pin D3, D4 and D8. You can use this pins in the sketch, but only to attach devices which are not in conflict with the required boot state and are not disturbed by the pull-up/pull-down.</p>

<p><strong>NodeMCU and "Wemos D1 R2 and Mini" esp8266 pins and io overview</strong></p>

<hr>

<p><strong>Serial</strong></p>

<p>RX io1 RX0</p>

<p>TX io3 TX0</p>

<hr>

<p><strong>boot config pins</strong> with pullup or pulldown on board</p>

<p>D3 io0 PULLUP (LOW for boot to flashing mode)</p>

<p>D4 io2 TX1 PULLUP (Serial1 TX. no RX for Serial1)</p>

<p>D8 io15 PULLDOWN (SS pin if esp8266 is SPI slave)</p>

<hr>

<p><strong>untroubled GPIOs</strong> with optional function for I2C or SPI bus:</p>

<p>D1 io5 default pin for I2C SCL</p>

<p>D2 io4 default pin for I2C SCA</p>

<p>D5 io14 SPI CLK</p>

<p>D6 io12 SPI MISO</p>

<p>D7 io13 SPI MOSI</p>

<hr>

<p><strong>RTC pin</strong> for timed deep sleep wake-up (if connected to reset pin)</p>

<p>D0 io16 - optional internal pulldown, internal pullup not available</p>

<hr>

<p><strong>not useable</strong>: S<em>x</em> pins io 6 to io 11 connect QIO SPI flash memory (in DIO flash mode the 2 QIO pins can be used as gpio) (in a very special setup the SPI bus can be used with other SPI device)</p>

<p><em>note: most digital IO start as INPUT_PULLUP</em> </p>
