{"id":136870,"date":"2024-01-31T16:00:51","date_gmt":"2024-01-31T16:00:51","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=136870"},"modified":"2024-02-08T15:20:09","modified_gmt":"2024-02-08T15:20:09","slug":"raspberry-pi-pico-bme280-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-bme280-arduino\/","title":{"rendered":"Raspberry Pi Pico: BME280 Get Temperature, Humidity, and Pressure (Arduino IDE)"},"content":{"rendered":"\n<p>Get started quickly with the BME280 sensor module with the Raspberry Pi Pico board, programmed using the Arduino IDE, to get temperature, humidity, and pressure readings. This brief tutorial will teach you how to use the BME280 sensor with your Raspberry Pi Pico board. We&#8217;ll show you how to wire the sensor, install the required libraries, and write a simple sketch to display sensor readings.<\/p>\n\n\n<div class=\"wp-block-image\">\n<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\/2023\/09\/Raspberry-Pi-Pico-BME280-Arduino-IDE.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico with BME280 Get Temperature Humidity and Pressure Arduino IDE\" class=\"wp-image-136871\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-BME280-Arduino-IDE.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-BME280-Arduino-IDE.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-BME280-Arduino-IDE.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-BME280-Arduino-IDE.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<p class=\"rntbox rntclgreen\"><strong>New to the Raspberry Pi Pico?<\/strong> <a href=\"https:\/\/randomnerdtutorials.com\/getting-started-raspberry-pi-pico-w\/\" title=\"\">Get started with the Raspberry Pi Pico here<\/a>.<\/p>\n\n\n\n<p><strong>Table of Contents<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#rpi-pico-arduino-ide\" title=\"\">Raspberry Pi Pico with Arduino IDE<\/a><\/li>\n\n\n\n<li><a href=\"#intro-bme280\" title=\"\">Introducing the BME280 Sensor Module<\/a><\/li>\n\n\n\n<li><a href=\"#bme280-raspberry-pi-pico-circuit\" title=\"\">Wiring the BME280 to the Raspberry Pi Pico<\/a><\/li>\n\n\n\n<li><a href=\"#bme280-library-raspberry-pi-pico-arduino-ide\" title=\"\">BME280 Library for Arduino IDE<\/a><\/li>\n\n\n\n<li><a href=\"#bme280-raspberry-pi-pico-code\" title=\"\">BME280 Pressure, Temperature, and Humidity &#8211; Arduino Sketch<\/a><\/li>\n<\/ul>\n\n\n\n<p>Do you prefer to program the Raspberry Pi Pico using MicroPython firmware? Check this tutorial instead:\u00a0<a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-bme280-micropython\/\">Raspberry Pi Pico \u2013 BME280 Get Temperature, Humidity, and Pressure (MicroPython)<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"rpi-pico-arduino-ide\">Raspberry Pi Pico with Arduino IDE<\/h2>\n\n\n\n<p>You need to install the Raspberry Pi Pico boards on Arduino IDE and you must know how to upload code to the board. Check out the following tutorial first if you haven\u2019t already:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/programming-raspberry-pi-pico-w-arduino-ide\/\">Programming Raspberry Pi Pico with Arduino IDE<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"intro-bme280\">Introducing the BME280 Sensor Module<\/h2>\n\n\n\n<p>The <a aria-label=\"BME280 sensor module (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/bme280-sensor-module\/\" target=\"_blank\" rel=\"noreferrer noopener\">BME280 sensor module<\/a> reads barometric pressure, temperature, and humidity. Because pressure changes with altitude, you can also estimate altitude. There are several versions of this sensor module, but we\u2019re using the one shown in the figure below.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><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 temperature, humidity, and pressure\" class=\"wp-image-86437\" style=\"width:750px;height:408px\" 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<p>This sensor communicates using I2C communication protocol, so the wiring is very simple. You can use any Raspberry Pi Pico I2C pins to connect the BME280 sensor. We&#8217;ll be using <span class=\"rnthl rntcyellow\">GPIO 4<\/span> (SDA) and <span class=\"rnthl rntclgray\">GPIO 5<\/span> (SCL)\u2014<a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-pinout-gpios\/\" title=\"\">learn more about the Raspberry Pi Pico GPIOs<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BME280<\/strong><\/td><td><strong>Raspberry Pi Pico<\/strong><\/td><\/tr><tr><td>Vin<\/td><td><span class=\"rnthl rntcred\">3.3V<\/span> (OUT)<\/td><\/tr><tr><td>GND<\/td><td><span class=\"rnthl rntcblack\">GND<\/span><\/td><\/tr><tr><td>SCL<\/td><td><span class=\"rnthl rntclgray\">GPIO 5<\/span><\/td><\/tr><tr><td>SDA<\/td><td><span class=\"rnthl rntcyellow\">GPIO 4<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Parts Required<\/h2>\n\n\n<div class=\"wp-block-image\">\n<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\/2023\/09\/Raspberry-Pi-Pico-BME280-circuit.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico parts required and connected to BME280 sensor\" class=\"wp-image-136809\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-BME280-circuit.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-BME280-circuit.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<p>For this project, you need to wire the BME280 sensor module to the Raspberry Pi Pico I2C pins. Here\u2019s a list of parts you need for this tutorial:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/bme280-sensor-module\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"BME280 sensor module\u2028 (opens in a new tab)\">BME280 sensor module<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-pico-w\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Raspberry Pi Pico board<\/a><\/li>\n\n\n\n<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>\n\n\n\n<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>\n<\/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=\"bme280-raspberry-pi-pico-circuit\">Wiring the BME280 to the Raspberry Pi Pico<\/h2>\n\n\n\n<p>Wire the BME280 to any <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-pinout-gpios\/#i2c\" title=\"\">combination of the Pico I2C pins<\/a>\u2014we&#8217;ll be using <span class=\"rnthl rntcyellow\">GPIO 4<\/span> (SDA) and <span class=\"rnthl rntclgray\">GPIO 5<\/span> (SCL) which are the default Raspberry Pi I2C pins when programmed with Arduino IDE.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"759\" height=\"684\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-BME280-circuit-diagram_bb.png?resize=759%2C684&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Wiring the BME280 to the Raspberry Pi Pico\" class=\"wp-image-136832\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-BME280-circuit-diagram_bb.png?w=759&amp;quality=100&amp;strip=all&amp;ssl=1 759w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-BME280-circuit-diagram_bb.png?resize=300%2C270&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 759px) 100vw, 759px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgreen\"><strong>Recommended reading:<\/strong> <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-pinout-gpios\/\">Raspberry Pi Pico and Pico W Pinout Guide: GPIOs Explained<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"bme280-library-raspberry-pi-pico-arduino-ide\">Installing the BME280 Library for Raspberry Pi Pico<\/h2>\n\n\n\n<p>To get readings from the BME280 sensor module, we&#8217;ll use the <a aria-label=\" (opens in a new tab)\" href=\"https:\/\/github.com\/adafruit\/Adafruit_BME280_Library\" target=\"_blank\" rel=\"noreferrer noopener\">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 in the Search box and install the library by Adafruit.<\/p>\n\n\n<div class=\"wp-block-image\">\n<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\/2023\/09\/install-adafruit-bme280-library-arduino-ide.png?resize=786%2C443&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Installing the BME280 Library for Raspberry Pi Pico\" class=\"wp-image-136872\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/install-adafruit-bme280-library-arduino-ide.png?w=786&amp;quality=100&amp;strip=all&amp;ssl=1 786w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/install-adafruit-bme280-library-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\/2023\/09\/install-adafruit-bme280-library-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<p>A pop-up window will open asking you to install the Adafruit Unified Sensor library. Install that library. If you don\u2019t get that pop-up window, you need to go to Sketch &gt; Include Library &gt; Manage Libraries and type \u201c<strong>adafruit unified sensor<\/strong>\u201d. Scroll down and install the Adafruit Unified Sensor library.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"bme280-raspberry-pi-pico-code\">BME280 Pressure, Temperature, and Humidity &#8211; Arduino Sketch<\/h2>\n\n\n\n<p>To show you how to read temperature, humidity, and pressure from the BME280, we&#8217;ll use a simple sketch that prints the current readings every second to the Serial Monitor. <\/p>\n\n\n\n<p>Copy the following code to the Arduino IDE. The following example is adapted from one of the examples provided by the <a href=\"https:\/\/github.com\/adafruit\/Adafruit_BME280_Library\" target=\"_blank\" rel=\"noopener\" title=\"\">Adafruit_BME280 library<\/a>.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\n  Rui Santos\n  Complete project details at https:\/\/RandomNerdTutorials.com\/raspberry-pi-pico-bme280-arduino\/\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n  Adapted from the Adafruit BME280 examples: https:\/\/github.com\/adafruit\/Adafruit_BME280_Library\n*********\/\n\n#include &lt;Wire.h&gt;\n#include &lt;Adafruit_Sensor.h&gt;\n#include &lt;Adafruit_BME280.h&gt;\n\n\/*#include &lt;SPI.h&gt;\n#define BME_SCK 18\n#define BME_MISO 19\n#define BME_MOSI 23\n#define BME_CS 5*\/\n\n#define SEALEVELPRESSURE_HPA (1013.25)\n\nAdafruit_BME280 bme; \/\/ I2C (default pins for Raspberry Pi Pico: GPIO 4 (SDA), GPIO 5(SCL)\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(115200);\n  Serial.println(&quot;BME280 with Raspberry Pi Pico&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(0x76);  \n  if (!status) {\n    Serial.println(&quot;Could not find a valid BME280 sensor, check wiring!&quot;);\n    while (1);\n  }\n\n  delayTime = 1000;\n\n  Serial.println();\n}\n\nvoid loop() { \n  printValues();\n  delay(delayTime);\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\/Raspberry-Pi-Pico\/Arduino\/BME280_Basic.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 <a href=\"#demonstration\" title=\"\">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, 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&gt;\n#include &lt;Adafruit_Sensor.h&gt;\n#include &lt;Adafruit_BME280.h&gt;<\/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>\/*#include &lt;SPI.h&gt;\n#define BME_SCK 18\n#define BME_MISO 19\n#define BME_MOSI 23\n#define BME_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 millibar). 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 Communication<\/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>. It will automatically use GPIO 4 as SDA and GPIO 5 as SCL.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Adafruit_BME280 bme; \/\/ I2C<\/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(115200);<\/code><\/pre>\n\n\n\n<p>The following lines initialize the sensor. Our sensor uses I2C address <strong>0x76<\/strong>. Most BME280 sensors will use that address, but if yours has a different one, make sure you modify that on the code.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>status = bme.begin(0x76); \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 rntclgreen\">You can follow this tutorial to find the address of your I2C devices: <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-i2c-scanner-arduino\/\">Raspberry Pi Pico: I2C Scanner (Arduino IDE) \u2013 Finding the Address of I2C Devices<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Printing Temperature, Humidity, and Pressure 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\">\n<li><span class=\"rnthl rntliteral\">bme.readTemperature()<\/span> &#8211; reads temperature in Celsius;<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">bme.readHumidity()<\/span> &#8211; reads absolute humidity;<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">bme.readPressure()<\/span> &#8211; reads pressure in hPa (hectoPascal = millibar);<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">bme.readAltitude(SEALEVELPRESSURE_HPA)<\/span> &#8211; estimates altitude in meters based on the pressure at the sea level.<\/li>\n<\/ul>\n\n\n\n<p>If you also want to display the temperature in Fahrenheit degrees, you need to uncomment the following lines of code:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/*Serial.print(\"Temperature = \");\nSerial.print(1.8 * bme.readTemperature() + 32);\nSerial.println(\" *F\");*\/<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Uploading the Code to the Raspberry Pi Pico<\/h2>\n\n\n\n<p>To upload code to the Raspberry Pi Pico, it needs to be in bootloader mode.<\/p>\n\n\n\n<p>If the Raspberry Pi is currently running MicroPython firmware, you need to manually put it into bootloader mode. For that, connect the Raspberry Pi Pico to your computer while holding the BOOTSEL button at the same time.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-Bottloader-mode.jpg?resize=750%2C422&amp;quality=100&amp;strip=all&amp;ssl=1\" alt=\"Raspberry Pi Pico Bootloader mode\" class=\"wp-image-130903\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-Bottloader-mode.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-Bottloader-mode.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<p>For future uploads using Arduino IDE, the board should go automatically into bootloader mode without the need to press the BOOTSEL button.<\/p>\n\n\n\n<p>Now, select your COM port in&nbsp;<strong>Tools&nbsp;<\/strong>&gt;&nbsp;<strong>Port<\/strong>. It may be the case that the COM port is grayed out. If that\u2019s the case, don\u2019t worry it will automatically find the port once you hit the upload button.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"595\" height=\"684\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-COM-port-not-showing.png?resize=595%2C684&amp;quality=100&amp;strip=all&amp;ssl=1\" alt=\"Raspberry Pi Pico - COM port not found Arduino IDE\" class=\"wp-image-132415\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-COM-port-not-showing.png?w=595&amp;quality=100&amp;strip=all&amp;ssl=1 595w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-COM-port-not-showing.png?resize=261%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 261w\" sizes=\"(max-width: 595px) 100vw, 595px\" \/><\/figure><\/div>\n\n\n<p>Upload the code.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"30\" height=\"30\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/arduino-2-0-upload-button.png?resize=30%2C30&amp;quality=100&amp;strip=all&amp;ssl=1\" alt=\"Arduino 2.0 Upload Button\" class=\"wp-image-103678\"\/><\/figure><\/div>\n\n\n<p>You should get a success message.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"595\" height=\"249\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/success-uploading-code-Rpi-pico.png?resize=595%2C249&amp;quality=100&amp;strip=all&amp;ssl=1\" alt=\"Done uploading Arduino IDE Raspberry Pi Pico\" class=\"wp-image-132414\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/success-uploading-code-Rpi-pico.png?w=595&amp;quality=100&amp;strip=all&amp;ssl=1 595w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/success-uploading-code-Rpi-pico.png?resize=300%2C126&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 595px) 100vw, 595px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"demonstration\">Demonstration<\/h2>\n\n\n\n<p>After uploading the code to the Raspberry Pi Pico board, open the Serial Monitor at a baud rate of 115200.<\/p>\n\n\n<div class=\"wp-block-image\">\n<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\/2023\/09\/raspberry-pi-pico-bme280.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico Circuit BME280 Temperature Humidity Pressure\" class=\"wp-image-136847\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/raspberry-pi-pico-bme280.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/raspberry-pi-pico-bme280.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<p>New sensor readings will be displayed in the Serial Monitor every second.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"385\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/BME280-raspberry-pi-pico-serial-monitor-arduino-ide.png?resize=601%2C385&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry pi pico with BME280 arduino ide demonstration \" class=\"wp-image-136874\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/BME280-raspberry-pi-pico-serial-monitor-arduino-ide.png?w=601&amp;quality=100&amp;strip=all&amp;ssl=1 601w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/BME280-raspberry-pi-pico-serial-monitor-arduino-ide.png?resize=300%2C192&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">Troubleshooting<\/h3>\n\n\n\n<p>Your BME280 is not working? It might be: incorrect wiring, wrong I2C address, broken sensor or you got a fake BME280 sensor. Take a look at this <a href=\"https:\/\/randomnerdtutorials.com\/solved-could-not-find-a-valid-bme280-sensor\/\" title=\"\">BME280 troubleshooting guide<\/a> to find the cause and solution for your problem.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>This tutorial was a quick getting started guide on how to get temperature, humidity, and pressure from a BME280 sensor with the Raspberry Pi Pico using Arduino IDE.<\/p>\n\n\n\n<p>We hope you&#8217;ve found this tutorial useful. We have tutorials for other popular environmental sensors:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-ds18b20-arduino\/\">Raspberry Pi Pico: <strong>DS18B20 Temperature Sensor<\/strong> (Arduino IDE) \u2013 Single and Multiple<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-dht11-dht22-arduino\/\">Raspberry Pi Pico: <strong>DHT11\/DHT22 Temperature and Humidity Sensor<\/strong> (Arduino IDE)<\/a><\/li>\n<\/ul>\n\n\n\n<p>You can check all our Raspberry Pi Pico projects on the following link:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-raspberry-pi-pico\/\" title=\"\"><strong>Free Raspberry Pi Pico Projects and Tutorials<\/strong><\/a><\/li>\n<\/ul>\n\n\n\n<p>Finally, if you would like to interface the BME280 with other microcontrollers, we have tutorials for ESP32, ESP8266, Arduino, and even for the Raspberry Pi board:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\" title=\"ESP32: Getting Started with the BME280 Sensor\"><strong>ESP32<\/strong>: Getting Started with the BME280 Sensor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-bme280-arduino-ide\/\" target=\"_blank\" rel=\"noopener\" title=\"\"><strong>ESP8266<\/strong>: Getting Started with the BME280 Sensor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/bme280-sensor-arduino-pressure-temperature-humidity\/\" title=\"\"><strong>Arduino<\/strong>: Getting Started with the BME280 Sensor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/micropython-bme280-esp32-esp8266\/\" title=\"\"><strong>ESP32\/ESP8266 (MicroPython)<\/strong>: Getting Started with the BME280 Sensor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-bme280-python\/\"><strong>Raspberry Pi<\/strong>: BME280 Temperature, Humidity and Pressure Sensor (<strong>Python<\/strong>)<\/a><\/li>\n<\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Get started quickly with the BME280 sensor module with the Raspberry Pi Pico board, programmed using the Arduino IDE, to get temperature, humidity, and pressure readings. This brief tutorial will &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Raspberry Pi Pico: BME280 Get Temperature, Humidity, and Pressure (Arduino IDE)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-bme280-arduino\/#more-136870\" aria-label=\"Read more about Raspberry Pi Pico: BME280 Get Temperature, Humidity, and Pressure (Arduino IDE)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":136871,"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":[324,325],"tags":[],"class_list":["post-136870","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-raspberry-pi-pico","category-raspberry-pi-pico-arduino-ide"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-BME280-Arduino-IDE.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\/136870","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=136870"}],"version-history":[{"count":8,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/136870\/revisions"}],"predecessor-version":[{"id":147551,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/136870\/revisions\/147551"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/136871"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=136870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=136870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=136870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}