Skip to main content
ESPBoards

ESP32 BMP388 / CJMCU-388 Barometric Pressure Sensor

The BMP388 is a high-precision digital barometric pressure and temperature sensor, offering enhanced accuracy and stability. It supports both I²C and SPI communication, making it ideal for weather monitoring, altitude measurement, and UAV applications.

⬇️ Jump to Code Examples

Arduino Core Image
ESP-IDF Image
ESPHome Image
PlatformIO Image

🔗 Quick Links

BMP388 / CJMCU-388 Barometric Pressure Sensor Datasheet ButtonBMP388 / CJMCU-388 Barometric Pressure Sensor Specs ButtonBMP388 / CJMCU-388 Barometric Pressure Sensor Specs ButtonBMP388 / CJMCU-388 Barometric Pressure Sensor Specs Button

ℹ️ About BMP388 / CJMCU-388 Barometric Pressure Sensor

The BMP388, developed by Bosch Sensortec, is a next-generation barometric pressure and temperature sensor with higher accuracy, lower noise, and improved temperature stability. It outperforms its predecessors, including the BMP180 and BMP280, making it ideal for weather monitoring, altimetry, and drone altitude control.

Key Features #

  • Superior Accuracy & Low Noise – More precise and stable than BMP180 and BMP280.
  • Wide Pressure Range – Ideal for altitude tracking, drones, and GPS applications.
  • Integrated Temperature Sensor – Enhances environmental monitoring and altitude calculations.
  • I²C & SPI Communication – Flexible connectivity with ESP32, Arduino, and other microcontrollers.

With its high precision and stability, the BMP388 is a top choice for advanced altitude and weather-based applications. 🚀

⚙️ BMP388 Sensor Technical Specifications

Below you can see the BMP388 / CJMCU-388 Barometric Pressure Sensor Technical Specifications. The sensor is compatible with the ESP32, operating within a voltage range suitable for microcontrollers. For precise details about its features, specifications, and usage, refer to the sensor’s datasheet.

  • Protocol: I2C/SPI
  • Interface: I²C (up to 3.4 MHz) / SPI (up to 10 MHz)
  • Pressure Range: 300 hPa to 1250 hPa
  • Temperature Range: -40°C to +85°C
  • Operating Voltage: 1.65V to 3.6V
  • Resolution: 0.03 hPa
  • Accuracy: ±0.08 hPa
  • Power Consumption: 3.4 µA at 1 Hz
  • Output: Temperature and Pressure (Digital)
  • Package Dimensions: 2.0 mm × 2.0 mm × 0.75 mm
  • Weight: 0.5 g

🔌 BMP388 Sensor Pinout

Below you can see the pinout for the BMP388 / CJMCU-388 Barometric Pressure Sensor. The VCC pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND pin is the ground connection and must be connected to the ground of your ESP32!

The BMP388 module has the following pins: VCC: Power supply (3.3V). GND: Ground pin. SDA: Serial Data pin for I²C communication. SCL: Serial Clock pin for I²C communication. CS: Chip Select for SPI communication (connect to GND for I²C mode). SDO: Serial Data Out for SPI communication (optional in I²C mode).

🧵 BMP388 Wiring with ESP32

Below you can see the wiring for the BMP388 / CJMCU-388 Barometric Pressure Sensor with the ESP32. Connect the VCC pin of the sensor to the 3.3V pin on the ESP32 or external power supply for power and the GND pin of the sensor to the GND pin of the ESP32. Depending on the communication protocol of the sensor (e.g., I2C, SPI, UART, or analog), connect the appropriate data and clock or signal pins to compatible GPIO pins on the ESP32, as shown below in the wiring diagram.

To interface the BMP388 module with an ESP32 using I²C: VCC: Connect to 3.3V on ESP32. GND: Connect to GND on ESP32. SDA: Connect to GPIO21 (default SDA). SCL: Connect to GPIO22 (default SCL). CS: Connect to GND to select I²C mode.

🛠️ BMP388 / CJMCU-388 Barometric Pressure Sensor Troubleshooting

This guide outlines a systematic approach to troubleshoot and resolve common problems with the . Start by confirming that the hardware connections are correct, as wiring mistakes are the most frequent cause of issues. If you are sure the connections are correct, follow the below steps to debug common issues.

💻 Library Not Found Error

Issue: The Arduino IDE cannot find the required BMP388 library.

Solution: Ensure that you have installed the Adafruit BMP3XX library from the Arduino Library Manager. Restart the Arduino IDE after installation.

❌ Sensor Initialization Failure

Issue: The BMP388 sensor fails to initialize, and the error message Could not find a valid BMP388 sensor appears.

Solution: Check the wiring connections and ensure the sensor receives 3.3V power. Use an I²C scanner to detect the sensor's address.

⚠️ Incorrect Pressure Readings

Issue: The sensor outputs incorrect pressure values, leading to inaccurate altitude measurements.

Solution: Verify that the reference sea-level pressure value is set correctly and recalibrate the sensor if needed.

💻 Code Examples

Below you can find code examples of BMP388 / CJMCU-388 Barometric Pressure Sensor with ESP32 in several frameworks:

