Component Guide

Sensors Beginner

BME280 Environmental Sensor

Measures temperature, humidity, and air pressure on one tiny I2C chip. Ideal for weather stations and altitude projects.

BME280 Environmental Sensor

Explain Like I'm 12

The BME280 is like a pocket weather station on a chip. It tells your ESP32 how warm the air is, how damp it feels, and how hard the air is pushing down — the same kind of pressure reading pilots and meteorologists use to guess the weather.

Quick Facts

  • Measures Temperature, humidity, and barometric pressure
  • Pins 4 wires — power, ground, SDA, SCL
  • Best for Weather stations, altitude tracking, climate monitors
  • Update speed New reading about every second

Technical Specifications

Arduino library: Adafruit BME280 Library + Adafruit Unified Sensor

  • Temperature range: −40°C to 85°C
  • Humidity range: 0–100% RH
  • Pressure range: 300–1100 hPa
  • Operating voltage: 3.3 V (recommended for ESP32)
  • Interface: I2C (address 0x76 or 0x77)
  • Sampling rate: up to 1 Hz in normal mode

Pinout

  • VCC Power ESP32 3.3 V Use 3.3 V for direct ESP32 wiring
  • GND Ground ESP32 GND Common ground with the ESP32
  • SDA I2C data ESP32 GPIO21 Data line — do not swap with SCL
  • SCL I2C clock ESP32 GPIO22 Clock line — many breakout boards include pull-up resistors

Wiring

A four-pin BME280 breakout connects over I2C. Match each pin to the ESP32 as shown below.

Wiring Diagram BME280 breakout — VCC to 3.3 V, GND to GND, SDA to GPIO21, SCL to GPIO22 on ESP32
  1. 1

    Unplug USB. Place the BME280 breakout on your breadboard.

  2. 2

    Connect VCC on the module to 3.3 V on the ESP32.

  3. 3

    Connect GND on the module to GND on the ESP32.

  4. 4

    Connect SDA on the module to GPIO21 on the ESP32.

  5. 5

    Connect SCL on the module to GPIO22 on the ESP32.

  6. 6

    Double-check — VCC to 3.3 V, GND to GND, SDA to GPIO21, SCL to GPIO22.

  7. 7

    Plug in USB. Your code must use the correct I2C address for your module.

Code Example

Copy into Arduino IDE. Install the library listed above first.

bme280_read.ino
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

Adafruit_BME280 bme;

void setup() {
  Serial.begin(115200);
  if (!bme.begin(0x76)) {
    Serial.println("BME280 not found at 0x76 — try 0x77 or check wiring");
    while (1) delay(10);
  }
}

void loop() {
  float temp = bme.readTemperature();
  float humidity = bme.readHumidity();
  float pressure = bme.readPressure() / 100.0F;

  if (isnan(temp) || isnan(humidity) || isnan(pressure)) {
    Serial.println("Read failed — check wiring");
  } else {
    Serial.printf("Temp: %.1f C  Humidity: %.0f%%  Pressure: %.0f hPa\n",
                  temp, humidity, pressure);
  }

  delay(1000);
}

Expected Output

Open Serial Monitor at 115200 baud. Every second you should see a line like:

Temp: 23.8 C Humidity: 52% Pressure: 1013 hPa

Breathe on the sensor and humidity rises. Move it near a window and temperature shifts. Pressure changes slowly — useful for weather trend tracking.

Common Mistakes

  • Swapping SDA and SCL — I2C will not respond until the data and clock lines match the code pins.
  • Using the wrong I2C address — many modules use 0x76, but some use 0x77 depending on the SDO pin.
  • Powering a bare sensor at 5 V when your ESP32 expects 3.3 V logic on I2C lines.
  • Sharing the I2C bus without a common GND between the ESP32 and the sensor.

Troubleshooting

  • Serial shows BME280 not found Check VCC, GND, SDA, and SCL wiring. Try address 0x77 if 0x76 fails. Confirm GPIO21 and GPIO22 in your board pinout.
  • Readings show NaN or Read failed Reseat jumper wires, verify 3.3 V at VCC, and power-cycle after fixing connections.
  • Pressure looks wrong indoors Pressure varies with altitude and weather. Compare trends over time rather than expecting an exact room number.

Related Guides

Related Projects

FAQ

Downloads

Official Bosch BME280 datasheet (PDF) — helpful for teachers and advanced builders.

Download Datasheet (PDF)