Embedded Systems Project: ESP32 External Sensor — BMP280

Angela Geraldine
4 min readMar 5, 2023

--

BMP280 is a digital pressure sensor that is usually used for mobile applications. Other than pressure, it can also scan temperature as well as altitude. Unlike BME280, BMP280 doesn’t have humidity sensor. Because of this difference, BMP280 is sold at a much lower price compared to the BME280.

BMP280

In this fourth embedded systems project, I will be showing how BMP280 measure temperature, pressure, and altitude. First, let’s go through the components needed for this project.

Components

For this project, we use one BMP280, breadboard, four jumper wires (male-to-male), and ESP32. As usual, we also use Arduino IDE software to run the code.

Components

Schematic

Schematic

Follow the wiring steps as shown above. As you may have noticed, the picture above shows the BMP180 and not the BMP280 that we are supposed to be using. BMP280 comes with six pins unlike BMP180 that only has four pins. You can ignore the other two pins on BMP280, meaning don’t wire them to the ESP32.

Arduino IDE Setup

Before compiling and running the code, we need to install Adafruit BMP280 library in Arduino IDE. Go to Sketch > Include Library > Manage Libraries > search Adafruit BMP280. They may ask you to install additional library such as Adafruit BusIO and Adafruit Unified Sensor. In this case, click INSTALL ALL.

install library dependencies

Code

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BMP280 bmp;
unsigned long delayTime;

void setup() {
Serial.begin(9600);
Serial.println(F("BMP280 test"));

bool status;

status = bmp.begin(0x76);
if (!status) {
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1);
}

Serial.println("-- Default Test --");
delayTime = 5000;

Serial.println();
}

void loop() {
printValues();
delay(delayTime);
}

void printValues() {
Serial.print("Temperature = ");
Serial.print(bmp.readTemperature());
Serial.println(" *C");

Serial.print("Pressure = ");
Serial.print(bmp.readPressure() / 100.0F);
Serial.println(" hPa");

Serial.print("Approx. Altitude = ");
Serial.print(bmp.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");

Serial.println();
}

This code uses the wire library to use I2C, meanwhile the Adafruit_Sensor and Adafruit_BMP280 libraries is for interface with the BMP280 sensor.

#define SEALEVELPRESSURE_HPA (1013.25)
This line of code declares the variable SEALEVELPRESSURE_HPA which is used for altitude measurement with a value of 1013.25. The value represents the pressure at the sea level in hectopascal (hPa). For more accurate results, you can replace the value with the current sea level pressure at your location.

Result

Final setup

First Trial
In the first trial, temperature and pressure readings were rather accurate, while altitude readings didn’t show any significant changes. I didn’t film the results for the first trial, so I only have screenshots from the Serial Monitor.

measurement when there is no pressure (room temperature)
measurement when there is pressure

Second Trial
In the second trial, room temperature readings were higher than before. The temperature readings got even higher when pressure was applied. This time though, pressure and altitude readings showed a significant change because I put more pressure than on the first trial.

Sensor readings when there is no pressure
Sensor readings when there is pressure
Screenshots from video above

As expected, temperature and pressure readings are higher when sensor is pressed with my finger. On the other hand, altitude gets lower. This is accurate because as air pressure rises, altitude drops.

That’s all for BMP280 project, thanks for reading \ʕ•ᴥ•ʔ/

--

--