Skip to main content

dht22

Read temperature and humidity from DHT22 (AM2302) sensors with a single GPIO pin.

Overview

The dht22 node reads temperature and relative humidity from DHT22 (AM2302) sensors. This affordable sensor provides both measurements from a single digital pin, making it ideal for environmental monitoring, smart home, and greenhouse applications.

±0.5°C
Temp Accuracy
±2% RH
Humidity Accuracy
-40 to +80°C
Temp Range
2 sec
Min Interval

DHT11 vs DHT22

Spec DHT11 DHT22
Temp Range 0-50°C -40 to 80°C
Temp Accuracy ±2°C ±0.5°C
Humidity Range 20-80% RH 0-100% RH
Price ~$1 ~$4

Wiring

4-Pin Module

VCC → 3.3V or 5V

DATA → GPIO 4

NC → Not Connected

GND → GND

3-Pin Module (Breakout)

VCC/+ → 3.3V

OUT/DATA → GPIO 4

GND/- → GND

Breakout modules have built-in pull-up resistor

Properties

Property Type Default Description
pin number 4 GPIO pin (BCM numbering)
sensorType string "22" Sensor type: "11" or "22"
interval number 5 Reading interval in seconds (min 2)
tempUnit string "C" Temperature unit: "C" or "F"

Output

{
  "payload": {
    "temperature": 23.5,
    "humidity": 45.2
  },
  "temperature": 23.5,
  "humidity": 45.2,
  "tempUnit": "°C",
  "timestamp": 1640000000000
}

Example: Room Climate Monitor

Display temperature and humidity on dashboard with comfort zone alerts.

// Function node: Comfort zone checker
var temp = msg.temperature;
var humidity = msg.humidity;
var status = "comfort";
var alert = null;

if (temp < 18) {
    status = "cold";
    alert = "Temperature too low!";
} else if (temp > 26) {
    status = "hot";
    alert = "Temperature too high!";
}

if (humidity < 30) {
    status = "dry";
    alert = "Humidity too low!";
} else if (humidity > 60) {
    status = "humid";
    alert = "Humidity too high!";
}

msg.payload = {
    temperature: temp,
    humidity: humidity,
    status: status,
    alert: alert
};

return msg;

Troubleshooting

Checksum errors
  • Add 10kΩ pull-up resistor if not using breakout board
  • Keep wires short (<20cm preferred)
  • Don't read faster than every 2 seconds
Timeout errors
  • Check wiring connections
  • Verify sensor is getting power
  • Try different GPIO pin

Related Nodes