Codey OnlineArduino & ESP32 component library › DHT11 Sensor Module
DHT11 Sensor Module
Sensors

DHT11 Sensor Module

DHT11 temperature and humidity sensor module

Width: 35.4 mm

Pinout — DHT11 Sensor Module

Pin Signal Description
VCC power Top right edge header hole for VCC
DAT data Middle right edge header hole for data
GND ground Bottom right edge header hole for ground

Example wiring diagram — DHT11 Sensor Module

From To Wire
board:5V x1:VCC red
board:GND x1:GND black
board:D2 x1:DAT green

Example Arduino code — DHT11 Sensor Module

This example was written and compile-checked for the arduino-uno. Codey Online adapts it to any other supported board for you.

#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  dht.begin();
  Serial.println("DHT11 sensor module example");
}

void loop() {
  delay(2000); // DHT11 needs a slow refresh rate

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

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

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

Related components

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

Build your Arduino or ESP32 project with AI

Describe what you want to build. Codey Online writes the code, draws the wiring diagram, compiles it and flashes your board straight from the browser.

Start for free