--- title: DHT22 temperature/humidity sensor on a NodeMCU 0.9 with ESPHome and Home Assistant date: 2021-04-11 summary: Wiring and ESPHome YAML for a DHT22 on an old yellow NodeMCU 0.9 board, feeding Home Assistant. USB uploads failing with "Upload with baud rate 460800 failed" were fixed by disconnecting the sensor while flashing. tags: esphome, home-assistant, esp8266, nodemcu, dht22, iot environment: ESPHome (Home Assistant add-on, 2021); NodeMCU v0.9 (ESP-12); DHT22 / AM2302 author: shaun status: published aliases: Home-Assistant-ESPHome-NodeMCU-DHT22-temperature-and-humidity-sensor.html --- ![Yellow NodeMCU 0.9 board](nodemcu-0-9.png) ## Setup In Home Assistant's **ESPHome** tab create a new node. For the device type pick **Other ESP8266s → NodeMCU 0.9**, add Wi-Fi credentials, then edit the YAML. The [DHT sensor docs](https://esphome.io/components/sensor/dht.html) list the options. ```yaml esphome: name: node-mcu-09 esp8266: board: nodemcu wifi: ssid: "your-ssid" password: "your-wifi-password" ap: # fallback hotspot if Wi-Fi fails ssid: "Node Mcu 09 Fallback Hotspot" password: "fallback-password" captive_portal: logger: api: ota: - platform: esphome sensor: - platform: dht model: DHT22 pin: D2 temperature: name: "Temperature 1" humidity: name: "Humidity 1" update_interval: 60s ``` (Written in 2021 with `platform: ESP8266` under `esphome:`; current ESPHome wants the separate `esp8266:` block shown above.) Wiring: ```text 3.3V -> DHT22 VCC D2 -> DHT22 DATA GND -> DHT22 GND ``` The DHT22 datasheet recommends a **4.7 kΩ pull-up** between VCC and DATA. Bare sensors need one; most breakout boards already have it. ## Symptoms: upload over USB fails Re-flashing over USB later failed every time with: ```text Upload with baud rate 460800 failed. Trying again with baud rate 115200. ``` The same happened with other NodeMCU boards. ## Fix Disconnect the sensor wires from the board's pins while flashing, then reconnect them. Something on the attached pins was getting in the way of the boot/flash sequence (D2 itself is not a strapping pin, so the exact cause is unproven). Once the first image is on the board, OTA updates over Wi-Fi avoid the problem.