Set which data pin on the NodeMCU is connected to the data pin on the DHT11.
The data pin is the GPIO pin number, not the data name. So pin D4 is (GPIO) pin 2 on the ESP-12:
Temperature is in Celsius, RH is in %.
To convert from Celsius to Fahrenheit: F = (C * 1.8 + 32)
importdhtfrommachineimportPinimporttime## D4 = GPIO2
d=dht.DHT11(Pin(2))## Can only collect temperature every ~2 seconds, so sleep 5s.
time.sleep(5)d.measure()c=d.temperature()h=d.humidity()f=(c*1.8+32)print("Temp is "+str(c)+"C ("+str(f)+"F) and RH is "+str(h))# Temperature is in C, RH is in %.
Bare vs. Shielded DHT11
A DHT 11 with a shield has 3 pins.
A bare DHT11 has 4 pins.
In either case, 3vs4 pins, there are only 3 pins used: Signal, Vcc (+), Ground (-).
The shielded, or PCB mounted, version includes a 10K Ohm pull up resistor for the signal line.