Project 01 · DHT11

Temperature and humidity, live.

First digital sensor, first library, first two-value CSV. The weather-station energy of a greenhouse, in one double period.

2 × 45 minAdafruit DHT libraryPin 2 + 10kΩ pull-upIoT intro
DHT11 wired to Arduino
VCC → 5V, GND → GND, DATA → D2. Raw 3-pin modules need 10kΩ between VCC and DATA.

Why this sensor

DHT11 speaks digital, so students skip ADC confusion. Relative humidity is a physics gift: water vapor versus what the air can hold at that temperature.

Line format: 24.5,60 — temperature, humidity. Processing already learned this split in the intro.

Install the library

Sketch → Include Library → Manage Libraries → “DHT sensor library” by Adafruit. Install dependencies when asked.

dht11_serial.ino
#include "DHT.h"

#define DHTPIN 2
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

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

void loop() {
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();
  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  Serial.print(temperature);
  Serial.print(",");
  Serial.println(humidity);
  delay(2000);
}
dht11_dashboard.pde
import processing.serial.*;

Serial myPort;
float temp = 0;
float hum = 0;

void setup() {
  size(480, 260);
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\n');
}

void draw() {
  background(16);
  fill(240);
  textSize(20);
  text("Temperature: " + nf(temp, 1, 1) + " C", 40, 50);
  text("Humidity: " + nf(hum, 1, 1) + " %", 40, 84);
  fill(220, 70, 70);
  rect(40, 120, map(temp, 0, 50, 0, 380), 28);
  fill(70, 120, 230);
  rect(40, 164, map(hum, 0, 100, 0, 380), 28);
  if (temp > 30) {
    fill(255, 70, 90);
    text("WARNING: HIGH TEMPERATURE", 40, 230);
  }
}

void serialEvent(Serial p) {
  String data = p.readStringUntil('\n');
  if (data != null && data.contains(",")) {
    String[] values = split(trim(data), ",");
    if (values.length == 2) {
      temp = float(values[0]);
      hum = float(values[1]);
    }
  }
}

Tasks & faults

Basic Text for both values.
Intermediate Two colored bars.
Advanced High-temperature alarm.
Challenge CSV log or a scrolling graph.
SymptomLikely cause
No dataWrong COM index
Sensor errorDATA pin or missing pull-up
Wild numbersLoose breadboard, too-short delay
Processing silentBaud or Serial Monitor still open
Next: LDR