A comprehensive weather monitoring system built with ESP32-S3 that measures environmental conditions and publishes data via MQTT protocol. Features a local OLED display and wireless connectivity for remote monitoring.
-
Multi-sensor Environmental Monitoring
- Temperature, humidity, and atmospheric pressure (BME280)
- Light intensity measurement (BH1750)
- Magnetic field and compass heading (QMC5883L)
- Calculated altitude based on sea level pressure
-
Real-time Data Visualization
- 128x64 OLED display with organized sensor readings
- Visual light level indicator bar
- Compass heading display
-
Wireless Connectivity
- WiFi connection with automatic reconnection
- MQTT publishing for remote monitoring
- Retained messages for reliable data delivery
-
Robust Operation
- Error handling and sensor validation
- Automatic WiFi and MQTT reconnection
- Configurable update intervals
| Component | Model | Purpose |
|---|---|---|
| Microcontroller | ESP32-S3 | Main processing unit |
| Environmental Sensor | BME280 | Temperature, humidity, pressure |
| Light Sensor | BH1750 | Ambient light measurement |
| Magnetometer | QMC5883L | Magnetic field and compass |
| Display | SSD1306 OLED (128x64) | Local data visualization |
I2C SDA: Pin 17
I2C SCL: Pin 16
All sensors communicate via I2C protocol on the shared bus.
Add these libraries to your Arduino IDE or PlatformIO project:
// Core libraries
#include <WiFi.h>
#include <Wire.h>
// Sensor libraries
#include <Adafruit_BME280.h>
#include <BH1750.h>
#include <QMC5883LCompass.h>
// Display library
#include <Adafruit_SSD1306.h>
// MQTT library
#include <AsyncMqttClient.h>Arduino IDE:
- Go to Tools β Manage Libraries
- Search and install each required library
- Ensure you have the ESP32 board package installed
PlatformIO:
lib_deps =
adafruit/Adafruit BME280 Library
adafruit/Adafruit SSD1306
claws/BH1750
mprograms/QMC5883LCompass
marvinroger/AsyncMqttClientconstexpr const char *WIFI_SSID = "Your_WiFi_Network";
constexpr const char *WIFI_PASSWORD = "Your_Password";constexpr const char *MQTT_HOST = "your-mqtt-broker.local";
constexpr uint16_t MQTT_PORT = 1883;
constexpr const char *MQTT_USERNAME = "your_username";
constexpr const char *MQTT_PASSWORD = "your_password";The QMC5883L magnetometer includes calibration values. Update these based on your specific sensor:
compass.setCalibration(-1361, 1307, -1430, 1383, -1117, 1301);To calibrate your magnetometer:
- Run the sensor in various orientations
- Record min/max values for each axis
- Update the calibration parameters
The system publishes data to the following topics:
| Topic | Data Type | Description |
|---|---|---|
esp/bme280/temperature |
Float | Temperature in Celsius |
esp/bme280/humidity |
Float | Relative humidity (%) |
esp/bme280/pressure |
Float | Atmospheric pressure (hPa) |
esp/bme280/altitude |
Float | Calculated altitude (meters) |
esp/bh1750/light |
Float | Light intensity (lux) |
esp/qmc5883l/x |
Integer | Magnetic field X-axis |
esp/qmc5883l/y |
Integer | Magnetic field Y-axis |
esp/qmc5883l/z |
Integer | Magnetic field Z-axis |
esp/qmc5883l/heading |
Float | Compass heading (degrees) |
All messages are published with QoS 1 and retained flag for reliability.
-
Hardware Assembly
- Connect all sensors to the ESP32-S3 via I2C
- Ensure proper power supply (3.3V for sensors)
- Double-check wiring connections
-
Software Setup
- Install required libraries
- Update WiFi and MQTT credentials
- Adjust sea level pressure for your location
- Upload the code to your ESP32-S3
-
Calibration
- Power on the device
- Allow sensors to stabilize
- Calibrate magnetometer if needed
The OLED display shows real-time data in an organized format:
βββββββββββββββββββββββββββββββ
β WEATHER STATION β
βββββββββββββββββββββββββββββββ€
β T: 25.1Β°C H: 65.2% β
βββββββββββββββββββββββββββββββ€
β P: 1013hPa A: 25m β
βββββββββββββββββββββββββββββββ€
β L: 245.6lux C: 180Β° β
β 0 ββββββββββββββββββββββ 1K β
βββββββββββββββββββββββββββββββ
The bottom bar visualizes light intensity from 0 to 1000 lux.
The system provides comprehensive serial output for debugging:
- Sensor readings every 500ms
- WiFi connection status
- MQTT connection and publish confirmations
- Error messages for troubleshooting
Connect to the serial monitor at 115200 baud to view real-time logs.
Integrate with Home Assistant, OpenHAB, or similar platforms using MQTT:
# Home Assistant sensor configuration
sensor:
- platform: mqtt
name: "Weather Station Temperature"
state_topic: "esp/bme280/temperature"
unit_of_measurement: "Β°C"
- platform: mqtt
name: "Weather Station Humidity"
state_topic: "esp/bme280/humidity"
unit_of_measurement: "%"Set up MQTT subscribers to log historical data:
import paho.mqtt.client as mqtt
import json
from datetime import datetime
def on_message(client, userdata, message):
data = {
'timestamp': datetime.now().isoformat(),
'topic': message.topic,
'value': float(message.payload.decode())
}
# Save to database or file
print(json.dumps(data))
client = mqtt.Client()
client.on_message = on_message
client.connect("your-mqtt-broker", 1883, 60)
client.subscribe("esp/+/+")
client.loop_forever()Modify the sensor reading frequency:
constexpr unsigned long SENSOR_UPDATE_INTERVAL = 1000; // 1 secondThe I2C bus can support additional sensors. Add them to the readSensors() function and create corresponding MQTT topics.
Modify the updateDisplay() function to change the layout, add graphics, or show different information.
Sensors not detected:
- Check I2C wiring (SDA/SCL connections)
- Verify sensor addresses using I2C scanner
- Ensure adequate power supply
WiFi connection problems:
- Verify SSID and password
- Check signal strength
- Ensure ESP32-S3 is within range
MQTT publishing fails:
- Confirm broker address and credentials
- Check network connectivity
- Verify topic permissions
Display issues:
- Confirm OLED I2C address (usually 0x3C)
- Check display wiring
- Verify library compatibility
Enable verbose logging by modifying the serial output or adding debug flags.
- Update Rate: 500ms (configurable)
- Power Consumption: ~80mA average (depends on WiFi usage)
- Memory Usage: Minimal with efficient sensor libraries
- Connectivity: Automatic reconnection for robust operation
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is open source. Please check the LICENSE file for details.
- Adafruit for excellent sensor libraries
- ESP32 community for development support
- Arduino ecosystem for making embedded development accessible
Built with β€οΈ for the maker community