Starting Electronics Needs Your Help!
It is that time of the year when we need to pay for web hosting and buy new components and equipment for new tutorials. You can help by making a donation. Contribute to this website by clicking the Donate button. The total will be updated once daily. (You may need to clear your browser cache to see the updates.)

Target Amount: $2000
Amount Raised: $1061

Donations Received

Top Donor: C.C. $100

X

GY-BMP280-3.3 Pressure Sensor Module Arduino Tutorial

Created on: 27 March 2018

This GY-BMP280-3.3 pressure sensor module Arduino tutorial shows how to connect a pressure sensor module to Arduino and how to read pressure and temperature from the device.

Either I²C or SPI interfaces can be used to connect the module to Arduino. The module operates from 3.3V and is not 5V tolerant, so it is important to wire it correctly to 5V Arduinos using level shifters and 3.3V for power.

To use the pressure sensor module, a library must be installed in the Arduino IDE. This is easily done as the library can be installed from within the Arduino IDE without the need for a complicated manual installation.

The image below shows the pressure sensor module used in this tutorial. It contains a BMP280 sensor from Bosch that can measure both atmospheric pressure as well as temperature. Also see the GY-BMP280-3.3 pressure sensor module pinout for pin numbering and circuit diagram of the module pictured below.

GY-BMP280-3.3 Pressure Sensor Module

GY-BMP280-3.3 Pressure Sensor Module

This tutorial shows first use and testing of the GY-BMP280-3.3 pressure sensor module so that you will know whether the device is working or not. The video below shows an Arduino Due running the test sketch and displaying pressure, altitude and temperature.

Can't see the video? View on YouTube →

Connecting the GY-BMP280-3.3 Pressure Sensor Module to Arduino

Unlike some other modules that use the same BMP280 sensor, this module does not have a voltage regulator or level shifters for easy use with 5V systems. It is a 3.3V only module. The easiest way to operate it is to use it with a 3.3V Arduino such as an Arduino Due, Arduino Zero or Arduino M0.

How to wire the module to 3.3V and 5V systems is shown below with examples using an Arduino Due and Arduino Uno. The following is included:

Software SPI refers to using the Arduino SPI driver to emulate SPI hardware using "bit banging". This enables a SPI device such as the pressure sensor to be connected to any Arduino pins. Hardware SPI refers to using the actual hardware SPI device of the microcontroller chip on the Arduino. Specific Arduino pins must be used for hardware SPI.

I²C Wiring to 3.3V Arduino Due

A GY-BMP280-3.3 pressure sensor module can be used directly with a 3.3V Arduino such as an Arduino Due. The I²C wiring is as follows.

  • Module pin 1 to Arduino Due 3.3V pin
  • Module pin 2 to Arduino Due GND pin
  • Module pin 3 to Arduino Due SCL (pin 21)
  • Module pin 4 to Arduino Due SDA (pin 20)
  • Module pin 5 – not connected
  • Module pin 6 to module pin 1 (or 3.3V) – this sets the I²C address to 0x77

Below is the wiring diagram as described above.

Arduino Due GY-BMP280-3.3 Pressure Sensor Module I2C Wiring Diagram

Arduino Due GY-BMP280-3.3 Pressure Sensor Module I²C Wiring Diagram

I²C Wiring to 5V Arduino Uno

A bidirectional level shifter module can be used to connect the 3.3V GY-BMP280-3.3 module I²C pins to a 5V Arduino such as an Arduino Uno or Arduino MEGA. Power for the pressure sensor module must be taken from the Arduino 3.3V pin.

Alternatively a transistor such as a 2N7000 N-Channel MOSFET can be used to make a bidirectional level shifter as shown below.

Transistor Bidirectional Level Shifter

2N7000 Bidirectional Level Shifter

2N7000 Bidirectional Level Shifter

In the above circuit, for logic 1 levels, when 3.3V is applied to the left 3.3V_Logic pin, 5V appears on the right 5V_Logic pin. For logic 0 levels, when 0V or GND is applied to the left pin, 0V or GND appears on the right pin.

Conversely, when 5V is applied to the right pin, 3.3V appears on the left pin. When 0V or GND is applied to the right pin, 0V or GND appears on the left pin.

2N7000 Transistor Bidirectional Level Shifter for Arduino Uno I²C

A single 2N7000 transistor and one 10k resistor is required per I²C pin when connecting a 5V Arduino to the 3.3V pressure sensor module. Only one 10k resistor is needed because the module already has a 10k pull-up resistor on each I²C pin. In the above image the resistor to the left of the vertical dashed line (R1) is found on the pressure sensor module. See the GY-BMP280-3.3 pressure sensor module pinout for details of the resistors on the module.

The circuit below shows how to wire the pressure sensor module to an Arduino Uno using the I²C pins. Pinout for the 2N7000 N-Channel MOSFET in a TO-92 package is also shown.

GY-BMP280-3.3 Pressure Sensor Module Wired to Arduino Uno

GY-BMP280-3.3 Pressure Sensor Module Wired to Arduino Uno

2N7000 N-Channel MOSFET, TO-92 Package

2N7000 N-Channel MOSFET, TO-92 Package

