Skip to content

Read DHT22 temperature and humidity

Read temperature and relative humidity while separating resolution from accuracy.

Try the four-week family weather project
How to complete this Wokwi lab

Your task: Read DHT22 temperature and humidity

Goal: Read temperature and relative humidity while separating resolution from accuracy.

Open the simulator · Read the full text instructions

Use this checklist as you work. Checks last only on this page and do not submit or record completion.

  1. Details for step 1
  2. Details for step 2
  3. Details for step 3
  4. Details for step 4
  5. Details for step 5
  6. Details for step 6
  7. Details for step 7
Simulator unavailable? Use the text fallback

Follow the checklist using the recorded results below. Predict each change, compare it with the recorded result, and explain why it matters. These are the lab's recorded results, not measurements you have made. Run the simulator later to test your predictions.

  1. Recorded result for step 1

    Input: inspect the running Wokwi circuit and diagram.json tab. The DHT22 has red power and black ground leads. Its green data lead reaches ESP32 GPIO 15. The same tool window reports T=24.0 C, RH=40.0 %.

    Why it matters: The capture ties the serial reading to this wired DHT22. Power, ground, and data paths are all visible. The GPIO 15 route identifies the signal used by the sketch. This is a simulator configuration, not installed sensor accuracy.

  2. Recorded result for step 2

    Input: inspect sketch.ino beside the running Wokwi circuit. The loop begins with delay(2000). The sketch converts five DHT bytes to temperature and humidity. Serial Monitor prints T=24.0 C, RH=40.0 % in this run.

    Why it matters: The 2000 ms delay sets the sketch's sampling interval. The one-decimal serial line shows its output format. The code checks reception and checksum before printing values. The programmed interval does not measure physical response time.

  3. Recorded result for step 3

    Input: click Start the simulation in Wokwi. The toolbar changes to a visible Stop control. The simulator clock reaches 00:07.166 in the capture. Serial Monitor below the circuit prints T=24.0 C, RH=40.0 %.

    Why it matters: The running timer and Stop control confirm execution. The Serial Monitor supplies the first measured simulator values. The DHT22 and ESP32 remain visible beside that readout. A reference instrument would still be needed for installed accuracy.

  4. Recorded result for step 4

    Input: leave the DHT22 at 24 C and 40% in Wokwi. Observed: "T=24.0 C, RH=40.0 %". Expected: 24.0 C and 40.0% RH. The measured line matches the real screenshot.

    Why it matters: This establishes both channels before either control changes. The firmware reports each value to one decimal place. The simulator settings reach the serial readout. One simulated reading does not establish physical accuracy.

  5. Recorded result for step 5

    Input: set the DHT22 temperature control to 30 C in Wokwi. Observed: "T=30.0 C, RH=40.0 %". Expected: temperature changes while humidity stays at 40.0%. The control displayed 30 C in this run.

    Why it matters: Only one simulated sensor channel changed. The Serial Monitor value matches the real screenshot. The 6 C difference from baseline is visible. This does not establish physical sensor accuracy.

  6. Recorded result for step 6

    Input: keep temperature at 30 C and set humidity to 70%. Observed: "T=30.0 C, RH=70.0 %". Expected: humidity changes by 30 percentage points. Temperature remained at the prior 30 C setting.

    Why it matters: The two controls can be varied independently. The run printed both updated values together. The screenshot marks the same 70.0% response. The result is a controlled simulator reading.

  7. Recorded result for step 7

    Input: restore DHT22 controls to 24 C and 40%. Observed: "T=24.0 C, RH=40.0 %". Expected: the starting serial line returns. Both Wokwi controls displayed their original settings.

    Why it matters: The final reading repeats the baseline values. This closes the change-and-restore sequence. The screenshot marks the same restored line. No physical drift is measured in this simulation.

Review the detailed text steps and cautions below.

Physics Phoebe, your practice guide

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

Wokwi ESP32

Third party Tool

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
    Input: inspect the running Wokwi circuit and diagram.json tab. The DHT22 has red power and black ground leads. Its green data lead reaches ESP32 GPIO 15. The same tool window reports T=24.0 C, RH=40.0 %.
    Why it matters
    The capture ties the serial reading to this wired DHT22. Power, ground, and data paths are all visible. The GPIO 15 route identifies the signal used by the sketch. This is a simulator configuration, not installed sensor accuracy.
    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
    Input: inspect sketch.ino beside the running Wokwi circuit. The loop begins with delay(2000). The sketch converts five DHT bytes to temperature and humidity. Serial Monitor prints T=24.0 C, RH=40.0 % in this run.
    Why it matters
    The 2000 ms delay sets the sketch's sampling interval. The one-decimal serial line shows its output format. The code checks reception and checksum before printing values. The programmed interval does not measure physical response time.
    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
    Input: click Start the simulation in Wokwi. The toolbar changes to a visible Stop control. The simulator clock reaches 00:07.166 in the capture. Serial Monitor below the circuit prints T=24.0 C, RH=40.0 %.
    Why it matters
    The running timer and Stop control confirm execution. The Serial Monitor supplies the first measured simulator values. The DHT22 and ESP32 remain visible beside that readout. A reference instrument would still be needed for 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
    Input: leave the DHT22 at 24 C and 40% in Wokwi. Observed: "T=24.0 C, RH=40.0 %". Expected: 24.0 C and 40.0% RH. The measured line matches the real screenshot.
    Why it matters
    This establishes both channels before either control changes. The firmware reports each value to one decimal place. The simulator settings reach the serial readout. One simulated reading does not establish physical accuracy.
    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
    Input: set the DHT22 temperature control to 30 C in Wokwi. Observed: "T=30.0 C, RH=40.0 %". Expected: temperature changes while humidity stays at 40.0%. The control displayed 30 C in this run.
    Why it matters
    Only one simulated sensor channel changed. The Serial Monitor value matches the real screenshot. The 6 C difference from baseline is visible. This does not establish physical sensor accuracy.
    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
    Input: keep temperature at 30 C and set humidity to 70%. Observed: "T=30.0 C, RH=70.0 %". Expected: humidity changes by 30 percentage points. Temperature remained at the prior 30 C setting.
    Why it matters
    The two controls can be varied independently. The run printed both updated values together. The screenshot marks the same 70.0% response. The result is a controlled simulator reading.
    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
    Input: restore DHT22 controls to 24 C and 40%. Observed: "T=24.0 C, RH=40.0 %". Expected: the starting serial line returns. Both Wokwi controls displayed their original settings.
    Why it matters
    The final reading repeats the baseline values. This closes the change-and-restore sequence. The screenshot marks the same restored line. No physical drift is measured in this simulation.
    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