Real‑Time Temperature & Humidity Monitoring via Web on Raspberry Pi 4
In this project, a Raspberry Pi 4 hosts a lightweight Bottle web server that reads data from an Adafruit DHT11 temperature‑humidity sensor and returns the values in real time. An RGB LED mounted on the board lights up in a distinct color for each request, giving instant visual feedback that the server is functioning.
How it works
- Navigate to
https://pi‑address:6789/to trigger the root route. The red LED turns on while the page loads. - After the page loads, you can press one of the three buttons:
- Blue – displays the current humidity and turns the LED blue.
- Green – displays the current temperature and turns the LED green.
- Red (Stop) – clears the display, resets the LED to red, and stops continuous updates.
- Each button sends a GET request every second until the stop button is pressed or the browser window is closed.
- Stopping the server with
Ctrl+Cturns off all LEDs and cleans up the GPIO pins.
Hardware schematic
Server code
from bottle import route, run, template, request
import RPi.GPIO as GPIO
import Adafruit_DHT
# Configure GPIO mode
GPIO.setmode(GPIO.BCM)
# Sensor configuration – DHT11 connected to GPIO 25
sensor_type = Adafruit_DHT.DHT11
sensor_pin = 25
GPIO.setup(sensor_pin, GPIO.IN)
# RGB LED pins
GPIO.setup(14, GPIO.OUT) # Red
GPIO.setup(15, GPIO.OUT) # Green
GPIO.setup(18, GPIO.OUT) # Blue
# Helper to turn all LEDs off
def set_leds_off():
GPIO.output(14, GPIO.LOW)
GPIO.output(15, GPIO.LOW)
GPIO.output(18, GPIO.LOW)
# Routes
@route('/')
def index():
set_leds_off()
GPIO.output(14, GPIO.HIGH)
return template('index.html')
@route('/humidity')
def humidity():
set_leds_off()
GPIO.output(18, GPIO.HIGH)
humidity, temperature = Adafruit_DHT.read(sensor_type, sensor_pin)
return {'humidity': humidity}
@route('/temperature')
def temperature_route():
set_leds_off()
GPIO.output(15, GPIO.HIGH)
humidity, temperature = Adafruit_DHT.read(sensor_type, sensor_pin)
return {'temperature': temperature}
@route('/stop')
def stop():
set_leds_off()
GPIO.output(14, GPIO.HIGH)
return {'stop': 'No further updates.'}
# Start the Bottle server
run(host='0.0.0.0', port='6789')
# Clean up on exit
set_leds_off()
GPIO.cleanup()
Source: Get Humidity/Temperature from Web
Manufacturing process
- Raspberry Pi Temperature & Humidity Network Monitor – DIY Setup Guide
- Seamless Temperature & Humidity Monitoring on Raspberry Pi with EzTemp
- How to Connect a DS1820 One‑Wire Temperature Sensor to a Raspberry Pi Using GPIO
- Build a Network‑Enabled Laboratory Weather Station with Raspberry Pi
- Turn Your Raspberry Pi 4 Into a Web Server and Build Your Own Site
- Arduino Temperature & Humidity Logger Using DHT11 and Ethernet Shield
- Arduino UNO & WiFi Shield: Real-Time Temperature Display on the Web via Serial
- Bolt IoT: Advanced Humidity & Temperature Monitoring with DHT11 and Arduino
- Arduino Weather Clock – Real-Time Date, Time, Temperature & Humidity Display
- DHT11 Temperature & Humidity Sensor for Arduino Projects