Software SPI Wiring to 3.3V Arduino Due

SPI wiring using software SPI is as follows when using the default pins from the test sketch. Any pins can be used with software SPI, but if they are different from below, then they must be changed in the sketch to match.

  • Module pin 1 to Arduino Due 3.3V pin
  • Module pin 2 to Arduino Due GND pin
  • Module pin 3 (SCK) to Arduino Due pin 13
  • Module pin 4 (SDI) to Arduino Due pin 11
  • Module pin 5 (CSB or CS) to Arduino Due pin 10
  • Module pin 6 (SDO) to Arduino Due pin 12

Below is the wiring diagram as described above.

Arduino Due GY-BMP280-3.3 Pressure Sensor Module SPI Wiring Diagram

Arduino Due GY-BMP280-3.3 Pressure Sensor Module SPI Wiring Diagram

Hardware SPI Wiring to 3.3V Arduino Due

Hardware SPI pins are a bit awkward to connect to on the Arduino due as they are found on the SPI pins (6 pin header) found near the middle of the board and not on any of the connectors at the edge of the board. The pinout for the SPI header is shown below.

Arduino Due SPI Pins found on SPI Header

Arduino Due SPI Pins found on SPI Header

SPCK in the image is the same as SCK on the module. MISO is the same as SDO, and MOSI is the same as SDI. Any pin can be used for the chip select (CS or CSB pin on the module), but must be changed accordingly in the Arduino sketch. Refer to the GY-BMP280-3.3 pressure sensor module pinout to see which pins to connect to the Arduino Due SPI header.

SPI Wiring to 5V Arduino Uno

Again, the module must be powered from the Arduino 3.3V pin and level shifters used for the SPI pins. Either use a level shifter module, or use a transistor level shifter for each SPI line as shown in the Arduino I²C section above.

Arduino Uno hardware SPI pins are found on the ICSP header, but also on digital pins 10 to 13 as follows:

  • Arduino Uno Pin 13 – SCK connects to pressure module SCK pin
  • Arduino Uno Pin 12 – MISO connects to pressure module SDO pin
  • Arduino Uno Pin 11 – MOSI connects to pressure module SDO pin
  • Arduino Uno Pin 10 – SS connects to pressure module CSB pin

Refer to the GY-BMP280-3.3 pressure sensor module pinout for pin names and numbers of the module.

Install the BMP280 Arduino Driver

Open the Arduino IDE and use the top menu to navigate to Sketch → Include Library → Manage Libraries... which will open the Library Manager dialog box.

In the Library Manager dialog box, enter BMP280 in the filter field to find the BMP280 driver as shown in the image below.

Arduino IDE Library Manager Dialog Box

Arduino IDE Library Manager Dialog Box

Click the Adafruit BMP280 Library item and then use the install button that appears to install it. Also click the I2C-Sensor-Lib iLib item and install it for I²C communications with the BMP280 module.

Installation of the BMP280 Arduino driver is shown in the video below.

Can't see the video? View on YouTube →

Testing the Pressure Module with Arduino

When the BMP280 driver library is installed in the Arduino IDE, a test sketch is available under the Examples menu item that can be used for testing the BMP280 pressure sensor module. Find the test sketch in the Arduino IDE by selecting File → Examples → Adafruit BMP280 Library → bmp280test from the top menu.

I²C Interface Test

By default the test sketch uses the I²C interface, so no changes to the sketch are necessary. The BMP280 driver library accesses the sensor at I²C address 0x77, which is the address of the module if the wiring described above is correct.

To run the test sketch, simply load it to the Arduino and then open the Arduino IDE Serial Monitor window to see the pressure, altitude and temperature read from the sensor. Make sure that the Serial Monitor window is set to use a baud rate of 9600.

SPI Interface Test

Open the same test sketch used for the I²C above in the Arduino IDE by selecting File → Examples → Adafruit BMP280 Library → bmp280test from the top menu.

Software SPI

For software SPI, comment out the I2C line near the top of the test sketch and uncomment the line that specifies the software SPI pins as shown in the code below.

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11 
#define BMP_CS 10

//Adafruit_BMP280 bme; // I2C
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);

The default software SPI pins are defined at the top of this code. If you are using different pins, change the pin numbers here.

Hardware SPI

For hardware SPI, the pressure sensor module must be connected to the hardware SPI pins of the Arduino being used. At the top of the test sketch, comment out the I2C line and uncomment the line that specifies only the chip select line as shown in the code below.

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11 
#define BMP_CS 10

//Adafruit_BMP280 bme; // I2C
Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);

BMP_CS has a default pin number of 10 as defined near the top of this code. If you are using a different pin for SPI chip select, change it here. The other pin numbers defined at the top of this code are not used when hardware SPI is selected because hardware SPI is only found on specific Arduino pins.

Running the Test Sketch with SPI

Run the test sketch the same way as done for I2C: load it to the Arduino and then open the Arduino IDE Serial Monitor window to see the pressure, altitude and temperature read from the sensor. Make sure that the Serial Monitor window is set to use a baud rate of 9600.

Amazon.com

Amazon.co.uk

← Go back to Push Button Module









Donate to Starting Electronics



Payoneer