If you encounter issues while using the BMP388 / CJMCU-388 Barometric Pressure Sensor, check the Common Issues Troubleshooting Guide.

Arduino Core Image

ESP32 BMP388 Arduino IDE Code Example

Example in Arduino IDE

Fill in your main Arduino IDE sketch file with the following code to use the BMP388 / CJMCU-388 Barometric Pressure Sensor:

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

Adafruit_BMP3XX bmp;

void setup() {
Serial.begin(115200);
if (!bmp.begin(0x76)) {
Serial.println("Could not find a valid BMP388 sensor, check wiring!");
while (1);
}
}

void loop() {
Serial.print("Temperature: ");
Serial.print(bmp.temperature);
Serial.println(" *C");

Serial.print("Pressure: ");
Serial.print(bmp.pressure / 100.0);
Serial.println(" hPa");
delay(2000);
}

This Arduino code initializes the BMP388 sensor using the Adafruit BMP3XX library. It reads temperature and pressure values and prints them to the Serial Monitor every two seconds.

Connect your ESP32 to your computer via a USB cable, Ensure the correct Board and Port are selected under Tools, Click the "Upload" button in the Arduino IDE to compile and upload the code to your ESP32.

ESP-IDF Image

ESP32 BMP388 ESP-IDF Code Example
Example in Espressif IoT Framework (ESP-IDF)

If you're using ESP-IDF to work with the BMP388 / CJMCU-388 Barometric Pressure Sensor, here's how you can set it up and read data from the sensor. Fill in this code in the main ESP-IDF file:

#include "bmp388.h"
#include "esp_log.h"

#define I2C_MASTER_SCL_IO 22
#define I2C_MASTER_SDA_IO 21
#define I2C_MASTER_FREQ_HZ 100000
#define BMP388_ADDR 0x76

static const char *TAG = "BMP388";

void app_main() {
ESP_LOGI(TAG, "Initializing BMP388...");
bmp388_dev dev;
bmp388_init(&dev, I2C_MASTER_SCL_IO, I2C_MASTER_SDA_IO, I2C_MASTER_FREQ_HZ, BMP388_ADDR);

while (1) {
bmp388_data data;
bmp388_read(&dev, &data);
ESP_LOGI(TAG, "Temperature: %.2f°C", data.temperature);
ESP_LOGI(TAG, "Pressure: %.2f hPa", data.pressure);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}

This ESP-IDF code configures the ESP32 to interface with the BMP388 sensor over I²C. The bmp388_init function initializes the sensor, and bmp388_read fetches pressure and temperature readings.

Update the I2C pins (I2C_MASTER_SDA_IO and I2C_MASTER_SCL_IO) to match your ESP32 hardware setup, Use idf.py build to compile the project, Use idf.py flash to upload the code to your ESP32.

ESPHome Image

ESP32 BMP388 ESPHome Code Example

Example in ESPHome (Home Assistant)

Fill in this configuration in your ESPHome YAML configuration file (example.yml) to integrate the BMP388 / CJMCU-388 Barometric Pressure Sensor

sensor:
- platform: bmp388
temperature:
name: "BMP388 Temperature"
pressure:
name: "BMP388 Pressure"
address: 0x76

This ESPHome configuration enables the BMP388 sensor to provide temperature and pressure readings over I²C, using the default address 0x76.

Upload this code to your ESP32 using the ESPHome dashboard or the esphome run command.

PlatformIO Image

ESP32 BMP388 PlatformIO Code Example

Example in PlatformIO Framework

For PlatformIO, make sure to configure the platformio.ini file with the appropriate environment and libraries, and then proceed with the code.

Configure platformio.ini

First, your platformio.ini should look like below. You might need to include some libraries as shown. Make sure to change the board to your ESP32:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/Adafruit BMP3XX Library
wire
monitor_speed = 115200

ESP32 BMP388 PlatformIO Example Code

Write this code in your PlatformIO project under the src/main.cpp file to use the BMP388 / CJMCU-388 Barometric Pressure Sensor:

#include <Wire.h>
#include <Adafruit_BMP3XX.h>

Adafruit_BMP3XX bmp;

void setup() {
Serial.begin(115200);
if (!bmp.begin(0x76)) {
Serial.println("Could not find a valid BMP388 sensor, check wiring!");
while (1);
}
}

void loop() {
Serial.print("Temperature: ");
Serial.print(bmp.temperature);
Serial.println(" *C");

Serial.print("Pressure: ");
Serial.print(bmp.pressure / 100.0);
Serial.println(" hPa");
delay(2000);
}

This PlatformIO code integrates the BMP388 sensor to read temperature and pressure values, printing them every two seconds.

Upload the code to your ESP32 using the PlatformIO "Upload" button in your IDE or the pio run --target upload command.

Conclusion

We went through technical specifications of BMP388 / CJMCU-388 Barometric Pressure Sensor, its pinout, connection with ESP32 and BMP388 / CJMCU-388 Barometric Pressure Sensor code examples with Arduino IDE, ESP-IDF, ESPHome and PlatformIO.