Codey OnlineBiblioteca de componentes Arduino y ESP32 › DHT22
DHT22
Sensores

DHT22

El DHT22 es un sensor digital de temperatura y humedad relativa que se usa con microcontroladores. Se comunica mediante una interfaz de datos de un solo hilo y normalmente se conecta con VCC, GND y una línea DATA.

Ancho: 17.7 mm

Pinout — DHT22

Pin Señal Descripción
GND ground Ground reference for the DHT22 module power and data signal.
VCC power Positive supply input for the DHT22 module, typically 3.3V to 5V.
DATA data Single-wire digital data output from the DHT22 temperature and humidity sensor.

Esquema de cableado de ejemplo — DHT22

Desde Hasta Cable
board:5V x1:VCC red
board:GND x1:GND black
board:D2 x1:DATA green

Código Arduino de ejemplo — DHT22

Este ejemplo se escribió y verificó por compilación para arduino-uno. Codey Online lo adapta a cualquier otra placa compatible.

#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

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

  dht.begin();
  Serial.println("DHT22 sensor example");
}

void loop() {
  delay(2000); // DHT22 needs a slow sampling rate

  float humidity = dht.readHumidity();
  float temperatureC = dht.readTemperature();

  if (isnan(humidity) || isnan(temperatureC)) {
    Serial.println("Failed to read from DHT22 sensor");
    return;
  }

  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.print(" %\tTemperature: ");
  Serial.print(temperatureC);
  Serial.println(" °C");
}

Componentes relacionados

18650 Battery Shield with USB-C Charger and 5V Boost Converter

18650 Battery Shield with USB-C Charger and 5V Boost Converter

2.4 inch OLED Display I2C 3.3V

2.4 inch OLED Display I2C 3.3V

3.5 inch TFT LCD Shield

3.5 inch TFT LCD Shield

50kg Load Cell Weight Sensor

50kg Load Cell Weight Sensor

Crea tu proyecto de Arduino o ESP32 con IA

Describe lo que quieres construir. Codey Online escribe el codigo, dibuja el esquema de conexiones, lo compila y graba tu placa directamente desde el navegador.

Empieza gratis