IoT/ESP32 B.Tech/Diploma Beginner

ESP32 with BMP388 Barometric/Altimeter Sensor (Arduino IDE)

Learn how to use BMP388 pressure sensor with the ESP32 board programmed using Arduino IDE. The BMP388 is a tiny and precise absolute barometric pressure sensor.

  • Suitable forB.Tech/Diploma IoT/ESP32 students
  • Build time1-2 weeks
  • LevelBeginner
  • Available atAjvika Labs, Kakinada

About this project

In this guide, you’ll learn how to use the BMP388 pressure sensor with the ESP32 board using Arduino IDE. The BMP388 is a tiny and precise absolute barometric pressure sensor. Because of its precision, it is often used to estimate altitude in drone applications. It can also be used in indoor/outdoor navigation, GPS applications, and others. The sensor communicates with a microcontroller using I2C or SPI communication protocols.
In this tutorial, we cover:
BMP388 Pinout
Wiring BMP388 with ESP32
Getting BMP388 Pressure, Altitude and Temperature with ESP32
ESP32 Web Server with BMP388
We have a similar tutorial for the ESP8266 board:
ESP8266 NodeMCU with BMP388 Barometric/Altimeter Sensor (Arduino)
Introducing BMP388 Barometric Sensor
The
BMP388
is a precise, low-power, low-noise absolute barometric pressure sensor that measures absolute pressure and temperature. Because pressure changes with altitude, we can also estimate altitude with great accuracy. For this reason, this sensor is handy for drone and navigation applications. You can also use it for other applications:
vertical velocity calculation;
internet of things;
weather forecast and weather stations;
health care applications;
fitness applications;
others…
We’re using the BMP388 sensor as a module, as shown in the figure below. It is also available in other different formats.
The following picture shows the other side of the sensor.
BMP388 Technical Data
The following table shows the key features of the BMP388 sensor. For more information, consult the
datasheet
Operation range
300 to 1250 hPa (pressure)
-40 to +85ºC (temperature)
Interface
I2C and SPI
Average typical current consumption
3.4 µA @ 1Hz
Absolute accuracy pressure
(typ.)
P=900 …1100 hPa (T=25 … 40°C)
±0.5 hPa
Relative accuracy pressure
(typ.)
P=900…1100 hPa (T=25 … 40°C)
±0.08 hPa
Noise in pressure
(lowest bandwidth, highest resolution)
0.03 Pa
Maximum sampling rate
200 Hz
BMP388 Pinout
Here’s the pinout of the BMP388 module we’re using—it might be slightly different for other modules.
VIN
Powers the sensor (5V)
3V3
Powers the sensor (3V3)
GND
Common GND
SCK
SCL pin for I2C communication
SCK pin for SPI communication
SDO
SDO (MISO) pin for SPI communication
SDI
SDI (MOSI) pin for SPI communication
SDA pin for I2C communication
CS
Chip select pin for SPI communication
INT
Interrupt pin
BMP388 Interface
As mentioned previously, the BMP388 sensor supports I2C and SPI interfaces.
BMP388 I2C
To use I2C communication protocol, use the following pins:
BMP388
ESP32
SDI
(SDA)
GPIO 21
SCK
(SCL)
GPIO 22
GPIO 22
(SCL) and
GPIO 21
(SDA) are the default
ESP32 I2C pins
. You can use other pins as long as you set them properly in the code.
Recommended reading:
ESP32 I2C Communication: Set Pins, Multiple Bus Interfaces and Peripherals (Arduino IDE)
BMP388 SPI
To use SPI communication protocol, use the following pins:
BMP388
ESP32
SCK
GPIO 18
SDI
(MOSI)
GPIO 23
SDO
(MISO)
GPIO 19
CS
(Chip Select)
GPIO 5
These are the default ESP32 SPI pins. You can use other pins as long as you set them properly in the code.
Parts Required
To complete this tutorial you need the following parts:
BMP388 sensor module
ESP32
(read
Best ESP32 development boards
)
Breadboard
Jumper wires
You can use the preceding links or go directly to
MakerAdvisor.com/tools
to find all the parts for your projects at the best price!
Schematic – ESP32 with BMP388
The BMP388 can communicate using I2C or SPI communication protocols.
ESP32 with BMP388 using I2C
Follow the next schematic diagram to wire the BMP388 to the ESP32 using the default I2C pins.
ESP32 with BMP388 using SPI
Alternatively, you may want to use the SPI communication protocol instead. In that case, follow the next schematic diagram to wire the BMP388 to the ESP32 using the default SPI pins.
Preparing Arduino IDE
We’ll program the ESP32 board using Arduino IDE. So, make sure you have the ESP32 add-on installed. Follow the next tutorial:
Install the ESP32 Board in Arduino IDE
If you want to use VS Code with the PlatformIO extension, follow the next tutorial instead to learn how to program the ESP32:
Getting Started with VS Code and PlatformIO IDE for ESP32 and ESP8266 (Windows, Mac OS X, Linux Ubuntu)
Installing the Adafruit BMP3XX Library
There are different libraries compatible with the BMP388 sensor and the ESP32. In this tutorial, we’ll use the
Adafruit BMP3XX library
Follow the next steps to install the library in your Arduino IDE:
Open your Arduino IDE and go to
Sketch
>
Include Library
>
Manage Libraries
. The Library Manager should open.
Search for “
adafruit bmp3xx
” in the search box and install the library.
Installing the Adafruit_Sensor Library
To use the BMP3XX library, you also need to install the
Adafruit_Sensor library
. Follow the next steps to install the library in your Arduino IDE:
Go to
Sketch
>
Include Library
>
Manage Libraries
and type “
Adafruit Unified Sensor
” in the search box. Scroll all the way down to find the library and install it.
After installing the libraries, restart your Arduino IDE.
Code – Reading BMP388 Pressure, Altitude and Temperature
The best way to get familiar with a new sensor is to start with a basic example provided by the library.
After installing the BMP3XX library, open the Arduino IDE and go to
File
>
Examples
>
Adafruit BMP3XX Library
>
bmp3XX_simpletest
. We’ve made a few changes to make it fully compatible with the ESP32.
/***************************************************************************
This is a library for the BMP3XX temperature & pressure sensor. Designed specifically to work with the Adafruit BMP388 Breakout ----> http://www.adafruit.com/products/3966
These sensors use I2C or SPI to communicate, 2 or 4 pins are required to interface. Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries. BSD license, all text above must be included in any redistribution
***************************************************************************/

