Build a climate monitoring station that tracks temperature, humidity, and light levels in your home. This ESP32-based project combines a DHT22 temperature and humidity sensor with an Adafruit TSL2591 light sensor to create a comprehensive environmental monitor that connects to your local WiFi network.
This guide provides a complete wiring diagram, parts list, and step-by-step assembly instructions. The included firmware reads sensor data every 5 seconds and exposes measurements via a web API endpoint, making it easy to integrate with Home Assistant or other home automation systems. Simply configure your WiFi credentials, upload the code, and start monitoring your indoor climate.
Wiring diagram

Gather all the parts
Assemble it in 3 steps
1. Sluit de sensor aan zonder USB-voeding
Verbind VCC met 3V3 (voeding), GND met GND (massa) en DATA met GPIO21 (signaal). Bij een vierpins DHT22 met het rooster naar je toe en de pootjes omlaag: VCC, DATA, niet aansluiten, GND. Volg bij een module de opschriften.
- Gebruik 3V3, niet 5V. Een verkeerde aansluiting kan de sensor of het bord beschadigen.
2. Plaats de weerstand
Verbind de weerstand van 4,7 kΩ tussen DATA en 3V3. De richting maakt niet uit. Heeft de sensor al een ingebouwde pull-upweerstand, dan mag de losse weerstand wegblijven.
3. Sluit de lichtsensor aan zonder USB-voeding
Verbind VIN met 3V3 (voeding), GND met GND (massa), SDA met GPIO19 (data) en SCL met GPIO22 (klok). Laat de DHT22 op GPIO21 zitten.
Review all connections
1. Connections between "sensor" and "ESP32"
2. Connections between "pullup" and "ESP32"
3. Connections between "licht" and "ESP32"
Deploy the firmware
#include <Arduino.h>
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_TSL2591.h>
#include <WiFi.h>
#include <WebServer.h>
// Vul hier je lokale 2,4 GHz-wifi in voordat je op Deploy drukt.
constexpr char wifiNaam[] = "Renele";
constexpr char wifiWachtwoord[] = "nele@home";
DHT sensor(21, DHT22);
Adafruit_TSL2591 licht(2591);
bool lichtGereed = false;
float lux = NAN;
WebServer server(80);
float temperatuur = NAN, vochtigheid = NAN;
uint32_t vorigeMeting;
bool online = false;
void setup() {
Serial.begin(115200);
sensor.begin();
lichtGereed = Wire.begin(19, 22) && licht.begin(&Wire);
if (lichtGereed) {
licht.setGain(TSL2591_GAIN_LOW);
licht.setTiming(TSL2591_INTEGRATIONTIME_100MS);
}
vorigeMeting = millis();
server.on("/metingen", HTTP_GET, [] {
if ((!isfinite(temperatuur) || !isfinite(vochtigheid)) && !isfinite(lux)) {
server.send(503, "application/json", "{\"error\":\"Sensor niet beschikbaar\"}");
return;
}
String json = String("{\"temperature\":") + (isfinite(temperatuur) ? String(temperatuur, 1) : String("null"))
+ ",\"humidity\":" + (isfinite(vochtigheid) ? String(vochtigheid, 1) : String("null"))
+ ",\"illuminance\":" + (isfinite(lux) ? String(lux, 1) : String("null")) + "}";
server.send(200, "application/json", json);
});
WiFi.mode(WIFI_STA);
WiFi.setAutoReconnect(true);
WiFi.begin(wifiNaam, wifiWachtwoord);
server.begin();
}
void loop() {
if (millis() - vorigeMeting >= 5000) {
vorigeMeting = millis();
if (lichtGereed) {
const uint32_t kanalen = licht.getFullLuminosity();
const uint16_t breed = kanalen & 0xFFFF, infrarood = kanalen >> 16;
lux = breed >= 36863 || infrarood >= 36863 ? NAN
: breed == 0 ? 0.0f : licht.calculateLux(breed, infrarood);
if (isfinite(lux) && lux < 0) lux = 0;
}
temperatuur = sensor.readTemperature();
vochtigheid = sensor.readHumidity();
if (isfinite(temperatuur) && isfinite(vochtigheid)) {
Serial.printf("Temperatuur: %.1f C, luchtvochtigheid: %.1f %%\n", temperatuur, vochtigheid);
} else {
Serial.println("Geen geldige DHT22-meting; controleer de bedrading.");
}
}
bool verbonden = WiFi.status() == WL_CONNECTED;
if (verbonden && !online) {
Serial.printf("Home Assistant: http://%s/metingen\n", WiFi.localIP().toString().c_str());
}
online = verbonden;
if (online) server.handleClient();
delay(2);
}Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




