ESP32 IoT Environmental Weather Station with BME280
This project shows how to build a compact environmental weather station using an ESP32 microcontroller and a BME280 sensor module. The ESP32 polls barometric pressure, ambient temperature, and relative humidity over I2C and transmits the readings over Wi-Fi for remote monitoring.

How It Works
The BME280 combines piezoresistive pressure sensing, capacitive humidity sensing, and a temperature sensor inside a single package with factory-trimmed calibration registers. Reading raw ADC counts from the sensor and compensating them using the onboard calibration coefficients yields accurate physical measurements.
I2C Bus Communication: The ESP32 acts as the I2C master and communicates with the BME280 over two lines—SDA (serial data) and SCL (serial clock)—using its 7-bit hardware address (typically 0x76 or 0x77 depending on the SDO pin state).
Oversampling and Filtering: Enabling oversampling on temperature, pressure, and humidity reduces measurement noise at the cost of slightly longer conversion times and higher active current draw.
Wi-Fi Telemetry: Using its built-in 802.11 b/g/n radio and TCP/IP stack, the ESP32 formats environmental metrics and pushes them over Wi-Fi to local dashboards or cloud endpoints.
Components Needed
- ESP32 Development Board
- BME280 Barometric Pressure, Temperature, and Humidity Sensor Module
- Breadboard and jumper wires
- USB-C or Micro-USB cable for programming and power
Wiring to the ESP32
Connect VCC on the BME280 module to the ESP32 3.3V rail and GND to GND. Wire SDI (SDA) to GPIO 21 and SCK (SCL) to GPIO 22, which serve as the default I2C pins on standard ESP32 boards.
| Module pin | ESP32 pin | Function |
|---|---|---|
| VCC | 3.3V | Power supply |
| GND | GND | Common ground |
| SDI (SDA) | GPIO 21 | I2C serial data |
| SCK (SCL) | GPIO 22 | I2C serial clock |

Build and Upload
Open the Arduino IDE and confirm that the ESP32 board package and the Adafruit BME280 Library (along with Adafruit Unified Sensor) are installed.
Create a new sketch and paste the weather station code shown below.
Replace the placeholder Wi-Fi SSID and password with your network credentials.
Select your ESP32 board from the Tools > Board menu and pick the matching serial port.
Upload the sketch and open the Serial Monitor at 115200 baud to verify sensor detection and telemetry output.
Example Code
ESP32 environmental weather station reading temperature, humidity, and pressure over I2C and reporting over Wi-Fi. Upload it with your ESP32 board selected and open the Serial Monitor at 115200 baud.
#include <WiFi.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
// Wi-Fi credentials
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
// I2C pin definitions
const int SDA_PIN = 21;
const int SCL_PIN = 22;
// Default BME280 I2C address (some modules use 0x77)
#define BME280_I2C_ADDR 0x76
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
void setup() {
Serial.begin(115200);
delay(1000);
Wire.begin(SDA_PIN, SCL_PIN);
if (!bme.begin(BME280_I2C_ADDR)) {
Serial.println("Could not find a valid BME280 sensor, check wiring or I2C address!");
while (1) {
delay(1000);
}
}
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected! IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
float temperatureC = bme.readTemperature();
float humidityPct = bme.readHumidity();
float pressureHpa = bme.readPressure() / 100.0F;
float altitudeM = bme.readAltitude(SEALEVELPRESSURE_HPA);
Serial.print("Temp: ");
Serial.print(temperatureC);
Serial.print(" °C | Humidity: ");
Serial.print(humidityPct);
Serial.print(" % | Pressure: ");
Serial.print(pressureHpa);
Serial.print(" hPa | Approx Alt: ");
Serial.print(altitudeM);
Serial.println(" m");
delay(5000); // Report every 5 seconds
}
Applications
- Indoor and outdoor microclimate logging stations
- Barometric trend tracking for local weather forecasting
- HVAC and ventilation monitoring in enclosed spaces
- Altitude estimation and environmental data collection nodes
Board Notes and Constraints
The ESP32 runs a dual-core Tensilica Xtensa LX6 processor at up to 240 MHz with built-in Wi-Fi and Bluetooth, making it well suited for periodic sensor polling and network publishing.
Logic Voltage: The ESP32 is a 3.3V device. While many BME280 breakout boards include onboard regulators and level shifters, powering the sensor from 3.3V and avoiding 5V signal levels prevents damage.
Self-Heating Effects: Keeping the BME280 close to the ESP32 or sampling continuously without sleep intervals can warm the sensor slightly and bias temperature and relative humidity readings upward.
Wi-Fi Current Peaks: Wi-Fi association and packet transmission introduce brief current spikes, so a regulated power rail and proper decoupling keep the MCU stable.
| ESP32 characteristic | Value | Why it matters here |
|---|---|---|
| Logic voltage | 3.3V | Matches native 3.3V I2C signaling and prevents GPIO overvoltage |
| Bus interface | Hardware I2C (Wire) | Supports clean two-wire polling of multi-metric BME280 registers |
| Connectivity | Wi-Fi 802.11 b/g/n & BLE | Transmits environmental telemetry to cloud services or local endpoints |
| Low-power modes | Light / Deep Sleep | Allows duty-cycled weather logging to reduce sensor self-heating and power draw |
Troubleshooting
- Sensor initialization fails (
0x76not found): CheckSDAandSCLconnections, verify3.3Vpower, and test address0x77(often set whenSDOis pulled high or tied toVCC). - Temperature reads higher than room ambient: Move the BME280 away from heat sources like the ESP32 chip or USB voltage regulator, and increase the polling interval.
- Humidity readings drift after exposure to condensation: Let the sensor dry in normal ambient air or use forced-mode sampling with intervals between readings.
- Frequent disconnects or brownouts during Wi-Fi traffic: Check cable quality and power supply current headroom, and add a decoupling capacitor near the power supply rail.
Taking It Further
Once your baseline serial telemetry is working cleanly, you can expand the weather station in several practical ways:
Cloud and Time-Series Logging: Publish JSON readings over MQTT or HTTPS to a time-series database or cloud dashboard to plot pressure drops and humidity shifts over time.
Deep Sleep Duty Cycling: Put the ESP32 into deep sleep between measurements and wake on a timer to cut power consumption for battery-powered deployments.
Local Display or Web UI: Attach a small I2C OLED display on the same SDA/SCL bus or serve a lightweight web dashboard directly from the ESP32.