Interfacing Arduino with BMP280 pressure and temperature sensor

This tutorial shows how to connect BMP280 barometric pressure and temperature sensor with Arduino UNO board. Values of the temperature and the pressure are sent to Arduino IDE serial monitor and displayed on 16×2 LCD screen.
In this project the BMP280 sensor is used in I2C mode.

The BMP280 sensor from Bosch Sensortec is a low cost pressure and temperature sensor with good accuracy. Because pressure changes with altitude we can use it as an altimeter with ±1 meter accuracy (pressure accuracy = ±1 hPa). Some parameters of the sensor are listed below:

Pressure range: 300…1100 hPa (equivalent to +9000…-500m above/below sea level)
Pressure resolution: 0.01 hPa ( < 10 cm)
Temperature range: -40…85 °C
Temperature resolution: 0.01 °C
Interface: I2C and SPI

Arduino UNO with BMP280 sensor and 1602 LCD display

Hardware Required:

  • Arduino board
  • BMP280 sensor module with 3.3V regulator and level shifter   —->  BMP280 datasheet
  • 1602 LCD screen
  • 10k ohm variable resistor or potentiometer
  • 330 ohm resistor
  • Breadboard
  • Jumper wires

The BMP280 chip works with maximum voltage of 3.6V (supply voltage range is from 1.71 to 3.6V) which means we’ve to use a 3V3 voltage regulator to supply it from a 5V source.
Also if we’re working with a 5V system (development board, microcontroller …) like the Arduino UNO board we’ve to use a voltage level shifter (level converter) which converts the 3.3V (comes from the BMP280 chip) into 5V (goes to the Arduino) and vice versa. This level shifter is for the I2C bus lines (clock and data).

Some BMP280 modules come with 3V3 voltage regulator and level shifter like the one provided by Adafruit Industries which is shown below.
A module like this can be used with 3.3V or 5V system without any problem.

Ardafruit BMP280 sensor breakout board

In this example I’m going to use a Chinese BMP280 module came with 3.3V regulator and level shifter, this mans connection will be more easier!

Interfacing Arduino with BMP280 sensor circuit:
Project circuit diagram is shown below.

Arduino BMP280 sensor 16x2 LCD circuit

Note that the BMP280 module shown in the circuit diagram has a 3.3V regulator and level shifter.

Generally, the BMP280 module has at least 4 pins because it can work in SPI mode or I2C mode. For the I2C mode we need 4 pins: VCC, GND, SDA and SCL where:
GND (ground) is connected to Arduino GND pin
VCC is the supply pin which is connected to Arduino 5V pin
SDA is I2C bus serial data line, connected to Arduino analog pin 4 (A4)
SCL is I2C bus serial clock line, connected to Arduino analog pin 5 (A5).

The 1602 LCD screen is used to display temperature and pressure values where:
RS —> Arduino digital pin 2
E  —> Arduino digital pin 3
D4 —> Arduino digital pin 4
D5 —> Arduino digital pin 5
D6 —> Arduino digital pin 6
D7 —> Arduino digital pin 7
VSS, RW, D0, D1, D2, D3 and K are connected to Arduino GND (ground)
VEE to the variable resistor (or potentiometer) output
VDD to Arduino 5V and A to Arduino 5V through 330 ohm resistor

VEE pin is used to control the contrast of the LCD. A (anode) and K (cathode) are the back light LED pins.

Interfacing Arduino with BMP280 sensor code:
To simplify the code of this project I used a library for the BMP280 sensor provided by Adafruit Industries. This library can be installed from Arduino IDE library manager (Arduino IDE —> Sketch —> Include Library —> Manage Libraries…). In the dialog box write adafruit bmp280 and install the library as shown in the image below:

Arduino install BMP280 library

or it can be downloaded and installed manually, download link is below:
Adafruit BMP280 Library   —-    direct link

You may need to install the Adafruit Unified Sensor library if it’s not already installed, download link is below:
Adafruit Unified Sensor library   —-    direct link

As any other I2C device, the BMP280 sensor has an I2C slave address which is 0x76 or 0x77. This address depends on the connection of the SDO pin (used for SPI mode as serial data out or MISO), if the SDO pin is connected (directly or through resistor) to VCC (3.3V) the address will be 0x77, and if it’s connected to GND the address will be 0x76.

The default I2C address of the library is defined as 0x77 and my device I2C address is 0x76.
In the code the definition of the I2C slave address is as shown below:

The initialization of the BMP280 sensor is done using the function begin() which returns 1 if OK and 0 if error. In the code the initialization with the previously defined address is as shown below:

Reading the values of temperature, pressure and altitude is done as shown below:

Since we know the pressure, we can calculate the altitude but we’ve to know the pressure of the sea level of our location. In the code I put 1013.25 hPa. Here the idea is just to know the height of a point with respect to another one!

Temperature and pressure values are displayed on 16×2 LCD screen and they are sent with approximating altitude to Arduino IDE serial monitor.

Note that 1 bar = 10000 Pa = 100 hPa. ( 1 hPa = 100 Pa)
Pa: Pascal
hPa: hectoPascal

Full Arduino Code:

Serial monitor result is shown below:

Arduino BMP280 sensor result

Related project:
Arduino with BME280 pressure, temperature and humidity sensor

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.