Project Overview
This project builds a comprehensive home weather and environmental monitoring station using a Raspberry Pi, multiple sensors, and a professional-grade data visualization stack. The system collects temperature, humidity, barometric pressure, air quality (PM2.5/PM10), and ambient light data, stores it in a time-series database, displays it on real-time dashboards, and sends alerts when conditions exceed thresholds.
Required Hardware
| Component | Price | Purpose |
| Raspberry Pi 4B (4GB) | $55 | Main server and sensor hub |
| SanDisk Max Endurance 64GB SD | $15 | Reliable storage for 24/7 operation |
| BME280 sensor (I2C) | $5 | Temperature, humidity, pressure |
| PMS5003 air quality sensor (UART) | $15 | PM1.0, PM2.5, PM10 particulate matter |
| BH1750 light sensor (I2C) | $3 | Ambient light level (lux) |
| ADS1115 ADC (I2C) | $4 | 4-channel analog input expansion |
| Dupont jumper wires | $3 | Sensor connections |
| Breadboard or perfboard | $3 | Wiring |
| Project case | $8 | Enclosure |
| Total | $111 | |
Software Stack
| Component | Purpose |
| InfluxDB 2 | Time-series database for sensor data |
| Grafana | Dashboards and visualization |
| Python | Sensor reading and data processing |
| Docker | Container deployment |
| Telegram Bot API | Alert notifications |
Sensor Wiring
BME280 (I2C) - Indoor Climate
| BME280 | Pi GPIO | Pin # |
| VCC | 3.3V | Pin 1 |
| GND | GND | Pin 6 |
| SCL | GPIO 3 (SCL) | Pin 5 |
| SDA | GPIO 2 (SDA) | Pin 3 |
PMS5003 (UART) - Air Quality
| PMS5003 | Pi GPIO | Pin # |
| VCC | 5V | Pin 2 |
| GND | GND | Pin 6 |
| TXD | GPIO 15 (RXD) | Pin 10 |
| RXD | GPIO 14 (TXD) | Pin 8 |
| SET | 3.3V | Pin 1 |
| RST | GPIO 23 | Pin 16 |
BH1750 (I2C) - Ambient Light
| BH1750 | Pi GPIO | Pin # |
| VCC | 3.3V | Pin 1 |
| GND | GND | Pin 9 |
| SCL | GPIO 3 (SCL) | Pin 5 (shared) |
| SDA | GPIO 2 (SDA) | Pin 3 (shared) |
| ADDR | GND | Sets address to 0x23 |
Step 1: Raspberry Pi Setup
- Install Raspberry Pi OS Lite (64-bit) using Raspberry Pi Imager
- Enable SSH, set username/password during imaging
- Boot and update:
sudo apt update && sudo apt full-upgrade -y
- Install dependencies:
sudo apt install python3-pip i2c-tools git -y
- Enable I2C and UART:
sudo raspi-config (Interface Options)
- Install Docker:
curl -fsSL https://get.docker.com | sh
- Add user to docker group:
sudo usermod -aG docker $USER
Step 2: Verify I2C Sensors
sudo i2cdetect -y 1
You should see addresses: 0x23 (BH1750), 0x48 (ADS1115), 0x76 or 0x77 (BME280).
Step 3: Python Sensor Reader
#!/usr/bin/env python3
import serial, time, board, busio
import adafruit_bme280, adafruit_bh1750
from influxdb_client import InfluxDBClient, Point
from influxdb_client.client.write_api import SYNCHRONOUS
INFLUX_URL = "http://localhost:8086"
INFLUX_TOKEN = "your-token-here"
INFLUX_ORG = "home"
INFLUX_BUCKET = "weather"
i2c = busio.I2C(board.SCL, board.SDA)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76)
bh1750 = adafruit_bh1750.BH1750(i2c, address=0x23)
pm_sensor = serial.Serial('/dev/ttyAMA0', baudrate=9600, timeout=2)
def read_pms5003():
pm_sensor.reset_input_buffer()
while True:
data = pm_sensor.read(32)
if len(data) >= 32 and data[0] == 0x42 and data[1] == 0x4d:
pm10 = (data[10] << 8) + data[11]
pm25 = (data[12] << 8) + data[13]
pm100 = (data[14] << 8) + data[15]
return {'pm1_0': pm10, 'pm2_5': pm25, 'pm10': pm100}
time.sleep(0.1)
client = InfluxDBClient(url=INFLUX_URL, token=INFLUX_TOKEN, org=INFLUX_ORG)
write_api = client.write_api(write_options=SYNCHRONOUS)
while True:
try:
temperature = bme280.temperature
humidity = bme280.relative_humidity
pressure = bme280.pressure
light = bh1750.lux
pm_data = read_pms5003()
point = Point("environment").tag("location", "indoor") .field("temperature", round(temperature, 2)) .field("humidity", round(humidity, 2)) .field("pressure", round(pressure, 2)) .field("light", round(light, 2)) .field("pm1_0", pm_data['pm1_0']) .field("pm2_5", pm_data['pm2_5']) .field("pm10", pm_data['pm10'])
write_api.write(bucket=INFLUX_BUCKET, record=point)
print(f"Written: {temperature:.1f}C, {humidity:.1f}%, {pressure:.1f}hPa, PM2.5={pm_data['pm2_5']}")
except Exception as e:
print(f"Error: {e}")
time.sleep(60)
Step 4: Deploy with Docker Compose
version: '3.8'
services:
influxdb:
image: influxdb:2.7
container_name: influxdb
ports:
- "8086:8086"
volumes:
- ./data/influxdb:/var/lib/influxdb2
environment:
- DOCKER_INFLUXDB_INIT_MODE=setup
- DOCKER_INFLUXDB_INIT_USERNAME=admin
- DOCKER_INFLUXDB_INIT_PASSWORD=your-secure-password
- DOCKER_INFLUXDB_INIT_ORG=home
- DOCKER_INFLUXDB_INIT_BUCKET=weather
- DOCKER_INFLUXDB_INIT_RETENTION=365d
restart: unless-stopped
grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- "3000:3000"
volumes:
- ./data/grafana:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD=your-grafana-password
depends_on:
- influxdb
restart: unless-stopped
Step 5: Configure Grafana Dashboard
- Open http://your-pi-ip:3000, login with admin password
- Add Data Source: InfluxDB, Query Language: Flux
- URL: http://influxdb:8086, Org: home, Token: (from InfluxDB), Bucket: weather
- Create dashboard panels with Flux queries
Example Flux Queries
// Temperature and Humidity
from(bucket: "weather")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == "environment")
|> filter(fn: (r) => r._field == "temperature" or r._field == "humidity")
|> aggregateWindow(every: v.windowPeriod, fn: mean)
// Air Quality PM2.5
from(bucket: "weather")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._field == "pm2_5")
|> aggregateWindow(every: v.windowPeriod, fn: mean)
Step 6: Telegram Alerts
- Message @BotFather on Telegram, create bot, save API token
- Get chat_id from https://api.telegram.org/botYOUR_TOKEN/getUpdates
- Create Python alert script that queries InfluxDB and sends messages
- Schedule with cron:
*/5 * * * * /usr/bin/python3 /home/pi/weather-station/alerts.py
Step 7: Auto-Start Service
sudo systemctl enable weather-station.service
sudo systemctl start weather-station.service
Remote Access Options
| Method | Setup | Security |
| Tailscale | curl -fsSL https://tailscale.com/install.sh | sh | Excellent (WireGuard mesh) |
| Cloudflare Tunnel | Install cloudflared | Excellent (no open ports) |
| Local only | http://raspberrypi.local:3000 | Home network only |
Expanding the System
| Sensor | Interface | Purpose |
| SCD40 | I2C | True CO2 sensing (accurate NDIR) |
| MQ-135 | Analog via ADS1115 | General air quality (CO2, NH3, benzene) |
| DS18B20 | 1-Wire | Fridge/freezer/pool temperature |
| SHT40 | I2C | Premium temp/humidity accuracy |
| Anemometer | Pulse input | Wind speed |
Troubleshooting
| Problem | Solution |
| I2C devices not detected | Check wiring; verify I2C enabled with raspi-config; run i2cdetect |
| PMS5003 not reading | Verify serial not used by console; check /dev/ttyAMA0; check permissions |
| InfluxDB connection refused | Verify container running with docker ps; wait for init to complete |
| Grafana shows no data | Check token, bucket name, time range; verify sensor script writing data |
| Sensor readings erratic | Add 100nF cap across sensor power pins; check 3.3V rail stability |