Wiring guide

How to wire a BMP280 to an Arduino Mega

To wire a BMP280 to an Arduino Mega, connect VIN to 3.3V, GND to GND, SCL to pin 21 and SDA to pin 20. The common breakout has no regulator, so power it from 3.3 V, not 5 V; its pull-ups then go to 3.3 V, which the board reads as high. The sketch below uses the Adafruit BMP280 (Adafruit_BMP280.h) library. It prints the temperature, the pressure and an altitude estimate.

  • 5 V logic
  • Library: Adafruit_BMP280.h
  • 4 wires
Arduino Mega · BMP280live0.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

BMP280 to Arduino Mega 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.

BMP280 pinArduino Mega pinWire colorWhy
VIN3.3VredThe BMP280 chip is a 3.3 V part; many breakouts have no regulator.
GNDGNDblueCommon ground.
SCLpin 21cyanI2C clock.
SDApin 20violetI2C data.
Voltage

Power and logic levels for BMP280 and Arduino Mega

Logic level

The Arduino Mega’s pins are 5 V logic. A 5 V part can drive them directly; a part whose signal pins are limited to 3.3 V needs a level shifter.

This pair

On the Mega the I2C bus is pin 20 (SDA) and pin 21 (SCL), not A4 and A5 as on an Uno. The SDA and SCL pins by AREF are the same two nets. The common purple BMP280 breakout has no regulator, so it runs from the Arduino Mega’s 3.3V pin, not 5V. Its I2C pull-ups then go to 3.3 V, which the ATmega2560 reads as high.

Pins to leave alone

Pins 14 to 19 are the three extra serial ports and 20 and 21 are I2C, so keep them free if you will need those. An Uno shield’s I2C on A4 and A5 is not connected to anything on a Mega.

The sketch

The working code for the Arduino Mega

Library: Adafruit BMP280 (Adafruit_BMP280.h). This is the sketch the circuit above runs.

BMP280 on Arduino Mega I2C
#include <Wire.h>
#include <Adafruit_BMP280.h>

Adafruit_BMP280 bmp;   // on I2C: SDA pin 20, SCL pin 21

void setup() {
  Serial.begin(9600);
  if (!bmp.begin(0x76)) {
    Serial.println("No BMP280 at 0x76");
    for (;;) {}
  }
  Serial.println("BMP280 found");
}

void loop() {
  Serial.print("Temperature: ");
  Serial.print(bmp.readTemperature(), 1);
  Serial.print(" C  Pressure: ");
  Serial.print(bmp.readPressure() / 100.0F, 1);
  Serial.print(" hPa  Altitude: ");
  Serial.print(bmp.readAltitude(1013.25), 0);
  Serial.println(" m");
  delay(1000);
}
Output

What you should see

Open the serial monitor at 9600 baud. The sketch prints BMP280 found and then a line with the temperature in degrees C, the pressure in hectopascals and the altitude. The sensor starts at 22 degrees C and about 1013 hPa.

If it prints that no sensor was found, the address is the first thing to check: this circuit answers at 0x76, and some breakouts use 0x77.

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

BMP280 found
Temperature: 22.0 C  Pressure: 1013.3 hPa  Altitude: -0 m
Pitfalls

Common mistakes wiring a BMP280 to an Arduino Mega

The wrong address

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

Powering a bare breakout from 5V

The six-pin purple board has no regulator, so 5V goes straight to a chip rated for 3.6 V. Use the Arduino Mega’s 3.3V pin, as in the circuit above.

Confusing it with a BME280

The BME280 looks the same and adds humidity. A BMP280 reports a chip ID of 0x58, a BME280 0x60, and each library refuses the other. If begin() fails at both addresses, check which chip you have.

Build your own BMP280 project

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