Temperature and humidity sensor (DHT11)
This is a simple project to build, perfect for beginners as well as for those with more experience. And the best part is that it's very accurate. It showed 22.2°C and 57%, just like a thermostat.
I did some research, and the recommended humidity level in a room should be between 40–60%. It's important not to go:
-
Below 30% → dry skin, irritation, static electricity risk
-
Above 70% → mold, dampness, and unpleasant smells
The temperature and humidity values will be displayed in the Serial Monitor.
Required components:
-
Arduino board (I used a Nano, but any Arduino-compatible microcontroller will work)
-
DHT11 or DHT22 sensor (3 pins: VCC, DATA, GND)
-
Jumper wires
-
Breadboard (optional, but recommended)
Connections:
-
Sensor VCC pin → Arduino 5V pin
-
Sensor GND pin → Arduino GND pin
-
Sensor DATA pin → Arduino pin 2
Code:
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11 // sau DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Eroare senzor");
return;
}
Serial.print("Temperatura: ");
Serial.print(t);
Serial.print(" °C | Umiditate: ");
Serial.print(h);
Serial.println(" %");
}
