Read DHT22 temperature and humidity
Read temperature and relative humidity while separating resolution from accuracy.

Physics Phoebe
Predict the reading, then compare it with the measurement.
Wokwi ESP32
Third party ToolRead temperature and relative humidity while separating resolution from accuracy.
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.
sketch.ino
- Use the launch button above to open the ESP32 editor in Wokwi.
- Select the editor’s diagram.json tab and replace all its text with the supplied diagram.json.
- Select the sketch.ino tab, replace all its text with the supplied sketch.ino, then click Start Simulation.
Steps
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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · 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.
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 checkA 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