{"id":104357,"date":"2021-07-08T10:49:30","date_gmt":"2021-07-08T10:49:30","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=104357"},"modified":"2021-10-07T13:14:04","modified_gmt":"2021-10-07T13:14:04","slug":"arduino-bmp388","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/arduino-bmp388\/","title":{"rendered":"Guide for BMP388 Altimeter with Arduino (Pressure, Altitude, Temperature)"},"content":{"rendered":"\n<p>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. In this tutorial, you&#8217;ll learn how to use the BMP388 altimeter\/pressure sensor with the Arduino board\u2014wiring diagram and example sketch.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-with-BMP388-Barometric-Altimeter-Sensor-Guide.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Guide for BMP388 Altimeter with Arduino Pressure Altitude Temperature\" class=\"wp-image-104368\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-with-BMP388-Barometric-Altimeter-Sensor-Guide.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-with-BMP388-Barometric-Altimeter-Sensor-Guide.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-with-BMP388-Barometric-Altimeter-Sensor-Guide.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-with-BMP388-Barometric-Altimeter-Sensor-Guide.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<p>In this tutorial, we cover:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#pinout\">BMP388 Pinout<\/a><\/li><li><a href=\"#wiring\">Wiring BMP388 with Arduino<\/a><\/li><li><a href=\"#basic-example\">Getting BMP388 Pressure, Altitude and Temperature with Arduino<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Introducing BMP388 Barometric Sensor<\/h2>\n\n\n\n<p>The <a href=\"https:\/\/makeradvisor.com\/tools\/bmp388-sensor-module\/\" target=\"_blank\" rel=\"noreferrer noopener\">BMP388<\/a> 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:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>vertical velocity calculation;<\/li><li>internet of things;<\/li><li>weather forecast and weather stations;<\/li><li>health care applications;<\/li><li>fitness applications;<\/li><li>others&#8230;<\/li><\/ul>\n\n\n\n<p>We&#8217;re using the BMP388 sensor as a module, as shown in the figure below. It is also available in other different formats.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Front-Back-Pins-BMP388-Sensor-Module-Altitude-Pressure-Temperature.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Front Pins BMP388 Sensor Module Altitude Pressure Temperature\" class=\"wp-image-104327\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Front-Back-Pins-BMP388-Sensor-Module-Altitude-Pressure-Temperature.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Front-Back-Pins-BMP388-Sensor-Module-Altitude-Pressure-Temperature.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>The following picture shows the other side of the sensor.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Part-Back-Pins-BMP388-Sensor-Module-Altitude-Pressure-Temperature.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Part Back Pins BMP388 Sensor Module Altitude Pressure Temperature\" class=\"wp-image-104328\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Part-Back-Pins-BMP388-Sensor-Module-Altitude-Pressure-Temperature.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Part-Back-Pins-BMP388-Sensor-Module-Altitude-Pressure-Temperature.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">BMP388 Technical Data<\/h3>\n\n\n\n<p>The following table shows the key features of the BMP388 sensor. For more information, consult the <a href=\"https:\/\/www.bosch-sensortec.com\/products\/environmental-sensors\/pressure-sensors\/bmp388\/\" target=\"_blank\" rel=\"noreferrer noopener\">datasheet<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Operation range<\/strong><\/td><td>300 to 1250 hPa (pressure)<br>-40 to +85\u00baC (temperature)<\/td><\/tr><tr><td><strong>Interface<\/strong><\/td><td>I2C and SPI<\/td><\/tr><tr><td><strong>Average typical current consumption<\/strong><\/td><td>3.4 \u00b5A @ 1Hz<\/td><\/tr><tr><td><strong>Absolute accuracy pressure<\/strong> (typ.)<br>P=900 \u20261100 hPa (T=25 \u2026 40\u00b0C)<\/td><td>\u00b10.5 hPa<\/td><\/tr><tr><td><strong>Relative accuracy pressure<\/strong> (typ.)<br>P=900\u20261100 hPa (T=25 \u2026 40\u00b0C)<\/td><td>\u00b10.08 hPa<\/td><\/tr><tr><td><strong>Noise in pressure<\/strong> (lowest bandwidth, highest resolution)<\/td><td>0.03 Pa<\/td><\/tr><tr><td><strong>Maximum sampling rate<\/strong><\/td><td>200 Hz<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"pinout\">BMP388 Pinout<\/h2>\n\n\n\n<p>Here&#8217;s the pinout of the BMP388 module we&#8217;re using\u2014it might be slightly different for other modules.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>VIN<\/td><td>Powers the sensor (5V)<\/td><\/tr><tr><td>3V3<\/td><td>Powers the sensor (3V3)<\/td><\/tr><tr><td>GND<\/td><td>Common GND<\/td><\/tr><tr><td>SCK<\/td><td>SCL pin for I2C communication<br>SCK pin for SPI communication<\/td><\/tr><tr><td>SDO<\/td><td>SDO (MISO) pin for SPI communication<\/td><\/tr><tr><td>SDI<\/td><td>SDI (MOSI) pin for SPI communication<br>SDA pin for I2C communication<\/td><\/tr><tr><td>CS<\/td><td>Chip select pin for SPI communication<\/td><\/tr><tr><td>INT<\/td><td>Interrupt pin<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">BMP388 Interface<\/h2>\n\n\n\n<p>As mentioned previously, the BMP388 sensor supports I2C and SPI interfaces.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-Board-BMP388-Sensor-Altitude-Pressure-Temperature-Parts-Required.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino UNO Board BMP388 Sensor Module Altitude Pressure Temperature Parts Required\" class=\"wp-image-104362\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-Board-BMP388-Sensor-Altitude-Pressure-Temperature-Parts-Required.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-Board-BMP388-Sensor-Altitude-Pressure-Temperature-Parts-Required.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p><strong>BMP388 I2C<\/strong><\/p>\n\n\n\n<p>To use I2C communication protocol, use the following pins (for the Arduino Uno\u2014if you&#8217;re using another model, check its I2C pins):<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BMP388<\/strong><\/td><td><strong>Arduino<\/strong><\/td><\/tr><tr><td><strong>SDI<\/strong> (SDA)<\/td><td>A4<\/td><\/tr><tr><td><strong>SCK<\/strong> (SCL)<\/td><td>A5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">BMP388 SPI<\/h4>\n\n\n\n<p>To use SPI communication protocol, use the following pins (for the Arduino Uno\u2014if you&#8217;re using another model, check its SPI pins):<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BMP388<\/strong><\/td><td><strong>Arduino<\/strong><\/td><\/tr><tr><td><strong>SCK<\/strong><\/td><td><span class=\"rnthl rntclblue\">Pin 13<\/span><\/td><\/tr><tr><td><strong>SDI <\/strong>(MOSI)<\/td><td><span class=\"rnthl rntcgreen\">Pin 11<\/span><\/td><\/tr><tr><td><strong>SDO <\/strong>(MISO)<\/td><td><span class=\"rnthl rntcyellow\">Pin 12<\/span><\/td><\/tr><tr><td><strong>CS <\/strong>(Chip Select)<\/td><td><span class=\"rnthl rntclgray\">Pin 10<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Parts Required<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-Board-BMP388-Module-Sensor-Altitude-Pressure-Temperature.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino UNO Board BMP388 Sensor Module Altitude Pressure Temperature Parts Demonstration\" class=\"wp-image-104361\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-Board-BMP388-Module-Sensor-Altitude-Pressure-Temperature.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-Board-BMP388-Module-Sensor-Altitude-Pressure-Temperature.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>To complete this tutorial you need the following parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/makeradvisor.com\/tools\/bmp388-sensor-module\/\" target=\"_blank\" rel=\"noreferrer noopener\">BMP388 sensor module<\/a><\/li><li><a href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\" rel=\"noreferrer noopener\">Arduino board<\/a> (read&nbsp;<a href=\"https:\/\/makeradvisor.com\/best-arduino-starter-kits\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best Arduino Starter Kits<\/a>)<\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\">Breadboard<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\">Jumper wires<\/a><\/li><\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"wiring\">Schematic &#8211; Arduino with BMP388<\/h2>\n\n\n\n<p>The BMP388 can communicate using I2C or SPI communication protocols.<\/p>\n\n\n\n<p><strong>Arduino with BMP388 using I2C<\/strong><\/p>\n\n\n\n<p>Follow the next schematic diagram to wire the BMP388 to the Arduino Uno using the I2C pins.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"619\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-BMP388-I2C-Wiring-Diagram.png?resize=750%2C619&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino with BMP388 Altimeter Pressure Sensor Wiring Circuit Diagram I2C\" class=\"wp-image-104364\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-BMP388-I2C-Wiring-Diagram.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-BMP388-I2C-Wiring-Diagram.png?resize=300%2C248&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p><strong>Arduino with BMP388 using SPI<\/strong><\/p>\n\n\n\n<p>Alternatively, if you want to use the SPI communication protocol, follow the next schematic diagram to wire the BMP388 to the Arduino Uno using the SPI pins.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"569\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-BMP388-SPI-Wiring-Diagram.png?resize=750%2C569&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino with BMP388 Altimeter Pressure Sensor Wiring Circuit Diagram SPI\" class=\"wp-image-104365\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-BMP388-SPI-Wiring-Diagram.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-BMP388-SPI-Wiring-Diagram.png?resize=300%2C228&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Installing the Adafruit BMP3XX Library<\/h2>\n\n\n\n<p>There are different libraries compatible with the BMP388 sensor and the Arduino. In this tutorial, we&#8217;ll use the <a href=\"https:\/\/github.com\/adafruit\/Adafruit_BMP3XX\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit BMP3XX library<\/a>.<\/p>\n\n\n\n<p>Follow the next steps to install the library in your Arduino IDE:<\/p>\n\n\n\n<p>Open your Arduino IDE and go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&nbsp;&gt;&nbsp;<strong>Manage Libraries<\/strong>. The Library Manager should open.<\/p>\n\n\n\n<p>Search for \u201c<strong>adafruit bmp3xx<\/strong>&nbsp;\u201d in the search box and install the library.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"443\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/Install-adafruit-bmp3xx-arduino-IDE.png?resize=786%2C443&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Install Adafruit bmp3xx library Arduino IDE\" class=\"wp-image-103858\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/Install-adafruit-bmp3xx-arduino-IDE.png?w=786&amp;quality=100&amp;strip=all&amp;ssl=1 786w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/Install-adafruit-bmp3xx-arduino-IDE.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/Install-adafruit-bmp3xx-arduino-IDE.png?resize=768%2C433&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Installing the Adafruit_Sensor Library<\/h3>\n\n\n\n<p>To use the BMP3XX library, you also need to install the&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\" target=\"_blank\">Adafruit_Sensor library<\/a>. Follow the next steps to install the library in your Arduino IDE:<\/p>\n\n\n\n<p>Go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&nbsp;&gt;&nbsp;<strong>Manage Libraries<\/strong>&nbsp;and type \u201c<strong>Adafruit Unified Sensor<\/strong>\u201d in the search box. Scroll all the way down to find the library and install it.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/adafruit_unified_sensor_library.png?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Installing Adafruit Unified Sensor Driver library\" class=\"wp-image-84295\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/adafruit_unified_sensor_library.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/adafruit_unified_sensor_library.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>After installing the libraries, restart your Arduino IDE.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"basic-example\">Code &#8211; Reading BMP388 Pressure, Altitude and Temperature<\/h2>\n\n\n\n<p>The best way to get familiar with a new sensor is to start with a basic example provided by the library.<\/p>\n\n\n\n<p>After installing the BMP3XX library, open the Arduino IDE and go to&nbsp;<strong>File<\/strong>&nbsp;&gt;&nbsp;<strong>Examples<\/strong>&nbsp;&gt;&nbsp;<strong>Adafruit BMP3XX Library<\/strong>&nbsp;&gt;&nbsp;<strong>bmp3XX_simpletest<\/strong>. The following code should load.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/***************************************************************************\n  This is a library for the BMP3XX temperature &amp; pressure sensor. Designed specifically to work with the Adafruit BMP388 Breakout ----&gt; http:\/\/www.adafruit.com\/products\/3966\n  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!\n  Written by Limor Fried &amp; Kevin Townsend for Adafruit Industries. BSD license, all text above must be included in any redistribution\n ***************************************************************************\/\n\n\/\/ Complete project details: https:\/\/RandomNerdTutorials.com\/arduino-bmp388\/\n\n\n#include &lt;Wire.h&gt;\n#include &lt;SPI.h&gt;\n#include &lt;Adafruit_Sensor.h&gt;\n#include &quot;Adafruit_BMP3XX.h&quot;\n\n#define BMP_SCK 13\n#define BMP_MISO 12\n#define BMP_MOSI 11\n#define BMP_CS 10\n\n#define SEALEVELPRESSURE_HPA (1013.25)\n\nAdafruit_BMP3XX bmp;\n\nvoid setup() {\n  Serial.begin(115200);\n  while (!Serial);\n  Serial.println(&quot;Adafruit BMP388 \/ BMP390 test&quot;);\n\n  if (!bmp.begin_I2C()) {   \/\/ hardware I2C mode, can pass in address &amp; alt Wire\n  \/\/if (! bmp.begin_SPI(BMP_CS)) {  \/\/ hardware SPI mode  \n  \/\/if (! bmp.begin_SPI(BMP_CS, BMP_SCK, BMP_MISO, BMP_MOSI)) {  \/\/ software SPI mode\n    Serial.println(&quot;Could not find a valid BMP3 sensor, check wiring!&quot;);\n    while (1);\n  }\n\n  \/\/ Set up oversampling and filter initialization\n  bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);\n  bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);\n  bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);\n  bmp.setOutputDataRate(BMP3_ODR_50_HZ);\n}\n\nvoid loop() {\n  if (! bmp.performReading()) {\n    Serial.println(&quot;Failed to perform reading :(&quot;);\n    return;\n  }\n  Serial.print(&quot;Temperature = &quot;);\n  Serial.print(bmp.temperature);\n  Serial.println(&quot; *C&quot;);\n\n  Serial.print(&quot;Pressure = &quot;);\n  Serial.print(bmp.pressure \/ 100.0);\n  Serial.println(&quot; hPa&quot;);\n\n  Serial.print(&quot;Approx. Altitude = &quot;);\n  Serial.print(bmp.readAltitude(SEALEVELPRESSURE_HPA));\n  Serial.println(&quot; m&quot;);\n\n  Serial.println();\n  delay(2000);\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Arduino\/bmp3xx_simpletest_Arduino.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sea Level Pressure<\/h3>\n\n\n\n<p>To get more accurate results for pressure and altitude, we recommend that you adjust the sea level pressure for your location in the <span class=\"rnthl rntliteral\">SEALEVELPRESSURE_HPA<\/span> variable:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define SEALEVELPRESSURE_HPA (1013.25)<\/code><\/pre>\n\n\n\n<p>The standard value is 1013.25 hPa. For more accurate results, check the sea level pressure at your location. You can use this website to check <a href=\"https:\/\/meteologix.com\/observations\/pressure-qnh.html\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"https:\/\/meteologix.com\/xx\/observations\/portugal\/pressure-qnh\/20210512-1000z.html\">sea level pressure<\/a>. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Code Works<\/h2>\n\n\n\n<p>Continue reading this section to learn how the code works, or skip to the <a href=\"#demonstration\">Demonstration <\/a>section.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Libraries<\/h3>\n\n\n\n<p>The code starts by including the needed libraries: the <span class=\"rnthl rntliteral\">Wire<\/span> library to use I2C, the <span class=\"rnthl rntliteral\">SPI<\/span> library (if you want to use SPI instead of I2C), the <span class=\"rnthl rntliteral\">Adafruit_Sensor,<\/span> and <span class=\"rnthl rntliteral\">Adafruit_BMP3XX<\/span> libraries to interface with the BMP388 sensor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;Wire.h&gt;\n#include &lt;SPI.h&gt;\n#include &lt;Adafruit_Sensor.h&gt;\n#include \"Adafruit_BMP3XX.h\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">SPI communication<\/h3>\n\n\n\n<p>We prefer to use the I2C communication protocol with the sensor. However, the code is prepared if you want to use SPI. The following lines of code define the SPI pins.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define BMP_SCK 13\n#define BMP_MISO 12\n#define BMP_MOSI 11\n#define BMP_CS 10<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Sea level pressure<\/h3>\n\n\n\n<p>A variable called <span class=\"rnthl rntliteral\">SEALEVELPRESSURE_HPA<\/span> is created.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define SEALEVELPRESSURE_HPA (1013.25)<\/code><\/pre>\n\n\n\n<p>This variable saves the pressure at the sea level in hectopascal (is equivalent to milibar). This variable is used to estimate the altitude for a given pressure by comparing it with the sea level pressure. This example uses the default value, but for accurate results, replace the value with the current sea level pressure at your location. You can use this website to check <a href=\"https:\/\/meteologix.com\/observations\/pressure-qnh.html\" target=\"_blank\" rel=\"noreferrer noopener\">sea level pressure<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">setup()<\/h3>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span> start a serial communication.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Init BMP388 Sensor I2C<\/h4>\n\n\n\n<p>This example uses I2C communication protocol by default. The following line starts an <span class=\"rnthl rntliteral\">Adafruit_BMP3XX<\/span> object called <span class=\"rnthl rntliteral\">bmp<\/span> on the I2C pins: <span class=\"rnthl rntcyellow\">A5<\/span> (SCL), <span class=\"rnthl rntclgray\">A4<\/span> (SDA).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (!bmp.begin_I2C()) {   \/\/ hardware I2C mode, can pass in address &amp; alt Wire<\/code><\/pre>\n\n\n\n<p>To use SPI, you need to comment this previous line and uncomment one of the following lines for hardware SPI (use the default SPI pins and choose the CS pin) or software SPI (use any pins).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/if (! bmp.begin_SPI(BMP_CS)) {  \/\/ hardware SPI mode  \n\/\/if (! bmp.begin_SPI(BMP_CS, BMP_SCK, BMP_MISO, BMP_MOSI)) {  \/\/ software SPI mode<\/code><\/pre>\n\n\n\n<p>Set up the following parameters (oversampling and filter) for the sensor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Set up oversampling and filter initialization\nbmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);\nbmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);\nbmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);\nbmp.setOutputDataRate(BMP3_ODR_50_HZ);<\/code><\/pre>\n\n\n\n<p>To increase the resolution of the raw sensor data, it supports oversampling. We&#8217;ll use the default oversampling parameters, but you can change them.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><span class=\"rnthl rntliteral\">setTemperatureOversampling()<\/span>: set temperature oversampling.<\/li><li><span class=\"rnthl rntliteral\">setPressureOversampling()<\/span>: set pressure oversampling.<\/li><\/ul>\n\n\n\n<p>These methods can accepts one of the following parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><span class=\"rnthl rntliteral\">BMP3_NO_OVERSAMPLING<\/span><\/li><li><span class=\"rnthl rntliteral\">BMP3_OVERSAMPLING_2X<\/span><\/li><li><span class=\"rnthl rntliteral\">BMP3_OVERSAMPLING_4X<\/span><\/li><li><span class=\"rnthl rntliteral\">BMP3_OVERSAMPLING_8X<\/span><\/li><li><span class=\"rnthl rntliteral\">BMP3_OVERSAMPLING_16X<\/span><\/li><li><span class=\"rnthl rntliteral\">BMP3_OVERSAMPLING_32X<\/span><\/li><\/ul>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">setIIRFilterCoeff()<\/span> function sets the coefficient of the filter (in samples). It can be:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><span class=\"rnthl rntliteral\">BMP3_IIR_FILTER_DISABLE<\/span> (no filtering)<\/li><li><span class=\"rnthl rntliteral\">BMP3_IIR_FILTER_COEFF_1<\/span><\/li><li><span class=\"rnthl rntliteral\">BMP3_IIR_FILTER_COEFF_3<\/span><\/li><li><span class=\"rnthl rntliteral\">BMP3_IIR_FILTER_COEFF_7<\/span><\/li><li><span class=\"rnthl rntliteral\">BMP3_IIR_FILTER_COEFF_15<\/span><\/li><li><span class=\"rnthl rntliteral\">BMP3_IIR_FILTER_COEFF_31<\/span><\/li><li><span class=\"rnthl rntliteral\">BMP3_IIR_FILTER_COEFF_63<\/span><\/li><li><span class=\"rnthl rntliteral\">BMP3_IIR_FILTER_COEFF_127<\/span><\/li><\/ul>\n\n\n\n<p>Set the output data rate with the <span class=\"rnthl rntliteral\">setOutputDataRate()<\/span> function. It can accept one of the following options:<\/p>\n\n\n\n<p><span class=\"rnthl rntliteral\">BMP3_ODR_200_HZ<\/span>, <span class=\"rnthl rntliteral\">BMP3_ODR_100_HZ<\/span>, <span class=\"rnthl rntliteral\">BMP3_ODR_50_HZ<\/span>, <span class=\"rnthl rntliteral\">BMP3_ODR_25_HZ<\/span>,<span class=\"rnthl rntliteral\">BMP3_ODR_12_5_HZ<\/span>, <span class=\"rnthl rntliteral\">BMP3_ODR_6_25_HZ<\/span>, <span class=\"rnthl rntliteral\">BMP3_ODR_3_1_HZ<\/span>, <span class=\"rnthl rntliteral\">BMP3_ODR_1_5_HZ<\/span>, <span class=\"rnthl rntliteral\">BMP3_ODR_0_78_HZ<\/span>, <span class=\"rnthl rntliteral\">BMP3_ODR_0_39_HZ<\/span>,<span class=\"rnthl rntliteral\">BMP3_ODR_0_2_HZ<\/span>, <span class=\"rnthl rntliteral\">BMP3_ODR_0_1_HZ<\/span>, <span class=\"rnthl rntliteral\">BMP3_ODR_0_05_HZ<\/span>, <span class=\"rnthl rntliteral\">BMP3_ODR_0_02_HZ<\/span>, <span class=\"rnthl rntliteral\">BMP3_ODR_0_01_HZ<\/span>, <span class=\"rnthl rntliteral\">BMP3_ODR_0_006_HZ<\/span>, <span class=\"rnthl rntliteral\">BMP3_ODR_0_003_HZ<\/span>, or <span class=\"rnthl rntliteral\">BMP3_ODR_0_001_HZ<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">loop()<\/h3>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, we&#8217;ll get measurements from the BMP388 sensor.<\/p>\n\n\n\n<p>First, tell the sensor to get new readings with <span class=\"rnthl rntliteral\">bmp.performReading()<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (! bmp.performReading()) {\n  Serial.println(\"Failed to perform reading :(\");\n  return;\n}<\/code><\/pre>\n\n\n\n<p>Then, get and print the temperature, pressure and altitude readings as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.print(\"Temperature = \");\nSerial.print(bmp.temperature);\nSerial.println(\" *C\");\n\nSerial.print(\"Pressure = \");\nSerial.print(bmp.pressure \/ 100.0);\nSerial.println(\" hPa\");\n\nSerial.print(\"Approx. Altitude = \");\nSerial.print(bmp.readAltitude(SEALEVELPRESSURE_HPA));\nSerial.println(\" m\");<\/code><\/pre>\n\n\n\n<p>You get each specific reading as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><span class=\"rnthl rntliteral\">bmp.temperature<\/span>: returns temperature reading<\/li><li><span class=\"rnthl rntliteral\">bmp.pressure<\/span>: returns pressure reading<\/li><li><span class=\"rnthl rntliteral\">bmp.readAltitude (SEALEVELPRESSURE_HPA)<\/span>: returns altitude estimation<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"demonstration\">Demonstration<\/h2>\n\n\n\n<p>After inserting the sea level pressure for your location, you can upload the code to your board. In your Arduino IDE, go to <strong>Tools <\/strong>&gt; <strong>Boards <\/strong>and select the board you&#8217;re using. Then, in <strong>Tools<\/strong> &gt; <strong>Port<\/strong>, select the COM port.<\/p>\n\n\n\n<p>After uploading, open the Serial Monitor at a baud rate of 115200. The readings will be printed in the Serial Monitor.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"674\" height=\"525\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/BMP388-Altitude-Pressure-Arduino-IDE-Serial-Monitor.png?resize=674%2C525&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"BMP388 Altitude Pressure Display Serial Monitor\" class=\"wp-image-103884\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/BMP388-Altitude-Pressure-Arduino-IDE-Serial-Monitor.png?w=674&amp;quality=100&amp;strip=all&amp;ssl=1 674w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/BMP388-Altitude-Pressure-Arduino-IDE-Serial-Monitor.png?resize=300%2C234&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 674px) 100vw, 674px\" \/><\/figure><\/div>\n\n\n\n<p>Notice that if you increase the sensor&#8217;s altitude, it will be reflected in the altitude reading. The altitude estimation is pretty accurate. It can detect small changes in the centimeters or inches range. You can check it by comparing the altitude you&#8217;re getting with the altitude of your location. To get your location&#8217;s altitude, you can use this <a href=\"https:\/\/www.freemaptools.com\/elevation-finder.htm\" target=\"_blank\" rel=\"noreferrer noopener\">website<\/a>. <\/p>\n\n\n\n<hr class=\"wp-block-separator is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>The BMP388 is a small and very precise pressure sensor that allows you to estimate altitude with great precision. The sensor also measures temperature. It is great for outdoor\/indoor navigation, drones, weather stations, and other applications.<\/p>\n\n\n\n<p>You&#8217;ve learned how to use the sensor with the Arduino board in this tutorial. We hope you found this getting started guide useful. In addition, we have guides for other popular sensors:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/complete-guide-for-dht11dht22-humidity-and-temperature-sensor-with-arduino\/\">Guide for&nbsp;<strong>DHT11\/DHT22 Temperature and Humidity Sensor<\/strong>&nbsp;with Arduino<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/bme280-sensor-arduino-pressure-temperature-humidity\/\">Guide for&nbsp;<strong>BME280<\/strong> Sensor&nbsp;with Arduino (<strong>Pressure, Temperature, Humidity<\/strong>)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-bmp180-barometric-sensor-with-arduino\/\">Guide for <strong>BMP180 Barometric Sensor<\/strong> with Arduino<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-ds18b20-temperature-sensor-with-arduino\/\">Guide for <strong>DS18B20 Temperature Sensor<\/strong> with Arduino<\/a><\/li><\/ul>\n\n\n\n<p>Learn more about the Arduino board with our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/arduino-step-by-step-projects\/\">Arduino Step-by-step Projects<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/free-arduino-mini-course\/\">Arduino Mini-Course for Absolute Beginners<\/a><\/li><li><a style=\"font-size: inherit;\" href=\"https:\/\/randomnerdtutorials.com\/projects-arduino\/\">More Arduino Projects and Tutorials \u2026<\/a><\/li><\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Guide for BMP388 Altimeter with Arduino (Pressure, Altitude, Temperature)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/arduino-bmp388\/#more-104357\" aria-label=\"Read more about Guide for BMP388 Altimeter with Arduino (Pressure, Altitude, Temperature)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":104368,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[303],"tags":[],"class_list":["post-104357","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-arduino"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/Arduino-with-BMP388-Barometric-Altimeter-Sensor-Guide.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/104357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=104357"}],"version-history":[{"count":11,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/104357\/revisions"}],"predecessor-version":[{"id":107115,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/104357\/revisions\/107115"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/104368"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=104357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=104357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=104357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}