{"id":86653,"date":"2019-07-02T12:30:22","date_gmt":"2019-07-02T12:30:22","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=86653"},"modified":"2020-07-30T14:11:54","modified_gmt":"2020-07-30T14:11:54","slug":"bme280-sensor-arduino-pressure-temperature-humidity","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/bme280-sensor-arduino-pressure-temperature-humidity\/","title":{"rendered":"Guide for BME280 Sensor with Arduino (Pressure, Temperature, Humidity)"},"content":{"rendered":"\n<p>This guide shows how to use the BME280 sensor module with Arduino to read pressure, temperature, humidity and estimate altitude. We\u2019ll show you how to wire the sensor, install the required libraries, and write a simple sketch to display the sensor readings.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/BME280-arduino-thumbnail.png?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Guide for BME280 Sensor with Arduino Pressure, Temperature, and Humidity\" class=\"wp-image-86654\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/BME280-arduino-thumbnail.png?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/BME280-arduino-thumbnail.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/BME280-arduino-thumbnail.png?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/BME280-arduino-thumbnail.png?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<p>You might also like reading other BME280 guides:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><span style=\"font-size: inherit; background-color: initial;\"><a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\">ESP32 with BME280 Sensor using Arduino IDE<\/a><\/span><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-web-server-with-bme280-mini-weather-station\/\">ESP32 Web Server with BME280 \u2013 Weather Station<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-bme280-arduino-ide\/\">ESP8266 with BME280 using Arduino IDE<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/micropython-bme280-esp32-esp8266\/\">ESP32\/ESP8266 with BME280 using MicroPython<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Introducing BME280 Sensor Module<\/h2>\n\n\n\n<p>The <a rel=\"noreferrer noopener\" aria-label=\"BME280 sensor (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/bme280-sensor-module\/\" target=\"_blank\">BME280 sensor<\/a> module reads barometric pressure, temperature, and humidity. Because pressure changes with altitude, you can also estimate altitude. There are several versions of this sensor module. The BME280 sensor uses I2C or SPI communication protocol to exchange data with a microcontroller.<\/p>\n\n\n\n<p>We\u2019re using the module illustrated in the figure below.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"1200\" height=\"722\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/bme280-sensor.jpg?resize=1200%2C722&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"BME280 Sensor Module reads pressure, temperature, and humidity\" class=\"wp-image-86437\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/bme280-sensor.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/bme280-sensor.jpg?resize=300%2C180&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/bme280-sensor.jpg?resize=768%2C462&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/bme280-sensor.jpg?resize=1024%2C616&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<p>This sensor communicates using I2C communication protocol, so the wiring is very simple. You connect the BME280 sensor to the Arduino Uno I2C pins as shown in the table below:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BME280<\/strong><\/td><td><strong>Arduino<\/strong><\/td><\/tr><tr><td>Vin<\/td><td><span class=\"rnthl rntcred\">5V<\/span><\/td><\/tr><tr><td>GND<\/td><td><span class=\"rnthl rntcblack\">GND<\/span><\/td><\/tr><tr><td>SCL<\/td><td><span class=\"rnthl rntcblue\">A5<\/span><\/td><\/tr><tr><td>SDA<\/td><td><span class=\"rnthl rntcgreen\">A4<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>There are other versions of this sensor that can use either SPI or I2C communication protocols, like the module shown in the next figure:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/BME280-SPI.jpg?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"BME280 with SPI and I2C\" class=\"wp-image-86630\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/BME280-SPI.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/BME280-SPI.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>If you&#8217;re using one of these sensors, to use I2C communication protocol, use the following pins:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BME280<\/strong><\/td><td><strong>Arduino<\/strong><\/td><\/tr><tr><td>SCK (SCL Pin)<\/td><td> <span class=\"rnthl rntcblue\">A5<\/span> <\/td><\/tr><tr><td>SDI (SDA pin) <\/td><td> <span class=\"rnthl rntcgreen\">A4<\/span> <\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>If you use SPI communication protocol, you need to use the following pins:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BME280<\/strong><\/td><td><strong>Arduino<\/strong><\/td><\/tr><tr><td> SCK (SPI Clock)<\/td><td> <span class=\"rnthl rntcblue\">Pin 13<\/span><\/td><\/tr><tr><td> SDO&nbsp;(MISO)<\/td><td> <span class=\"rnthl rntcyellow\">Pin 12<\/span><\/td><\/tr><tr><td> SDI (MOSI)<\/td><td> <span class=\"rnthl rntcgreen\">Pin 11<\/span><\/td><\/tr><tr><td> CS (Chip Select) <\/td><td> <span class=\"rnthl rntcbrown\">Pin 10<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Parts Required<\/h2>\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\/bme280-sensor-module\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">BME280 sensor module<\/a><\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\">Arduino <\/a>(read <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/best-arduino-starter-kits\/\" target=\"_blank\">Best Arduino Started Kits<\/a>)<\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\">Breadboard<\/a><\/li><li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" 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\">Schematic<\/h2>\n\n\n\n<p>Wire the BME280 sensor to your Arduino board as shown in the following schematic diagram.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/BME280-Arduino_schematic.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/BME280-Arduino_schematic.png?resize=563%2C680&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino BME280 Wiring Schematic Diagram\" class=\"wp-image-86657\" width=\"563\" height=\"680\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/BME280-Arduino_schematic.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/BME280-Arduino_schematic.png?resize=248%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 248w\" sizes=\"(max-width: 563px) 100vw, 563px\" \/><\/a><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Installing the BME280 library<\/h2>\n\n\n\n<p>To get readings from the BME280 sensor module you need to use the <a href=\"https:\/\/github.com\/adafruit\/Adafruit_BME280_Library\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Adafruit_BME280 library<\/a>. 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 bme280<\/strong> \u201d on the Search box and install the library.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"443\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/08\/install-bme280.png?resize=786%2C443&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Installing BME280 library in Arduino IDE\" class=\"wp-image-70233\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/08\/install-bme280.png?w=786&amp;quality=100&amp;strip=all&amp;ssl=1 786w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/08\/install-bme280.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/08\/install-bme280.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<h2 class=\"wp-block-heading\">Installing the Adafruit_Sensor library<\/h2>\n\n\n\n<p>To use the BME280 library, you also need to install the <a href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Adafruit_Sensor library<\/a>. Follow the next steps to install the library in your Arduino IDE:<\/p>\n\n\n\n<p>Go to <strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&nbsp;&gt;&nbsp;<strong>Manage Libraries<\/strong> 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<figure class=\"wp-block-image\"><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>\n\n\n\n<p>After installing the libraries, restart your Arduino IDE.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Reading Pressure, Temperature, and Humidity<\/h2>\n\n\n\n<p>To read pressure, temperature, and humidity we&#8217;ll use a sketch example from the library.<\/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=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-BME280-circuit.jpg?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino BME280 Guide Reading Temperature, Humidity, and Pressure Sketch\" class=\"wp-image-86658\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-BME280-circuit.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-BME280-circuit.jpg?resize=300%2C168&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 BME280 library, and the Adafruit_Sensor library, open the Arduino IDE and, go to <strong>File<\/strong> &gt; <strong>Examples<\/strong> &gt; <strong>Adafruit BME280 library<\/strong> &gt; <strong>bme280 test<\/strong>.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n * Complete Project Details http:\/\/randomnerdtutorials.com\n*\/\n\n#include &lt;Wire.h&gt;\n#include &lt;SPI.h&gt;\n#include &lt;Adafruit_Sensor.h&gt;\n#include &lt;Adafruit_BME280.h&gt;\n\n#define BME_SCK 13\n#define BME_MISO 12\n#define BME_MOSI 11\n#define BME_CS 10\n\n#define SEALEVELPRESSURE_HPA (1013.25)\n\nAdafruit_BME280 bme; \/\/ I2C\n\/\/Adafruit_BME280 bme(BME_CS); \/\/ hardware SPI\n\/\/Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); \/\/ software SPI\n\nunsigned long delayTime;\n\nvoid setup() {\n  Serial.begin(9600);\n  Serial.println(F(&quot;BME280 test&quot;));\n\n  bool status;\n  \n  \/\/ default settings\n  \/\/ (you can also pass in a Wire library object like &amp;Wire2)\n  status = bme.begin();  \n  if (!status) {\n    Serial.println(&quot;Could not find a valid BME280 sensor, check wiring!&quot;);\n    while (1);\n  }\n  \n  Serial.println(&quot;-- Default Test --&quot;);\n  delayTime = 1000;\n\n  Serial.println();\n}\n\n\nvoid loop() { \n  printValues();\n  delay(delayTime);\n}\n\n\nvoid printValues() {\n  Serial.print(&quot;Temperature = &quot;);\n  Serial.print(bme.readTemperature());\n  Serial.println(&quot; *C&quot;);\n  \n  \/\/ Convert temperature to Fahrenheit\n  \/*Serial.print(&quot;Temperature = &quot;);\n  Serial.print(1.8 * bme.readTemperature() + 32);\n  Serial.println(&quot; *F&quot;);*\/\n  \n  Serial.print(&quot;Pressure = &quot;);\n  Serial.print(bme.readPressure() \/ 100.0F);\n  Serial.println(&quot; hPa&quot;);\n  \n  Serial.print(&quot;Approx. Altitude = &quot;);\n  Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));\n  Serial.println(&quot; m&quot;);\n  \n  Serial.print(&quot;Humidity = &quot;);\n  Serial.print(bme.readHumidity());\n  Serial.println(&quot; %&quot;);\n  \n  Serial.println();\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\/Arduino_BME280_Test.ino\" target=\"_blank\">View raw code<\/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 &#8220;Demonstration&#8221; 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, and the <span class=\"rnthl rntliteral\">Adafruit_Sensor<\/span> and <span class=\"rnthl rntliteral\">Adafruit_BME280<\/span> libraries to interface with the BME280 sensor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;Wire.h>\n#include &lt;Adafruit_Sensor.h>\n#include &lt;Adafruit_BME280.h><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">SPI communication<\/h3>\n\n\n\n<p>As we&#8217;re going to use I2C communication, the following lines that define the SPI pins are commented:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/*#define BME_SCK 13\n#define BME_MISO 12\n#define BME_MOSI 11\n#define BME_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 more accurate results, replace the value with the current sea level pressure at your location.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">I2C<\/h3>\n\n\n\n<p>This example uses I2C communication protocol by default. As you can see, you just need to create an <span class=\"rnthl rntliteral\">Adafruit_BME280<\/span> object called <span class=\"rnthl rntliteral\">bme<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Adafruit_BME280 bme; \/\/ I2C<\/code><\/pre>\n\n\n\n<p>To use SPI, you need to comment this previous line and uncomment one of the following lines.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/Adafruit_BME280 bme(BME_CS); \/\/ hardware SPI\n\/\/Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); \/\/ software SPI<\/code><\/pre>\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(9600);<\/code><\/pre>\n\n\n\n<p>And the sensor is initialized:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>status = bme.begin(); \nif (!status) {\n  Serial.println(\"Could not find a valid BME280 sensor, check wiring!\");\n  while (1);\n}<\/code><\/pre>\n\n\n\n<p class=\"rntbox rntclblue\"><strong>Note: <\/strong> when testing the sensor, if you can&#8217;t get any sensor readings, you may need to find your BME280 sensor I2C address. With the BME280 wired to your Arduino, run <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/raw.githubusercontent.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/master\/Projects\/LCD_I2C\/I2C_Scanner.ino\" target=\"_blank\">this I2C scanner sketch<\/a> to check the address of your sensor. Then, pass the address to the <span class=\"rnthl rntliteral\">begin()<\/span> method.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Printing values<\/h3>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, the <span class=\"rnthl rntliteral\">printValues()<\/span> function reads the values from the BME280 and prints the results in the Serial Monitor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void loop() { \n  printValues();\n  delay(delayTime);\n}<\/code><\/pre>\n\n\n\n<p>Reading temperature, humidity, pressure, and estimate altitude is as simple as using the following methods on the <span class=\"rnthl rntliteral\">bme<\/span> object:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><span class=\"rnthl rntliteral\">bme.readTemperature()<\/span> &#8211; reads temperature in Celsius;<\/li><li><span class=\"rnthl rntliteral\">bme.readHumidity()<\/span> &#8211; reads absolute humidity;<\/li><li><span class=\"rnthl rntliteral\">bme.readPressure()<\/span> &#8211; reads pressure in hPa (hectoPascal = millibar);<\/li><li><span class=\"rnthl rntliteral\">bme.readAltitude(SEALEVELPRESSURE_HPA)<\/span> &#8211; estimates altitude in meters based on the pressure at the sea level.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-BME280-guide.jpg?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino BME280 Read Temperature, Humidity, and Pressure Sketch\" class=\"wp-image-86659\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-BME280-guide.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/Arduino-BME280-guide.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>Upload the code to your Arduino Board.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"34\" height=\"29\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/12\/arduino-ide-upload-button.png?resize=34%2C29&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Upload Arduino Sketch for BME280 Sensor\" class=\"wp-image-65439\"\/><\/figure><\/div>\n\n\n\n<p>Open the Serial Monitor at a baud rate of 9600. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"745\" height=\"109\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/serial-monitor.png?resize=745%2C109&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Upload Arduino Sketch for BME280 Sensor\" class=\"wp-image-81671\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/serial-monitor.png?w=745&amp;quality=100&amp;strip=all&amp;ssl=1 745w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/serial-monitor.png?resize=300%2C44&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 745px) 100vw, 745px\" \/><\/figure><\/div>\n\n\n\n<p>You should see the readings displayed on the Serial Monitor.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"666\" height=\"469\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/bme280-readings-arduino-ide.png?resize=666%2C469&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino Sketch for BME280 Sensor Demonstration Serial Monitor\" class=\"wp-image-86486\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/bme280-readings-arduino-ide.png?w=666&amp;quality=100&amp;strip=all&amp;ssl=1 666w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/bme280-readings-arduino-ide.png?resize=300%2C211&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 666px) 100vw, 666px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>The BME280 provides an easy and inexpensive way to get pressure, temperature and humidity readings. The sensor communicates via I2C communication protocol, which means that wiring is very simple, you just need to connect the sensor to the Arduino I2C pins. <\/p>\n\n\n\n<p>Writing the code to get the sensor readings is also very straightforward thanks to the BME280_Adafruit library. You just need to use the <span class=\"rnthl rntliteral\">readTemperature()<\/span>, <span class=\"rnthl rntliteral\">readHumidity()<\/span> and <span class=\"rnthl rntliteral\">readPressure()<\/span> methods. You can also estimate altitude using the <span class=\"rnthl rntliteral\">readAltitude()<\/span> method.<\/p>\n\n\n\n<p>We have guides for other sensors and modules with the Arduino that you may find useful:<\/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\/\">DHT11\/DHT22 Humidity and Temperature Sensor With Arduino<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-ds18b20-temperature-sensor-with-arduino\/\">DS18B20 Temperature Sensor with Arduino<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-oled-display-with-arduino\/\">I2C OLED Display with Arduino<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-relay-module-with-arduino\/\">Relay Module with Arduino<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/complete-guide-for-ultrasonic-sensor-hc-sr04\/\">Ultrasonic Sensor HC-SR04 with Arduino<\/a><\/li><\/ul>\n\n\n\n<p>If you want to learn more about Arduino, take a look at 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 course<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/projects-arduino\/\">Free Arduino Projects and Tutorials<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/arduino-mini-course\/\">Arduino Mini Course<\/a><\/li><\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide shows how to use the BME280 sensor module with Arduino to read pressure, temperature, humidity and estimate altitude. We\u2019ll show you how to wire the sensor, install the &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Guide for BME280 Sensor with Arduino (Pressure, Temperature, Humidity)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/bme280-sensor-arduino-pressure-temperature-humidity\/#more-86653\" aria-label=\"Read more about Guide for BME280 Sensor with Arduino (Pressure, Temperature, Humidity)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":86654,"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":[2,302,269,264,10],"tags":[],"class_list":["post-86653","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-0-guide","category-guide-project","category-project","category-a-tutorials"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/BME280-arduino-thumbnail.png?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/86653","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=86653"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/86653\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/86654"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=86653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=86653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=86653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}