Wiring guide

How to wire a BME280 to an ESP32

To wire a BME280 to an ESP32, connect VIN to 3V3, GND to GND, SCL to GPIO 22 (D22) and SDA to GPIO 21 (D21). The ESP32 and the BME280 are both 3.3 V parts, so no regulator and no level shifter is needed. The sketch below uses the Adafruit BME280 (Adafruit_BME280.h) library. It prints the temperature, the humidity and the pressure.

  • 3.3 V logic
  • Library: Adafruit_BME280.h
  • 4 wires
ESP32 · BME280live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Pin to pin

BME280 to ESP32 wiring table

Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.

BME280 pinESP32 pinWire colorWhy
VIN3V3redThe BME280 chip is a 3.3 V part; many breakouts have no regulator.
GNDGNDblueCommon ground.
SCLGPIO 22 (D22)cyanI2C clock.
SDAGPIO 21 (D21)violetI2C data.
Voltage

Power and logic levels for BME280 and ESP32

Logic level

The ESP32’s GPIO pins are 3.3 V logic and are not 5 V tolerant. Nothing wired to a pin may go above 3.3 V.

Supply

The BME280 takes 3.3 V from 3V3. That pin is the ESP32’s own regulated 3.3 V output.

This pair

On an ESP32 DevKit, Wire.begin() with no arguments puts SDA on GPIO 21 and SCL on GPIO 22, labeled D21 and D22. The ESP32 and the BME280 are both 3.3 V parts, so no regulator and no level shifter is needed.

Pins to leave alone

GPIO 34, 35, 36 (VP) and 39 (VN) are input only: they cannot drive a pin or take an internal pull-up. GPIO 0, 2, 5, 12 and 15 are strapping pins, read at power-on, and GPIO 6 to 11 are the flash chip.

The sketch

The working code for the ESP32

Library: Adafruit BME280 (Adafruit_BME280.h). This is the sketch the circuit above runs.

BME280 on ESP32 I2C
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

Adafruit_BME280 bme;   // on I2C: SDA GPIO 21 (D21), SCL GPIO 22 (D22)

void setup() {
  Serial.begin(115200);
  if (!bme.begin(0x76)) {
    Serial.println("No BME280 at 0x76");
    for (;;) {}
  }
  Serial.println("BME280 found");
}

void loop() {
  Serial.print("Temperature: ");
  Serial.print(bme.readTemperature(), 1);
  Serial.print(" C  Humidity: ");
  Serial.print(bme.readHumidity(), 1);
  Serial.print(" %  Pressure: ");
  Serial.print(bme.readPressure() / 100.0F, 1);
  Serial.println(" hPa");
  delay(1000);
}
Output

What you should see

Open the serial monitor at 115200 baud. The sketch prints BME280 found and then a line with the temperature in degrees C, the humidity in percent and the pressure in hectopascals.

The BME280 is the BMP280 plus a humidity sensor; the two look alike, and a BMP280 sold as a BME280 reads no humidity.

The serial monitor prints this, recorded from the circuit above left at its defaults:

BME280 found
Temperature: 22.0 C  Humidity: 50.0 %  Pressure: 1013.3 hPa
Pitfalls

Common mistakes wiring a BME280 to an ESP32

The wrong address

Adafruit’s board answers at 0x77, the cheap purple ones at 0x76, and bme.begin() with no argument tries 0x77. If it fails, try the other address before suspecting the wiring.

Using a BMP280 library

A BMP280 has no humidity and a different chip ID (0x58 against 0x60). Adafruit_BMP280 refuses a BME280 and the reverse, so match the library to the chip printed on the module.

Powering it from VIN (5 V from USB)

A breakout without a regulator is a bare 3.3 V chip: 5 V on VIN can kill it. Use 3V3.

Build your own BME280 project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.