Monitoring atmospheric pressure, temperature, and humidity is valuable for weather tracking, indoor climate control, and even altitude estimation. In this project, we’ll build an IoT barometric/weather logger using a BMP280 or BME280 sensor, send data to the cloud, and visualize it on a dashboard.
What You’ll Need
Component Purpose BMP280 or BME280 sensor module Measures pressure, temperature (plus humidity in BME280)ESP32 or ESP8266 development boardWi-Fi connectivity and data processing Breadboard, jumper wires Prototyping connections3.3V regulator / level shifte rIf your board is 5V—ensure safe voltage levelsCloud / dashboard platforme.g. ThingsBoard, Adafruit IO, MQTT + Grafana, etc.(Optional) OLED / LCD displayFor local readout(Optional) Battery + power management For off-grid / remote deployment
Circuit & Wiring
- Power: Supply the sensor with 3.3 V (do not use 5 V).
- I²C interface:
- SDA → microcontroller SDA
- SCL → microcontroller SCL
- Add pull-up resistors (e.g. 4.7 kΩ) if not already present
- (Optional) If your microcontroller is 5V, use a level shifter on SDA / SCL.
- (Optional) Local display: connect an OLED (e.g. SSD1306) or LCD via I²C.
If using SPI mode instead, wire MOSI, MISO, CLK, CS pins and initialize accordingly.
Software / Firmware
We’ll use Arduino (or PlatformIO) with following logical flow:
- Include libraries:
Wire.h (for I²C)Adafruit_BME280.h or Adafruit_BMP280.h (or unified sensor library)- Wi-Fi / MQTT or HTTP client library
- (Optional) Display library
- In
setup():
- Initialize serial for debugging
- Initialize I²C
- Begin sensor (check for failure)
- Connect to Wi-Fi
- Initialize cloud / MQTT client
- (Optional) Initialize display
- In
loop() (or scheduled task):
- Read sensor values:
temperature, pressure (and humidity if BME280) - Optionally, compute altitude using standard formula (with sea-level pressure)
- Format JSON payload or topic message
- Publish to cloud / server
- (Optional) Display values locally
- Wait or sleep until next reading
- (Optional) Implement low-power mode / deep sleep for battery saving.
Sample Code (Sketch Skeleton)
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h> // or Adafruit_BMP280.h
#include <WiFi.h>
#include <PubSubClient.h>
#define SEALEVEL_PRESSURE_HPA 1013.25
// Replace with your Wi-Fi credentials
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASS";
// MQTT / cloud parameters
const char* mqtt_server = "your.mqtt.server";
const int mqtt_port = 1883;
const char* topic = "weather/data";
Adafruit_BME280 bme; // for BME280. For BMP280, use Adafruit_BMP280
WiFiClient espClient;
PubSubClient mqttClient(espClient);
void connectWiFi() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected.");
}
void connectMQTT() {
while (!mqttClient.connected()) {
if (mqttClient.connect("weather-logger")) {
Serial.println("MQTT connected");
} else {
delay(1000);
}
}
}
void setup() {
Serial.begin(115200);
Wire.begin();
if (!bme.begin(0x76)) {
Serial.println("Sensor not found!");
while (1);
}
connectWiFi();
mqttClient.setServer(mqtt_server, mqtt_port);
}
void loop() {
if (!mqttClient.connected()) {
connectMQTT();
}
mqttClient.loop();
float temperature = bme.readTemperature();
float pressure = bme.readPressure() / 100.0F; // convert Pa to hPa
float humidity = bme.readHumidity(); // only valid for BME280
float altitude = bme.readAltitude(SEALEVEL_PRESSURE_HPA);
// Prepare JSON (or any format)
String payload = "{";
payload += "\"temperature\":" + String(temperature, 2) + ",";
payload += "\"pressure\":" + String(pressure, 2) + ",";
payload += "\"altitude\":" + String(altitude, 2);
// If using BME:
payload += ",\"humidity\":" + String(humidity, 2);
payload += "}";
Serial.println("Publishing: " + payload);
mqttClient.publish(topic, payload.c_str());
delay(10000); // 10-second interval (or use timer / sleep)
}
You can expand the code to handle reconnections, QoS, retained messages, OTA updates, etc.
Dashboard & Cloud Setup
Pick a dashboard or IoT platform. Here are some ideas:
- ThingsBoard: Host your own or use cloud edition. Build dashboards with charts, gauges, maps.
- Adafruit IO: Simple dashboards with feeds and charts.
- MQTT + InfluxDB + Grafana: Use your own server or cloud VM.
- Google Sheets / Google Cloud: Use HTTP POST to send data to a lightweight backend.
On dashboard, create:
- Live gauge or line-chart for temperature
- Live gauge / trend chart for pressure
- (If applicable) humidity chart
- Optional derived charts (e.g. pressure changes over time)
- Alerts / thresholds (e.g. pressure drop > threshold → send email or notification)
Enhancements & Extensions
- Local storage: Save data to microSD or internal flash when network is down.
- Battery & solar: Use Li-ion + solar panel + power management to run off-grid.
- Multiple sensors: Add light sensors, CO₂ sensors, VOC sensors, etc., on same node.
- Multi-node network: Have nodes publish to central broker.
- Web UI on device: Host a small webpage on the ESP showing latest readings.
- Calibration & filtering: Use digital filters or calibration offsets to improve accuracy.
- Enclosure & weatherproofing: Protect sensor in a Stevenson screen / Vented case.
Challenges & Tips
- Ensure the module runs at 3.3 V and not exceed its voltage limits.
- Use proper pull-up resistors on I²C lines if not on the breakout.
- Sea-level pressure changes day-to-day; for altitude calculations, calibrate with local baseline.
- Avoid thermal self-heating: avoid placing electronics too close to sensor.
- Use averaging / smoothing to reduce jitter in pressure readings.
Conclusion
This IoT Barometric & Weather Logger is a versatile project: you get environmental data, remote monitoring, and the ability to expand further. It’s ideal for hobbyists, weather enthusiasts, or as a module in larger smart home / climate systems.