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.

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.
#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);
}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.
| Symptom | Likely cause |
|---|---|
| No data | Wrong COM index |
| Sensor error | DATA pin or missing pull-up |
| Wild numbers | Loose breadboard, too-short delay |
| Processing silent | Baud or Serial Monitor still open |
