Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

DHT11 with Arduino Nano — humidity warning LED for the monsoon

Connect a 3-pin DHT11 module to an Arduino Nano on D4, print temperature and humidity, and light the on-board LED when the room passes 75 % RH.

Arduino C++Verified — core avr 1.8.8, DHT sensor library 1.4.7, 3 Nov 2026Compile-only

Community draft — report a mistake

The DHT11 is the cheapest temperature-and-humidity sensor you can buy — about ₹60 — and it’s fine for a “is this room damp?” check. During the monsoon, indoor humidity sits above 75 % for weeks; that’s when fungus starts on walls and electronics.

This sketch uses the Nano’s on-board LED as a warning lamp: it lights whenever humidity passes 75 %. Change HUMID_LIMIT to suit a cupboard, a grain store or a camera dry-box.

Wiring

Arduino NanoOnly the pins used are shown · 5 V logicDHT115VGNDD4VCCDATAGND
Every connection
Arduino NanoDHT11WireNotes
5VVCCred
D4DATAyellowThe blue 3-pin module has its own pull-up resistor.
GNDGNDblack

3.3–5.5 V part, 5 V board. Power it from your board's logic voltage so the data line matches the GPIO: 3.3 V on ESP32 and Pico, 5 V on Uno.

Board quirks

  • Module pin order varies: some boards print S, +, −, others VCC, DATA, GND. Follow the print on yours, not a photo.
  • The DHT11 reports whole degrees and whole percent, ±2 °C / ±5 % RH. For anything you’ll calibrate or log, the DHT22 is worth the extra ₹150.
  • D13 drives the Nano’s on-board LED, so the sketch uses it as the humidity warning without extra wiring.
  • A6/A7 cannot run the DHT protocol (analog-only pins). Use D2–D12 or A0–A5.

Code

dht11-nano.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// DHT11 module (3-pin, pull-up on the module) on an Arduino Nano, with a "too humid" LED warning.
// VCC → 5V, DATA → D4, GND → GND. The on-board LED (D13) lights above 75 % RH.
#include <DHT.h>

const uint8_t DHT_PIN = 4;
const float HUMID_LIMIT = 75.0;  // monsoon rooms sit at 80-90 %
DHT dht(DHT_PIN, DHT11);

void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  dht.begin();
}

void loop() {
  delay(1500);  // DHT11: one reading per second at most
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
    Serial.println(F("DHT11 read failed"));
    return;
  }
  bool humid = h > HUMID_LIMIT;
  digitalWrite(LED_BUILTIN, humid ? HIGH : LOW);
  Serial.print(F("Temp: "));
  Serial.print(t, 0);
  Serial.print(F(" C  Humidity: "));
  Serial.print(h, 0);
  Serial.print(F(" %"));
  if (humid) Serial.print(F("  (humid!)"));
  Serial.println();
}

Library: DHT sensor library (Adafruit (also install Adafruit Unified Sensor)) — compiled with DHT sensor library 1.4.7.

Expected serial output

Serial Monitor · 115200Output
Temp: 30 C  Humidity: 68 %
Temp: 30 C  Humidity: 77 %  (humid!)

Common errors

DHT11 read failed

Wrong pin order on the module, DATA on A6/A7, or reading more than once a second. Full fix.

no matching function for call to DHT::DHT

An old DHT library is installed. Use “DHT sensor library” by Adafruit 1.4.x. Full fix.

Port not showing on Windows

Most Nano clones use a CH340 USB chip that needs a driver. Full fix.

↑↓ to move · Enter to open