Skip to content
If this is your first visit, please click here to learn about shipping and delivery.
If this is your first visit, please touch here to learn about shipping and delivery.
DHT22 temperature and humidity sensor and board-mounted module options

Building a DHT22 Humidity Logger: Sensor Placement, Sampling and Trustworthy Data

A humidity sensor can communicate perfectly and still give an unrepresentative room reading. Mount it beside a warm regulator or inside a poorly ventilated box and it measures that local environment. A useful humidity logger needs sound placement and honest handling of data as well as correct wiring.

The PMD Way DHT22 temperature and humidity sensor is offered as a bare sensor or a board-mounted version. Both belong in the humidity sensor collection, but their connector arrangements and supporting components can differ. Check the version you have before following a connection diagram.

Understand relative humidity

Relative humidity, expressed as %RH, compares the water vapour present with the saturation level at the same temperature. A temperature change can therefore change relative humidity even when the amount of water vapour has not changed.

This explains a common puzzle: a sensor inside an electronics enclosure reads warmer and less humid than a reference instrument nearby. The readings may describe two different local environments. Moving the sensors together and allowing them to settle is more informative than immediately applying a software correction.

Sensirion's humidity and temperature design guide explains the importance of thermal separation and air exchange. These are general installation principles; its sensor-specific ratings should not be transferred to a DHT22.

Identify the sensor and board variant

DHT22 and AM2302 names commonly appear in this product family. Use the documentation that matches the actual package or module. A board may add a pull-up resistor or other components, and its labelled pin order may differ from the bare device.

The Aosong AM2302 technical manual specifies a timed single-data-line protocol. It is not an I2C device merely because a drawing labels the data connection SDA, and it is not interchangeable with the Dallas 1-Wire protocol.

The cited manual specifies a 3.3–5.5 V supply for its device. Confirm the supplied module's requirements and the controller's input limits. A pull-up connected to a 5 V rail can expose a connected input to 5 V; do not assume a 3.3 V controller tolerates that. Check existing board pull-ups before adding another.

Start with a small, verifiable logger

Use a driver that supports both the sensor and your processor. The library author's DHTlib repository documents an AVR-optimised implementation; that description matters when choosing software for another architecture. An example compiling successfully is not proof that timing-sensitive acquisition works reliably on every board.

Begin by recording temperature, humidity, timestamp and read status. Print units and distinguish a successful result from a timeout or checksum failure. Keep the first experiment simple enough that communications can be assessed independently from a display, wireless connection or storage system.

Aosong calls for at least two seconds between reads and a settling delay after power-up. Polling rapidly does not make the physical sensor respond faster. Choose a slower logging interval when the environment changes gradually, while preserving enough information to observe the behaviour that matters.

Keep stale readings visible

If a read fails, do not replace it with zero humidity or silently reuse an old value with a new timestamp. Store the failure status and the time of the last valid reading. A display can continue showing that value if it clearly indicates that it is stale.

For a classroom logger, an illustrative record might contain a scheduled sample time, a valid temperature, a valid humidity and an “OK” flag. A failed sample should retain its time and an error flag with empty measurement fields. This makes missing data visible when students plot the results later.

Choose a representative mounting location

Decide which air you want to measure: room air, air inside a cupboard or the exhaust from a device. Place the sensor accordingly and describe that location in the data record. An exhaust measurement should not be labelled as general room humidity.

Keep it away from processor heat, power resistors and direct sunlight. Provide airflow without exposing the sensor to splashes or trapping it in a dead pocket. Do not coat or seal the sensing openings. Consider moisture absorbed by nearby materials and contamination from fresh adhesives or solvents.

Test with the final enclosure closed and all electronics operating normally. If readings change significantly when the display backlight or radio turns on, investigate heat and electrical interference separately. A relocation test can help: move the sensor away while keeping the same software and compare the result.

Compare readings fairly

  1. Place the logger and a suitable reference close together without blocking their vents.
  2. Keep them away from hands, breath, sunlight and local heat sources.
  3. Allow both instruments to settle in the same environment.
  4. Compare a series of readings rather than one instant.
  5. Repeat under another stable condition within both instruments' specifications.

Account for the reference instrument's uncertainty. Two sensors disagreeing does not identify which one is wrong. A single offset correction established at one humidity and temperature may not hold elsewhere, so preserve the uncorrected data and document any adjustment.

Breathing on the sensor is a useful demonstration that it responds, but it is not a calibration method. It simultaneously changes humidity, temperature and airflow, and can introduce condensation. Avoid using that response to claim a particular accuracy or response time.

Set alerts that tolerate real variation

For a storage-cupboard monitor, select thresholds based on the stored materials' requirements and the measurement uncertainty. Add separate trigger and clear thresholds and an appropriate persistence time. Otherwise normal fluctuations near one boundary can create repeated alerts.

Test the alert logic using recorded or simulated values as well as live readings. Include failed samples and stale data. A sensor fault should have an explicit outcome rather than being interpreted as an unusually dry room.

Record the module version, wiring, supply, library version, sampling interval, mounting position and comparison results. Those details make the humidity trace explainable and help you improve the installation when a change in enclosure or location affects the readings.

Previous article Battery Power for Arduino Projects: Voltage Range, Runtime and Regulator Heat