← Back to Projects

Raspberry Pi Climate Monitor

A DHT22 sensor on a Raspberry Pi, a live web dashboard, and an LED strip that changes colour with the room temperature.

Category IoT
Hardware Raspberry Pi, DHT22, WLED strip
Stack Python, Flask, MQTT, Chart.js
The dashboard over one simulated day, sped up. The readings are simulated to show how the interface behaves; they are not recorded data.

Overview

A home climate monitor built around a single DHT22 sensor. Readings travel over MQTT to a small web app, which shows live temperature and humidity in any browser on the network. The same readings also set the colour of an LED strip, so the temperature of the room can be read at a glance.

How it works

  • A Python publisher reads the DHT22 on GPIO 4. When the sensor misreads, which DHT sensors do often, it retries up to five times, then publishes temperature, humidity and a timestamp as JSON to an MQTT broker every five seconds.
  • A Flask app subscribes to that topic, keeps the latest reading and serves it at a /temperature endpoint. One setting switches it to read the sensor directly over GPIO instead.
  • The dashboard polls that endpoint and shows live temperature and humidity cards plus a Chart.js trend chart of the last 20 readings. You can switch the chart between both, temperature only or humidity only, and set the refresh interval from 1 to 300 seconds.
  • The publisher shuts down cleanly on Ctrl+C, releasing the sensor and closing the MQTT connection.

Temperature as colour

Alongside each reading, the publisher sends a command to a WLED controller to colour the LED strip. Between 20 and 25 °C the colour blends smoothly between six stops, from dark blue through cyan and green to orange and red.

The dashboard

Cards for the current temperature and humidity sit above the trend chart, which plots both on separate axes.

Climate Monitor dashboard with temperature and humidity cards and a line chart of both readings over time
Sample screenshot with simulated readings.
Next Project Raspberry Pi Timelapse Controller →