{"id":103853,"date":"2021-06-30T17:10:01","date_gmt":"2021-06-30T17:10:01","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=103853"},"modified":"2021-07-08T11:26:16","modified_gmt":"2021-07-08T11:26:16","slug":"esp32-bmp388-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-bmp388-arduino\/","title":{"rendered":"ESP32 with BMP388 Barometric\/Altimeter Sensor (Arduino IDE)"},"content":{"rendered":"\n<p>In this guide, you&#8217;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.<\/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\/ESP32-with-BMP388-Barometric-Altimeter-Sensor.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 with BMP388 Barometric Altimeter Sensor Arduino IDE\" class=\"wp-image-104307\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/ESP32-with-BMP388-Barometric-Altimeter-Sensor.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/ESP32-with-BMP388-Barometric-Altimeter-Sensor.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\/ESP32-with-BMP388-Barometric-Altimeter-Sensor.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\/ESP32-with-BMP388-Barometric-Altimeter-Sensor.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 ESP32<\/a><\/li><li><a href=\"#basic-example\">Getting BMP388 Pressure, Altitude and Temperature with ESP32<\/a><\/li><li><a href=\"#web-server\">ESP32 Web Server with BMP388<\/a><\/li><\/ul>\n\n\n\n<p>We have a similar tutorial for the ESP8266 board: <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-bmp388-arduino\/\">ESP8266 NodeMCU with BMP388 Barometric\/Altimeter Sensor (Arduino)<\/a><\/p>\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\/ESP32-BMP388-Sensor-Altitude-Pressure-Temperature-Arduino.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 BMP388 Sensor Altitude Pressure Temperature Arduino\" class=\"wp-image-104321\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/ESP32-BMP388-Sensor-Altitude-Pressure-Temperature-Arduino.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/ESP32-BMP388-Sensor-Altitude-Pressure-Temperature-Arduino.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:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BMP388<\/strong><\/td><td><strong>ESP32<\/strong><\/td><\/tr><tr><td><strong>SDI<\/strong> (SDA)<\/td><td>GPIO 21<\/td><\/tr><tr><td><strong>SCK<\/strong> (SCL)<\/td><td>GPIO 22<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><span class=\"rnthl rntcyellow\">GPIO 22<\/span> (SCL) and <span class=\"rnthl rntclgray\">GPIO 21<\/span> (SDA) are the default <a href=\"https:\/\/randomnerdtutorials.com\/esp32-i2c-communication-arduino-ide\/\">ESP32 I2C pins<\/a>. You can use other pins as long as you set them properly in the code.<\/p>\n\n\n\n<p class=\"rntbox rntclblue\">Recommended reading: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-i2c-communication-arduino-ide\/\">ESP32 I2C Communication: Set Pins, Multiple Bus Interfaces and Peripherals (Arduino IDE)<\/a><\/p>\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:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BMP388<\/strong><\/td><td><strong>ESP32<\/strong><\/td><\/tr><tr><td><strong>SCK<\/strong><\/td><td><span class=\"rnthl rntclblue\">GPIO 18<\/span> <\/td><\/tr><tr><td><strong>SDI <\/strong>(MOSI)<\/td><td><span class=\"rnthl rntcgreen\">GPIO 23<\/span> <\/td><\/tr><tr><td><strong>SDO <\/strong>(MISO)<\/td><td><span class=\"rnthl rntcyellow\">GPIO 19<\/span> <\/td><\/tr><tr><td><strong>CS <\/strong>(Chip Select)<\/td><td><span class=\"rnthl rntclgray\">GPIO 5<\/span> <\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>These are the default ESP32 SPI pins. You can use other pins as long as you set them properly in the code.<\/p>\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\/ESP32-BMP388-Sensor-Module-Altitude-Pressure-Temperature.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 BMP388 Sensor Module Altitude Pressure Temperature\" class=\"wp-image-104323\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/ESP32-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\/ESP32-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>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\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\" rel=\"noreferrer noopener\">ESP32&nbsp;<\/a>(read&nbsp;<a href=\"https:\/\/makeradvisor.com\/esp32-development-boards-review-comparison\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best ESP32 development boards<\/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; ESP32 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>ESP32 with BMP388 using I2C<\/strong><\/p>\n\n\n\n<p>Follow the next schematic diagram to wire the BMP388 to the ESP32 using the default 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=\"729\" height=\"711\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/ESP32-BMP388-I2C-Wiring.png?resize=729%2C711&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 BMP388 Wiring Circuit Diagram I2C with Arduino\" class=\"wp-image-103906\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/ESP32-BMP388-I2C-Wiring.png?w=729&amp;quality=100&amp;strip=all&amp;ssl=1 729w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/ESP32-BMP388-I2C-Wiring.png?resize=300%2C293&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 729px) 100vw, 729px\" \/><\/figure><\/div>\n\n\n\n<p><strong>ESP32 with BMP388 using SPI<\/strong><\/p>\n\n\n\n<p>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.<\/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=\"783\" height=\"709\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/ESP32-BMP388-SPI-Wiring.png?resize=783%2C709&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 BMP388 Wiring Circuit Diagram SPI\" class=\"wp-image-103909\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/ESP32-BMP388-SPI-Wiring.png?w=783&amp;quality=100&amp;strip=all&amp;ssl=1 783w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/ESP32-BMP388-SPI-Wiring.png?resize=300%2C272&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/ESP32-BMP388-SPI-Wiring.png?resize=768%2C695&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 783px) 100vw, 783px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Preparing Arduino IDE<\/h2>\n\n\n\n<p>We&#8217;ll program the ESP32 board using Arduino IDE. So, make sure you have the ESP32 add-on installed. Follow the next tutorial:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/installing-the-esp32-board-in-arduino-ide-windows-instructions\/\">Install the ESP32 Board in Arduino IDE<\/a><\/li><\/ul>\n\n\n\n<p>If you want to use VS Code with the PlatformIO extension, follow the next tutorial instead to learn how to program the ESP32:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/vs-code-platformio-ide-esp32-esp8266-arduino\/\">Getting Started with VS Code and PlatformIO IDE for ESP32 and ESP8266 (Windows, Mac OS X, Linux Ubuntu)<\/a><\/li><\/ul>\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 ESP32. 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 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\/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>. We&#8217;ve made a few changes to make it fully compatible with the ESP32.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/***************************************************************************\r\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\r\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!\r\n  Written by Limor Fried &amp; Kevin Townsend for Adafruit Industries. BSD license, all text above must be included in any redistribution\r\n ***************************************************************************\/\r\n\r\n\/\/ Complete project details: https:\/\/RandomNerdTutorials.com\/esp32-bmp388-arduino\/\r\n\r\n#include &lt;Wire.h&gt;\r\n#include &lt;SPI.h&gt;\r\n#include &lt;Adafruit_Sensor.h&gt;\r\n#include &quot;Adafruit_BMP3XX.h&quot;\r\n\r\n#define BMP_SCK 18\r\n#define BMP_MISO 19\r\n#define BMP_MOSI 23\r\n#define BMP_CS 5\r\n\r\n#define SEALEVELPRESSURE_HPA (1013.25)\r\n\r\nAdafruit_BMP3XX bmp;\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  while (!Serial);\r\n  Serial.println(&quot;Adafruit BMP388 \/ BMP390 test&quot;);\r\n\r\n  if (!bmp.begin_I2C()) {   \/\/ hardware I2C mode, can pass in address &amp; alt Wire\r\n  \/\/if (! bmp.begin_SPI(BMP_CS)) {  \/\/ hardware SPI mode  \r\n  \/\/if (! bmp.begin_SPI(BMP_CS, BMP_SCK, BMP_MISO, BMP_MOSI)) {  \/\/ software SPI mode\r\n    Serial.println(&quot;Could not find a valid BMP3 sensor, check wiring!&quot;);\r\n    while (1);\r\n  }\r\n\r\n  \/\/ Set up oversampling and filter initialization\r\n  bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);\r\n  bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);\r\n  bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);\r\n  bmp.setOutputDataRate(BMP3_ODR_50_HZ);\r\n}\r\n\r\nvoid loop() {\r\n  if (! bmp.performReading()) {\r\n    Serial.println(&quot;Failed to perform reading :(&quot;);\r\n    return;\r\n  }\r\n  Serial.print(&quot;Temperature = &quot;);\r\n  Serial.print(bmp.temperature);\r\n  Serial.println(&quot; *C&quot;);\r\n\r\n  Serial.print(&quot;Pressure = &quot;);\r\n  Serial.print(bmp.pressure \/ 100.0);\r\n  Serial.println(&quot; hPa&quot;);\r\n\r\n  Serial.print(&quot;Approx. Altitude = &quot;);\r\n  Serial.print(bmp.readAltitude(SEALEVELPRESSURE_HPA));\r\n  Serial.println(&quot; m&quot;);\r\n\r\n  Serial.println();\r\n  delay(2000);\r\n}\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP32\/BMP388\/bmp3xx_simpletest_ESP32.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 <a href=\"https:\/\/meteologix.com\/observations\/pressure-qnh.html\" target=\"_blank\" rel=\"noreferrer noopener\">website to check 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 18\n#define BMP_MISO 19\n#define BMP_MOSI 23\n#define BMP_CS 5<\/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 default ESP32 I2C pins: <span class=\"rnthl rntcyellow\">GPIO 22<\/span> (SCL), <span class=\"rnthl rntclgray\">GPIO 21<\/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 accept 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. 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\" id=\"web-server\">ESP32 Web Server with BMP388<\/h2>\n\n\n\n<p>In this section, we provide an example of web server that you can build with the ESP32 to display BMP388 readings on a web page.<\/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\/ESP32-BMP388-Sensor-Altitude-Pressure-Temperature-Arduino-Web-Server.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 BMP388 Sensor Altitude Pressure Temperature Arduino Web Server\" class=\"wp-image-104322\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/ESP32-BMP388-Sensor-Altitude-Pressure-Temperature-Arduino-Web-Server.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/ESP32-BMP388-Sensor-Altitude-Pressure-Temperature-Arduino-Web-Server.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\">Installing Libraries \u2013 Async Web Server<\/h3>\n\n\n\n<p>To build the web server you need to install the following libraries. Click the links below to download the libraries.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/me-no-dev\/ESPAsyncWebServer\/archive\/master.zip\" target=\"_blank\">ESPAsyncWebServer<\/a>&nbsp;<\/li><li><a href=\"https:\/\/github.com\/me-no-dev\/AsyncTCP\/archive\/master.zip\" target=\"_blank\" rel=\"noreferrer noopener\">AsyncTCP<\/a><\/li><\/ul>\n\n\n\n<p>These libraries aren\u2019t available to install through the Arduino Library Manager, so you need to copy the library files to the Arduino Installation Libraries folder. Alternatively, in your Arduino IDE, you can go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&nbsp;&gt;&nbsp;<strong>Add .zip Library<\/strong>&nbsp;and select the libraries you\u2019ve just downloaded.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Code<\/h3>\n\n\n\n<p>Then, upload the following code to your board (type your SSID and password).<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\r\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\r\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-bmp388-arduino\/\r\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\r\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n*********\/\r\n\r\n#include &lt;Wire.h&gt;\r\n#include &lt;SPI.h&gt;\r\n#include &lt;Adafruit_Sensor.h&gt;\r\n#include &lt;Adafruit_BMP3XX.h&gt;\r\n#include &lt;WiFi.h&gt;\r\n#include &lt;ESPAsyncWebServer.h&gt;\r\n\r\n\/\/ Replace with your network credentials\r\nconst char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;\r\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\r\n\r\n\/\/Uncomment if using SPI\r\n\/*#define BMP_SCK 18\r\n#define BMP_MISO 19\r\n#define BMP_MOSI 23\r\n#define BMP_CS 5*\/\r\n\r\n#define SEALEVELPRESSURE_HPA (1013.25)\r\n\r\nAdafruit_BMP3XX bmp;\r\n\r\nfloat temp;\r\nfloat pres;\r\nfloat alt;\r\n\r\nAsyncWebServer server(80);\r\nAsyncEventSource events(&quot;\/events&quot;);\r\n\r\nunsigned long lastTime = 0;  \r\nunsigned long timerDelay = 30000;  \/\/ send readings timer\r\n\r\nvoid getBMPReadings(){\r\n  if (! bmp.performReading()) {\r\n    Serial.println(&quot;Failed to perform reading :(&quot;);\r\n    return;\r\n  }\r\n  temp = bmp.temperature;\r\n  pres = bmp.pressure \/ 100.0;\r\n  alt = bmp.readAltitude(SEALEVELPRESSURE_HPA);\r\n}\r\n\r\nString processor(const String&amp; var){\r\n  getBMPReadings();\r\n  \/\/Serial.println(var);\r\n  if(var == &quot;TEMPERATURE&quot;){\r\n    return String(temp);\r\n  }\r\n  else if(var == &quot;PRESSURE&quot;){\r\n    return String(pres);\r\n  }\r\n else if(var == &quot;ALTITUDE&quot;){\r\n    return String(alt);\r\n  }\r\n}\r\n\r\nconst char index_html[] PROGMEM = R&quot;rawliteral(\r\n&lt;!DOCTYPE HTML&gt;&lt;html&gt;\r\n&lt;head&gt;\r\n  &lt;title&gt;BMP388 Web Server&lt;\/title&gt;\r\n  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;\r\n  &lt;link rel=&quot;stylesheet&quot; href=&quot;https:\/\/use.fontawesome.com\/releases\/v5.7.2\/css\/all.css&quot; integrity=&quot;sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr&quot; crossorigin=&quot;anonymous&quot;&gt;\r\n  &lt;link rel=&quot;icon&quot; href=&quot;data:,&quot;&gt;\r\n  &lt;style&gt;\r\n    html {font-family: Arial; display: inline-block; text-align: center;}\r\n    p {  font-size: 1.2rem;}\r\n    body {  margin: 0;}\r\n    .topnav { overflow: hidden; background-color: #0F7173; color: white; font-size: 1.4rem; }\r\n    .content { padding: 20px; }\r\n    .card { background-color: white; box-shadow: 2px 2px 12px 1px rgba(140,140,140,.5); }\r\n    .cards { max-width: 700px; margin: 0 auto; display: grid; grid-gap: 2rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }\r\n    .reading { font-size: 2rem; }\r\n    .card.temperature { color: #272932; }\r\n    .card.altitude { color: #D8A47F; }\r\n    .card.pressure { color: #F05D5E; }\r\n  &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n  &lt;div class=&quot;topnav&quot;&gt;\r\n    &lt;h3&gt;BMP388 WEB SERVER&lt;\/h3&gt;\r\n  &lt;\/div&gt;\r\n  &lt;div class=&quot;content&quot;&gt;\r\n    &lt;div class=&quot;cards&quot;&gt;\r\n      &lt;div class=&quot;card pressure&quot;&gt;\r\n        &lt;h4&gt;&lt;i class=&quot;fas fa-angle-double-down&quot;&gt;&lt;\/i&gt; PRESSURE&lt;\/h4&gt;&lt;p&gt;&lt;span class=&quot;reading&quot;&gt;&lt;span id=&quot;pres&quot;&gt;%PRESSURE%&lt;\/span&gt; hPa&lt;\/span&gt;&lt;\/p&gt;\r\n      &lt;\/div&gt;\r\n      &lt;div class=&quot;card altitude&quot;&gt;\r\n        &lt;h4&gt;&lt;i class=&quot;fas fa-long-arrow-alt-up&quot;&gt;&lt;\/i&gt; ALTITUDE&lt;\/h4&gt;&lt;p&gt;&lt;span class=&quot;reading&quot;&gt;&lt;span id=&quot;alt&quot;&gt;%ALTITUDE%&lt;\/span&gt; m&lt;\/span&gt;&lt;\/p&gt;\r\n      &lt;\/div&gt;\r\n      &lt;div class=&quot;card temperature&quot;&gt;\r\n        &lt;h4&gt;&lt;i class=&quot;fas fa-thermometer-half&quot;&gt;&lt;\/i&gt; TEMPERATURE&lt;\/h4&gt;&lt;p&gt;&lt;span class=&quot;reading&quot;&gt;&lt;span id=&quot;temp&quot;&gt;%TEMPERATURE%&lt;\/span&gt; &amp;deg;C&lt;\/span&gt;&lt;\/p&gt;\r\n      &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n  &lt;\/div&gt;\r\n&lt;script&gt;\r\nif (!!window.EventSource) {\r\n var source = new EventSource('\/events');\r\n \r\n source.addEventListener('open', function(e) {\r\n  console.log(&quot;Events Connected&quot;);\r\n }, false);\r\n source.addEventListener('error', function(e) {\r\n  if (e.target.readyState != EventSource.OPEN) {\r\n    console.log(&quot;Events Disconnected&quot;);\r\n  }\r\n }, false);\r\n \r\n source.addEventListener('message', function(e) {\r\n  console.log(&quot;message&quot;, e.data);\r\n }, false);\r\n \r\n source.addEventListener('temperature', function(e) {\r\n  console.log(&quot;temperature&quot;, e.data);\r\n  document.getElementById(&quot;temp&quot;).innerHTML = e.data;\r\n }, false);\r\n \r\n source.addEventListener('pressure', function(e) {\r\n  console.log(&quot;pressure&quot;, e.data);\r\n  document.getElementById(&quot;pres&quot;).innerHTML = e.data;\r\n }, false);\r\n \r\n source.addEventListener('altitude', function(e) {\r\n  console.log(&quot;altitude&quot;, e.data);\r\n  document.getElementById(&quot;alt&quot;).innerHTML = e.data;\r\n }, false);\r\n}\r\n&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;)rawliteral&quot;;\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n\r\n  WiFi.mode(WIFI_STA);\r\n  \r\n  \/\/ Set device as a Wi-Fi Station\r\n  WiFi.begin(ssid, password);\r\n  while (WiFi.status() != WL_CONNECTED) {\r\n    delay(1000);\r\n    Serial.println(&quot;Setting as a Wi-Fi Station..&quot;);\r\n  }\r\n  Serial.print(&quot;Station IP Address: &quot;);\r\n  Serial.println(WiFi.localIP());\r\n  Serial.println();\r\n\r\n  \/\/ Init BMEP388 sensor\r\n  if (!bmp.begin_I2C()) {   \/\/ hardware I2C mode, can pass in address &amp; alt Wire\r\n  \/\/if (! bmp.begin_SPI(BMP_CS)) {  \/\/ hardware SPI mode  \r\n  \/\/if (! bmp.begin_SPI(BMP_CS, BMP_SCK, BMP_MISO, BMP_MOSI)) {  \/\/ software SPI mode\r\n    Serial.println(&quot;Could not find a valid BMP3 sensor, check wiring!&quot;);\r\n    while (1);\r\n  }\r\n  \/\/ Set up oversampling and filter initialization\r\n  bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);\r\n  bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);\r\n  bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);\r\n  bmp.setOutputDataRate(BMP3_ODR_50_HZ);\r\n\r\n  \/\/Get readings when initializing\r\n  getBMPReadings();\r\n\r\n  \/\/ Handle Web Server\r\n  server.on(&quot;\/&quot;, HTTP_GET, [](AsyncWebServerRequest *request){\r\n    request-&gt;send(200, &quot;text\/html&quot;, index_html, processor);\r\n  });\r\n\r\n  \/\/ Handle Web Server Events\r\n  events.onConnect([](AsyncEventSourceClient *client){\r\n    if(client-&gt;lastId()){\r\n      Serial.printf(&quot;Client reconnected! Last message ID that it got is: %u\\n&quot;, client-&gt;lastId());\r\n    }\r\n    \/\/ send event with message &quot;hello!&quot;, id current millis\r\n    \/\/ and set reconnect delay to 1 second\r\n    client-&gt;send(&quot;hello!&quot;, NULL, millis(), 10000);\r\n  });\r\n  server.addHandler(&amp;events);\r\n  server.begin();\r\n}\r\n\r\nvoid loop() {\r\n  if ((millis() - lastTime) &gt; timerDelay) {\r\n    getBMPReadings();\r\n    Serial.printf(&quot;Pressure = %.2f hPa \\n&quot;, pres);\r\n    Serial.printf(&quot;Altitude = %.2f m \\n&quot;, alt);\r\n    Serial.printf(&quot;Temperature = %.2f \u00baC \\n&quot;, temp);\r\n    Serial.println();\r\n\r\n    \/\/ Send Events to the Web Server with the Sensor Readings\r\n    events.send(&quot;ping&quot;,NULL,millis());\r\n    events.send(String(pres).c_str(),&quot;pressure&quot;,millis());\r\n    events.send(String(alt).c_str(),&quot;altitude&quot;,millis());\r\n    events.send(String(temp).c_str(),&quot;temperature&quot;,millis());\r\n    \r\n    lastTime = millis();\r\n  }\r\n}\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP32\/BMP388\/ESP32_BMP388_Web_Server.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Demonstration<\/h3>\n\n\n\n<p>After uploading, open the Serial Monitor at a baud rate of 115200 to get the ESP32 IP address.<\/p>\n\n\n\n<p>Open a browser and type the IP address. You should get access to the web server with the latest sensor readings. You can access the web server on your computer, tablet, or smartphone in your local network.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/BMP388-Simple-Web-Server-ESP32.jpg?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"609\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/BMP388-Simple-Web-Server-ESP32.jpg?resize=300%2C609&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 Simple Web Server BMP388 Altimeter\" class=\"wp-image-104309\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/BMP388-Simple-Web-Server-ESP32.jpg?w=300&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/BMP388-Simple-Web-Server-ESP32.jpg?resize=148%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 148w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>The readings are updated automatically on the web server using Server-Sent Events. You can check the <a href=\"https:\/\/randomnerdtutorials.com\/esp32-web-server-sent-events-sse\/\">Server-Sent Events tutorial<\/a> to have an idea of how it works.<\/p>\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 ESP32 development board and Arduino IDE 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\/esp32-dht11-dht22-temperature-humidity-sensor-arduino-ide\/\">ESP32 with&nbsp;<strong>DHT11\/DHT22 Temperature and Humidity Sensor<\/strong>&nbsp;using Arduino IDE<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\">ESP32 with&nbsp;<strong>BME280<\/strong>&nbsp;using Arduino IDE (<strong>Pressure, Temperature, Humidity<\/strong>)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme680-sensor-arduino\/\">ESP32 with <strong>BME680 Environmental Sensor<\/strong> using Arduino IDE (Gas, Pressure, Humidity, Temperature)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-ds18b20-temperature-arduino-ide\/\">ESP32<strong>&nbsp;DS18B20 Temperature Sensor<\/strong>&nbsp;with Arduino IDE (Single, Multiple, Web Server)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-with-bmp180-barometric-sensor\/\">ESP32 with&nbsp;<strong>BMP180 Barometric Sensor<\/strong>&nbsp;(Temperature and Pressure)<\/a><\/li><\/ul>\n\n\n\n<p>Learn more about the ESP32 with our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE (eBook + video course)<\/a><\/strong><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/build-web-servers-esp32-esp8266-ebook\/\">Build Web Servers with ESP32 and ESP8266 eBook (2nd Edition)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">More ESP32 Projects and Tutorials \u2026<\/a><\/li><\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, you&#8217;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. &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32 with BMP388 Barometric\/Altimeter Sensor (Arduino IDE)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-bmp388-arduino\/#more-103853\" aria-label=\"Read more about ESP32 with BMP388 Barometric\/Altimeter Sensor (Arduino IDE)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":104307,"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":[281,276,277,299,264],"tags":[],"class_list":["post-103853","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32-project","category-esp32","category-esp32-arduino-ide","category-0-esp32","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/06\/ESP32-with-BMP388-Barometric-Altimeter-Sensor.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\/103853","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=103853"}],"version-history":[{"count":20,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/103853\/revisions"}],"predecessor-version":[{"id":105074,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/103853\/revisions\/105074"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/104307"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=103853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=103853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=103853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}