BeginnerSensors

ESP32 Room Temperature and Humidity Monitor

Read a DHT22 and print temperature and humidity to the Arduino serial monitor.

Estimated time: 45โ€“75 minutes ยท Skills: Microcontroller setup, GPIO, installing a library

Parts from the database

Other supplies

Amazon links may be affiliate links. As an Amazon Associate, Electronics Hobby Hub earns from qualifying purchases.

Connections

  1. DHT22 VCC to 3V3, GND to GND, DATA to ESP32 GPIO 4. Use a 3.3 V-compatible breakout.
  2. For a bare four-pin sensor, identify pins from its datasheet and add a 4.7โ€“10 kฮฉ resistor from DATA to 3V3.
  3. Do not power the sensor from 5 V if its DATA line would then pull the ESP32 input above 3.3 V.

Build steps

  1. Install Arduino IDE support for your ESP32 board and select the matching board/port.
  2. Install Adafruit DHT sensor library and Adafruit Unified Sensor from Library Manager.
  3. Wire the sensor with power disconnected, then upload the included sketch.
  4. Open Serial Monitor at 115200 baud and let the sensor settle; compare readings after breathing near it and then waiting for the air to clear.

Software and firmware setup

#include <DHT.h>
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() { Serial.begin(115200); dht.begin(); }
void loop() {
  float h = dht.readHumidity();
  float c = dht.readTemperature();
  if (isnan(h) || isnan(c)) Serial.println("Read failed: check DATA wiring");
  else { Serial.printf("Temperature: %.1f C  Humidity: %.1f %%\n", c, h); }
  delay(2000);
}

Review the pin assignments in the sketch against the wiring table before uploading.

Test your build

You should see a new temperature and relative-humidity reading every two seconds. DHT22 updates are slow; do not poll it rapidly.

Troubleshooting

  • If readings fail, confirm GPIO 4 matches the code and DATA has a pull-up.
  • If values are implausible, check sensor pin order and avoid touching the sensing slots.
  • If USB upload fails, select the actual board and serial port and use a data-capable cable.

Safety and limitations

Power from USB or a regulated 3.3 V-compatible development board. The sensor is for hobby room monitoring, not medical or safety-critical decisions.

Manufacturer and platform documentation

Community Notes for This Project

These are unverified visitor contributions, separate from the build guide and manufacturer specifications. Verify technical advice against the linked datasheets before relying on it.

Set up the comments service to load community notes.

Share a tip or question about this build

โ† Browse all projects