// Complete project details: https://ajvikalabs.com/esp32-bmp388-arduino/

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP3XX.h"

#define BMP_SCK 18
#define BMP_MISO 19
#define BMP_MOSI 23
#define BMP_CS 5

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BMP3XX bmp;

void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("Adafruit BMP388 / BMP390 test");

if (!bmp.begin_I2C()) { // hardware I2C mode, can pass in address & alt Wire
//if (! bmp.begin_SPI(BMP_CS)) { // hardware SPI mode
//if (! bmp.begin_SPI(BMP_CS, BMP_SCK, BMP_MISO, BMP_MOSI)) { // software SPI mode
Serial.println("Could not find a valid BMP3 sensor, check wiring!");
while (1);
}

// Set up oversampling and filter initialization
bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
bmp.setOutputDataRate(BMP3_ODR_50_HZ);
}

void loop() {
if (! bmp.performReading()) {
Serial.println("Failed to perform reading :(");
return;
}
Serial.print("Temperature = ");
Serial.print(bmp.temperature);
Serial.println(" *C");

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

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

Serial.println();
delay(2000);
}
Sea Level Pressure
To get more accurate results for pressure and altitude, we recommend that you adjust the sea level pressure for your location in the
SEALEVELPRESSURE_HPA
variable:
#define SEALEVELPRESSURE_HPA (1013.25)
The standard value is 1013.25 hPa. For more accurate results, check the

Technologies used

ESP32ESP8266ArduinoBLEGPSI2CSPIArduino IDE

Hardware components

  • ESP32
  • ESP8266
  • Arduino
  • GPS

Software & tools

  • Arduino IDE
  • VS Code
  • PlatformIO
  • PlatformIO

What you get

  • Working project / hardware kit, tested before delivery
  • Complete source code with explanation
  • Project demo and guidance for your viva
  • Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed. Payment is in two parts: • 50% advance to start the project • Remaining 50% before delivery Note: • Documentation and PPT are not included by default • If you need documentation/PPT, it can be arranged for extra time and cost We'll confirm the exact timeline and cost with you after reviewing your requirements.