Home Code BMP384 pressure sensor and Arduino example

BMP384 pressure sensor and Arduino example

by shedboy71

In this article we look at a temperature and pressure sensor, the BMP384 pressure sensor from Bosch Sensortec, and connect it to an Arduino Uno

Sensor Information

The BMP384 can be used for high-resolution measurements (up to 21-bit) and uses a gel-filled cavity to provide extra resistance to liquids (water and other chemicals). This makes it a great option for monitoring pressure near water or in humid environments, though the sensor is not water-proof without an adequate integration concept.

We use a Sparkfun breakout

The BMP384 provides excellent accuracy across a wide measurement range (300hPa to 1250hPa and -40 to +85°C) on an incredibly small footprint that uses the Qwiic Micro size (0.75in. x 0.30in. / 19.05mm x 7.62mm) so you can install it in projects with exceptionally tight spaces. The sensor also features a configurable oversampling setting, a FIFO buffer for storing up to 73 measurements, and a low-pass filter so users can customize the performance based on the application's requirements.

The Qwiic Pressure Sensor communicates over I2C by default, utilizing the handy Qwiic system so no soldering is required to connect it to the rest of your system.

The BMP384 has three operating modes: Sleep Mode, Normal Mode and Forced Mode. In Sleep Mode, the sensor is idle and consumes ~2µA, while in Normal Mode the sensor automatically cycles between measurement and standby periods and consumes ~700µA at peak current draw during measurements. Forced Mode allows direct control of measurements to wake the sensor from Sleep Mode, take a single-shot measurement, and return the device to Sleep Mode.

This is what the breakout looks like

Features

Take note of the supply voltage

  • Supply Voltage Range: 1.65V – 3.6V
  • Current Draw:
    • 700µA – Peak while measuring pressure
    • 3.4 µA @ 1Hz – Pressure and temperature monitoring with Ultra Low Power oversampling settings
    • ~2µA – Sleep Mode
  • Data Transfer Speeds:
    • I2C – 3.4MHz
    • SPI – 10MHz
  • I2C Address: 0x77 (Default), 0x76 (Alternate which can be set under the board by bridging 2 pads using solder)
  • Internal Temperature Sensor

Parts Required

You can connect to the sensor using DuPont-style jumper wire.

The sensor will cost in the range of $20, I did get it along with various others at a decent sale price – keep your eyes open. I got mine for under half price in the UK from Pimoroni.

Name Link
Arduino Uno UNO R3 CH340G with usb cable
BMP384 Aliexpress link
Connecting cables Male to Male + Male to Female and Female to Female Jumper Wire Dupont Cable

 

Schematic/Connection

I used 3.3v from the Arduino Uno

I also used a Qwiic cable, but if you do not have one, there is an unpopulated set of pins you can solder a header to. This is how you would wire this up

 

Code Example

I installed the Sparkfun library using the Arduino ide

Click the Manage Libraries … menu item, search for BMP384, and select the Sparkfun BMP384 library like this

This is one of the examples that gets installed with the library, with a  few comments and unused lines removed.

#include <Wire.h>
#include "SparkFunBMP384.h"

// Create a new sensor object
BMP384 pressureSensor;

// I2C address selection
uint8_t i2cAddress = BMP384_I2C_ADDRESS_DEFAULT; // 0x77
//uint8_t i2cAddress = BMP384_I2C_ADDRESS_SECONDARY; // 0x76

void setup()
{
    // Start serial
    Serial.begin(115200);
    Serial.println("BMP384 Example1 begin!");

    // Initialize the I2C library
    Wire.begin();

    // Check if sensor is connected and initialize
    // Address is optional (defaults to 0x77)
    while(pressureSensor.beginI2C(i2cAddress) != BMP3_OK)
    {
        // Not connected, inform user
        Serial.println("Error: BMP384 not connected, check wiring and I2C address!");

        // Wait a bit to see if connection is established
        delay(1000);
    }

    Serial.println("BMP384 connected!");
}

void loop()
{
    // Get measurements from the sensor
    bmp3_data data;
    int8_t err = pressureSensor.getSensorData(&data);

    // Check whether data was acquired successfully
    if(err == BMP3_OK)
    {
        // Acquisistion succeeded, print temperature and pressure
        Serial.print("Temperature (C): ");
        Serial.print(data.temperature);
        Serial.print("\t\t");
        Serial.print("Pressure (Pa): ");
        Serial.println(data.pressure);
    }
    else
    {
        // Acquisition failed, most likely a communication error (code -2)
        Serial.print("Error getting data from sensor! Error code: ");
        Serial.println(err);
    }

    // Only print every second
    delay(1000);
}

 

Output

When run you will see something like this in the serial monitor window, this was doing the typical ‘touch the sensor' test so you can see the temperature rising

Temperature (C): 22.72 Pressure (Pa): 98985.96
Temperature (C): 22.71 Pressure (Pa): 98982.92
Temperature (C): 25.31 Pressure (Pa): 98987.02
Temperature (C): 24.89 Pressure (Pa): 98971.35
Temperature (C): 26.83 Pressure (Pa): 99749.94
Temperature (C): 27.77 Pressure (Pa): 100920.69
Temperature (C): 28.25 Pressure (Pa): 101199.35
Temperature (C): 28.59 Pressure (Pa): 101513.90

Links

https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp384-ds003.pdf

Share

You may also like

Leave a Comment