Using the DHT11 Temperature Sensor with MicroPython on a NodeMCU
DHT11 Temperature Sensor
- Connect the VCC pin to a 3.3v power pin
- Connect the GND pin to a GND pin.
- Connect the Data pin to pin D4.
- There is a DHT11 module built-in to MicroPython
- Import the dht module.
- 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)
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.
categories: micropython | esp8266 | nodemcu |