Skip to content

Read DHT22 temperature and humidity

Read temperature and relative humidity while separating resolution from accuracy.

Physics Phoebe, your practice guide

Physics Phoebe
Predict the reading, then compare it with the measurement.

Wokwi ESP32

Third party Tool

Read temperature and relative humidity while separating resolution from accuracy.

Tier 2 · Web · paste-in setup · Account needed to save a project

Version tested: Compiled with arduino-cli 1.5.2-rc.1 for esp32 core 3.3.11; booted headlessly with wokwi-cli 0.26.1 on 2026-09-07; serial line 'T=24.0 C, RH=40.0 %' seen at 5.361 s (wall time from CLI start; scenario timeout 20 s simulated time); captured in the Wokwi web editor on 2026-09-09. Date: 2026-09-05.

Open the ESP32 editor, paste diagram.json, then paste sketch.ino.

Open Wokwi to paste in the files (new tab)

Get the files

Use both prepared files. This is a paste-in setup; saving a project requires a Wokwi account.

diagram.json

856 bytes · Circuit connections

Download

sketch.ino

1,451 bytes · ESP32 program

Download

  1. Use the launch button above to open the ESP32 editor in Wokwi.
  2. Select the editor’s diagram.json tab and replace all its text with the supplied diagram.json.
  3. Select the sketch.ino tab, replace all its text with the supplied sketch.ino, then click Start Simulation.

Steps

Screens captured against Wokwi ESP32 Compiled with arduino-cli 1.5.2-rc.1 for esp32 core 3.3.11; booted headlessly with wokwi-cli 0.26.1 on 2026-09-07; serial line 'T=24.0 C, RH=40.0 %' seen at 5.361 s (wall time from CLI start; scenario timeout 20 s simulated time); captured in the Wokwi web editor on 2026-09-09 on 2026-09-05; the tool may have moved on — the text steps are the contract.

  1. 1 Step 1

    Do
    In the Simulation panel, inspect the DHT22 wiring after pasting both supplied files.
    You will see
    The DHT22 has power and ground connections, with its data line connected to ESP32 pin 15.
    Why it matters
    The chapter treats operating conditions as part of every specification. Checking the signal path establishes which setup your readings describe.
    Step 1: The sensor power, ground, and signal wiring connect to the ESP32. The ring marks the sensor.
    Step 1 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  2. 2 Step 2

    Do
    In the sketch.ino editor tab, find delay(2000) and the temperature and humidity calculations.
    You will see
    The code waits 2000 ms before reading and prints temperature in °C and relative humidity in percent.
    Why it matters
    Sampling rate and response time describe different waits. The code sets when readings happen, while sensor response describes how quickly a physical change settles.
    Step 2: The named source lines show the sampling and conversion calculations. The ring marks those code lines.
    Step 2 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  3. 3 Step 3

    Do
    In the Simulation toolbar, click the play button and wait for compilation.
    You will see
    The timer starts, the stop button appears, and the Serial Monitor opens below the circuit.
    Why it matters
    A running model lets you test the reading sequence. The chapter still requires a trusted reference before accepting installed accuracy.
    Step 3: The simulation is running and Serial Monitor is open. The ring marks the Stop control.
    Step 3 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  4. 4 Step 4

    Do
    In the Serial Monitor panel, read the first temperature and humidity result after at least two seconds.
    You will see
    The Serial Monitor prints T=24.0 C, RH=40.0 % about every two seconds.
    Why it matters
    Resolution is the smallest displayed step. These decimal places show the output format, but they do not establish closeness to a trusted value.
    Step 4: The serial reading is T=24.0 C, RH=40.0%. The ring marks the baseline result.
    Step 4 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  5. 5 Step 5

    Do
    In the Simulation panel, select the DHT22 and set its temperature control to 30 °C.
    You will see
    The temperature control shows 30 °C, and the Serial Monitor changes to T=30.0 C, RH=40.0 %.
    Why it matters
    Changing temperature alone separates the two reported quantities. This supports the chapter’s habit of testing each claim under stated conditions.
    Step 5: The temperature is 30.0 C and humidity remains 40.0%. The ring marks the updated reading.
    Step 5 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  6. 6 Step 6

    Do
    In the DHT22 control panel, set relative humidity to 70%.
    You will see
    The humidity control shows 70%, and the Serial Monitor changes to T=30.0 C, RH=70.0 %.
    Why it matters
    Humidity is also an operating condition, not just a number on a display. The chapter asks whether the installed sensor can support that environment.
    Step 6: The reading is 30.0 C and 70.0% humidity. The ring marks the changed humidity.
    Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  7. 7 Step 7

    Do
    In the DHT22 control panel, restore temperature to 24 °C and relative humidity to 40%.
    You will see
    The Serial Monitor returns to T=24.0 C, RH=40.0 % after the sample interval.
    Why it matters
    Precision describes how closely repeated readings agree. Returning to the starting conditions checks repeatability here, while field testing must still consider drift and mounting.
    Step 7: The reading returns to 24.0 C and 40.0% humidity. The ring marks the restored baseline.
    Step 7 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)

Chapter checks

These questions refer to the chapter’s examples. Use the return links to review their answers.

  1. A sensor reports temperature in 0.01 degree steps, but its accuracy claim is much wider than the decision threshold. What should the review conclude?

    Return to the chapter’s knowledge check
  2. A team chooses a sensor because it is inexpensive, but the field environment causes frequent drift and replacement visits. Which specification review was incomplete?

    Return to the chapter’s knowledge check

Caution

Tool versions change and screens may differ. Reopen the supplied setup, check the tool documentation, and use the site feedback control if the problem remains. The screenshots show browser measurements, not hardware calibration; values may vary slightly between runs. A startup checksum error occurred during testing and was discarded; later valid packets produced the recorded readings.

Return to Sensor Specifications · Browse Labs