NSK Electronics Arduino

Arduino · Lesson 4

DHT11& DHT22

Give your Uno a weather sense. These tiny sensors spit out temperature and relative humidity on one digital wire — perfect for greenhouses, incubators, and “is my room muggy?” gadgets.

DHT11 blue sensor module beside DHT22 white sensor module on black breakout boards.

What you will learn

Pick a sensor

DHT11 (cheap & fast) vs DHT22 (wider & sharper).

Pinout

VCC, Data, NC, GND — same on both.

Wire & code

Pull-up, DHTlib, Serial °C and %RH.

Swap tip

Same wiring — just change read11 / read22.

New to Uno? Finish Basic Arduino first. Coming from motion sensing? You already use digital pins from the PIR lesson.

Why DHT sensors?

Want a greenhouse log, a humidor controller, or a tiny weather station? DHT11 and DHT22 (also sold as AM2302) are factory-calibrated humidity + temperature packages. No extra amplifier chips — just power, ground, and one Data wire.

They report values with one decimal place. The trade-off: new readings only about once or twice per second. For room climate that is plenty.

Meet DHT11 & DHT22

They look related and share the same pinout, but the white DHT22 is the sharper, wider-range sibling. Blue DHT11 wins on price, size, and sampling speed.

Side-by-side: blue DHT11 module on the left, white DHT22 module on the right.

Left: compact blue DHT11. Right: taller white DHT22. Both shown on 3-pin breakout boards (NC already omitted).

Compare at a glance

Spec DHT11 DHT22
Operating voltage 3 to 5 V 3 to 5 V
Max current 2.5 mA max 2.5 mA max
Humidity range 20–80% / ±5% 0–100% / 2–5%
Temperature range 0–50 °C / ±2 °C −40 to 80 °C / ±0.5 °C
Sampling rate 1 Hz (every 1 s) 0.5 Hz (every 2 s)
Body size 15.5 × 12 × 5.5 mm 15.1 × 25 × 7.7 mm
Advantage Ultra low cost More accurate

DHT22 covers freerzer-to-sauna and wetter air. DHT11 is cheaper, smaller, and updates twice as often. Wiring stays the same if you swap them — only the sketch’s read11 / read22 call changes.

Pinout VCC Data NC GND

Bare sensors have four pins. Looking at the grille face, left to right:

DHT11 (left) and DHT22 (right) pinout: VCC, Data, NC, GND left to right. NSK Electronics.

Common grille-face order: VCC · Data · NC · GND. Always check silkscreen — modules may label S / + / −.

VCC

Power 3.3–5.5 V. Prefer 5 V on Uno (longer Data cable OK).

Data

Single-wire digital chat with the MCU. Needs a pull-up to VCC.

NC

Not connected — leave open on 4-pin parts.

GND

0 V return. Share with Uno GND.

Module tip: many black breakout boards (like the hero photo) already hide NC and include a pull-up resistor — three pins only.

How a DHT “feels” the air

Crack open the case (in your mind) and you find three friends working together.

Humidity sensing film between electrodes, NTC thermistor, and IC that outputs digital Data bits.
  1. Humidity cell: two electrodes with a moisture-loving film. Wetter air → more ions → resistance drops.
  2. NTC thermistor: a resistor that drops ohms as it warms (Negative Temperature Coefficient).
  3. Tiny IC: reads both, applies factory calibration, and squirts a digital packet on the Data pin.

You never do the analog maths — the sensor already speaks “%RH and °C” in bits.

Try it: pretend readings

Press Sample for a playful indoor climate reading. Real hardware will print similar numbers in Serial Monitor.

Temperature 24.0 °C
Humidity 55 %
Demo only — upload the sketch for live sensor data.

Wiring to Arduino Uno

Three useful wires. On a bare 4-pin sensor, leave NC open and add a 10 kΩ resistor from Data to VCC so the line idles HIGH.

Arduino Uno 5V GND D8 wired to DHT VCC GND Data with 10k pull-up.

Suggested lesson pin: Data → D8. Change the sketch if you pick another digital pin.

DHT pinArduino Uno
VCC5V
GNDGND
DataDigital pin 8 (+ 10 kΩ to 5V if no onboard pull-up)
NCLeave open

Cable length: at 5 V you can often place the sensor up to ~20 m away. At 3.3 V keep it near (~1 m) or readings get weird from voltage drop.

Library — DHTlib

These sensors use a picky single-wire timing protocol. The easy path is the DHTlib library.

  1. Arduino IDE → Sketch → Include Library → Manage Libraries…
  2. Search dhtlib (Rob Tillaart).
  3. Install the single matching entry.

Then call DHT.read22(pin) for DHT22/AM2302, or DHT.read11(pin) for DHT11.

Example sketch — Serial Monitor

Upload, open Tools → Serial Monitor at 9600 baud, wait a couple of seconds between samples. Blow gently on the grille — humidity should climb.

// DHT11 / DHT22 — temperature & humidity on Serial
#include <dht.h>

#define dataPin 8
dht DHT;

void setup() {
  Serial.begin(9600);
}

void loop() {
  // Uncomment the sensor you wired:
  int readData = DHT.read22(dataPin);  // DHT22 / AM2302
  // int readData = DHT.read11(dataPin);  // DHT11

  float t = DHT.temperature;
  float h = DHT.humidity;

  Serial.print("Temperature = ");
  Serial.print(t);
  Serial.print(" ");
  Serial.print((char)176);
  Serial.print("C | ");
  Serial.print((t * 9.0) / 5.0 + 32.0);
  Serial.print(" ");
  Serial.print((char)176);
  Serial.println("F");

  Serial.print("Humidity = ");
  Serial.print(h);
  Serial.println(" %");
  Serial.println();

  delay(2000);  // respect DHT22's 0.5 Hz pace
}

What the code is doing

  • #include <dht.h> — brings in DHTlib.
  • dataPin 8 — must match your Data wire.
  • read22 / read11 — pick the chip you actually plugged in.
  • DHT.temperature / DHT.humidity — °C and %RH after a successful read.
  • delay(2000) — DHT22 needs ~2 s between samples; DHT11 can go faster but 2 s is a safe habit.

Design tips

  • Don’t spam the sensor: wait at least 1 s (DHT11) or 2 s (DHT22) between reads.
  • Pull-up matters: missing 10 kΩ on a bare sensor → checksum fails / NaN readings.
  • Self-heating: continuous reads can warm the package a little — keep the delay.
  • Sun & breath: direct sun skews temperature; breathing on the grille spikes humidity (great demo!).

In one sentence: moist film + NTC → tiny IC → digital packet on Data — Arduino just asks every couple of seconds.

Quick checklist

  • 5V → VCC, GND → GND, Data → D8
  • 10 kΩ Data→VCC (unless the module already has it)
  • Leave NC open on 4-pin sensors
  • Install DHTlib · use read11 or read22
  • Serial Monitor @ 9600 · wait ≥2 s between samples