{"id":108681,"date":"2022-01-05T16:13:21","date_gmt":"2022-01-05T16:13:21","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=108681"},"modified":"2022-01-05T16:13:23","modified_gmt":"2022-01-05T16:13:23","slug":"solved-could-not-find-a-valid-bme280-sensor","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/solved-could-not-find-a-valid-bme280-sensor\/","title":{"rendered":"[SOLVED] Could not find a valid BME280 sensor, check wiring!"},"content":{"rendered":"\n<p>This is a troubleshooting guide for the BME280 temperature, humidity, and pressure sensor when using ESP32, ESP8266, Arduino, or similar boards.<\/p>\n\n\n\n<p>If you get an error message in your Serial Monitor when trying to initialize the BME280 sensor, go through the following steps to understand what might be causing the issue and how to fix it.<\/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\/2022\/01\/BME280-troubleshooting.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"BME280 Sensor Troubleshooting Could not find a valid BME280 sensor check wiring\" class=\"wp-image-108689\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BME280-troubleshooting.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BME280-troubleshooting.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BME280-troubleshooting.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BME280-troubleshooting.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>If you get the following error <span style=\"color: #FF0000;\"><em>Could not find a valid BME280 sensor, check wiring!<\/em><\/span> when trying to initialize the BME280 sensor, it might be one of the following issues:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#wiring\">Incorrect wiring<\/a><\/li><li><a href=\"#check-i2c-address\">Wrong I2C address<\/a><\/li><li><a href=\"#broken-fried-sensor\">Broken\/fried sensor<\/a><\/li><li><a href=\"#fake-bme280\">Fake BME280 Sensor<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"wiring\">1. Check Wiring<\/h2>\n\n\n\n<p>BME280 sensor modules are available in different formats\u2014with 4 pins and with 6 pins.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4-pin model BME280<\/h3>\n\n\n\n<p>The models with 4 pins only allow I2C communication protocol like the module shown in the picture below.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><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 module 4 pin\" 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>You must wire the SDA and SCL pins to your microcontrollers&#8217; I2C pins. The following table shows the default I2C pins for the ESP32, ESP8266, and Arduino Uno boards:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BME280<\/strong><\/td><td><strong>ESP32<\/strong><\/td><td><strong>ESP8266<\/strong><\/td><td><strong>Arduino Uno<\/strong><\/td><\/tr><tr><td><strong>SCL<\/strong><\/td><td><span class=\"rnthl rntcyellow\">GPIO 22<\/span><\/td><td><span class=\"rnthl rntcyellow\">GPIO 5<\/span> (D1)<strong>*<\/strong><\/td><td><span class=\"rnthl rntcyellow\">A5<\/span><\/td><\/tr><tr><td><strong>SDA<\/strong><\/td><td><span class=\"rnthl rntclgray\">GPIO 21<\/span><\/td><td><span class=\"rnthl rntclgray\">GPIO 4<\/span> (D2)<strong>*<\/strong><\/td><td><span class=\"rnthl rntclgray\">A4<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"rntbox rntcred\"><strong>*<\/strong> in most ESP8266 development boards, GPIO 5 is labeled on the board as D1 and GPIO 4 as D2. For more information check the <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-pinout-reference-gpios\/\">ESP8266 pinout guide<\/a>. <\/p>\n\n\n\n<p>Besides the I2C pins, you should connect the VIN pin (also labeled VCC on some modules) to <span class=\"rnthl rntcred\">3.3V<\/span> and GND to the microcontroller&#8217;s <span class=\"rnthl rntcblack\">GND<\/span> pin.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6-pin model BME280 <\/h3>\n\n\n\n<p>There are models with 6 pins that support both I2C and SPI communication protocol.<\/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=\"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 module 6 pin\" 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 want to use I2C communication protocol with these models, you need to wire the sensor&#8217;s I2C pins to your microcontroller&#8217;s I2C pins. In this case, the SDI label corresponds to the SDA pin and the SCK to the SCL pin. <\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BME280<\/strong><\/td><td><strong>ESP32<\/strong><\/td><td><strong>ESP8266<\/strong><\/td><td><strong>Arduino Uno<\/strong><\/td><\/tr><tr><td><strong>SCL<\/strong> (SCK)<\/td><td><span class=\"rnthl rntcyellow\">GPIO 22<\/span><\/td><td><span class=\"rnthl rntcyellow\">GPIO 5<\/span> (D1)<strong>*<\/strong><\/td><td><span class=\"rnthl rntcyellow\">A5<\/span><\/td><\/tr><tr><td><strong>SDA<\/strong> (SDI)<\/td><td><span class=\"rnthl rntclgray\">GPIO 21<\/span><\/td><td><span class=\"rnthl rntclgray\">GPIO 4<\/span> (D2)<strong>*<\/strong><\/td><td><span class=\"rnthl rntclgray\">A4<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Besides the I2C pins, you should connect the VIN pin (also labeled VCC on some modules) to <span class=\"rnthl rntcred\">3.3V<\/span> and GND to the microcontroller&#8217;s <span class=\"rnthl rntcblack\">GND<\/span> pin.<\/p>\n\n\n\n<p>If you want to use SPI communication protocol, you need to connect the sensor&#8217;s SPI pins to your microcontroller&#8217;s SPI pins. The following table shows the connection to the default SPI pins.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BME280<\/strong><\/td><td><strong>ESP32<\/strong><\/td><td><strong>ESP8266<\/strong><\/td><td><strong>Arduino Uno<\/strong><\/td><\/tr><tr><td><strong>SCK (SPI Clock)<\/strong><\/td><td><span class=\"rnthl rntcblue\">GPIO 18<\/span><\/td><td><span class=\"rnthl rntcblue\">GPIO 14<\/span> (D5)<\/td><td><span class=\"rnthl rntcblue\">Pin 13<\/span><\/td><\/tr><tr><td><strong>SDO (MISO)<\/strong><\/td><td><span class=\"rnthl rntcyellow\">GPIO 19<\/span><\/td><td><span class=\"rnthl rntcyellow\">GPIO 12<\/span> (D6)<\/td><td><span class=\"rnthl rntcyellow\">Pin 12<\/span><\/td><\/tr><tr><td><strong>SDI (MOSI)<\/strong><\/td><td><span class=\"rnthl rntcgreen\">GPIO 23<\/span><\/td><td><span class=\"rnthl rntcgreen\">GPIO 13<\/span> (D7)<\/td><td><span class=\"rnthl rntcgreen\">Pin 11<\/span><\/td><\/tr><tr><td><strong>CS (Chip Select)<\/strong><\/td><td><span class=\"rnthl rntcbrown\">GPIO 5<\/span><\/td><td><span class=\"rnthl rntcbrown\">GPIO 15<\/span> (D8)<\/td><td><span class=\"rnthl rntcbrown\">Pin 10<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Besides the I2C pins, you should connect the VIN pin (also labeled VCC on some modules) to <span class=\"rnthl rntcred\">3.3V<\/span> and GND to the microcontroller&#8217;s <span class=\"rnthl rntcblack\">GND<\/span> pin.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"check-i2c-address\">2. Check I2C Address<\/h2>\n\n\n\n<p>If you&#8217;re using I2C communication protocol, and your board can&#8217;t find the BME280 sensor, it might be the case that you&#8217;re not using the correct I2C address. Usually, the BME280 I2C sensor is <span class=\"rnthl rntliteral\">0x76<\/span>, but it might be different. So, we recommend running an <a href=\"https:\/\/raw.githubusercontent.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/master\/Projects\/LCD_I2C\/I2C_Scanner.ino\" target=\"_blank\" rel=\"noreferrer noopener\">I2C scanner<\/a> sketch to find the sensor&#8217;s I2C address.<\/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  \n*********\/\n\n#include &lt;Wire.h&gt;\n \nvoid setup() {\n  Wire.begin();\n  Serial.begin(115200);\n  Serial.println(&quot;\\nI2C Scanner&quot;);\n}\n \nvoid loop() {\n  byte error, address;\n  int nDevices;\n  Serial.println(&quot;Scanning...&quot;);\n  nDevices = 0;\n  for(address = 1; address &lt; 127; address++ ) {\n    Wire.beginTransmission(address);\n    error = Wire.endTransmission();\n    if (error == 0) {\n      Serial.print(&quot;I2C device found at address 0x&quot;);\n      if (address&lt;16) {\n        Serial.print(&quot;0&quot;);\n      }\n      Serial.println(address,HEX);\n      nDevices++;\n    }\n    else if (error==4) {\n      Serial.print(&quot;Unknow error at address 0x&quot;);\n      if (address&lt;16) {\n        Serial.print(&quot;0&quot;);\n      }\n      Serial.println(address,HEX);\n    }    \n  }\n  if (nDevices == 0) {\n    Serial.println(&quot;No I2C devices found\\n&quot;);\n  }\n  else {\n    Serial.println(&quot;done\\n&quot;);\n  }\n  delay(5000);          \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\/LCD_I2C\/I2C_Scanner.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>After getting the I2C sensor address, make sure you use the right address in your code. For example, in most of our projects, we use the Adafruit BME280 library. In that case, we must pass the address to the <span class=\"rnthl rntliteral\">begin()<\/span> method as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>bme.begin(<strong>YOUR_SENSOR_I2C_ADDRESS<\/strong>)<\/code><\/pre>\n\n\n\n<p>If the I2C scanner sketch returns <span class=\"rnthl rntliteral\">0x76<\/span> or any other address and you still can&#8217;t get it working, go to <a href=\"#fake-bme280\">issue 4<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"broken-fried-sensor\">3. Broken\/fried Sensor<\/h2>\n\n\n\n<p>If your microcontroller can&#8217;t find the sensor&#8217;s I2C address and you&#8217;re sure the wiring is correct, you probably have a hardware problem: <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>your sensor might be broken;<\/li><li>faulty wires;<\/li><li>insufficient power supply; <\/li><\/ul>\n\n\n\n<p>We recommend checking all the wiring again.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"fake-bme280\">4. Fake BME280 Sensor (BMP280)<\/h2>\n\n\n\n<p>Some vendors sell BMP280 sensor modules as BME280. It is very difficult to tell the difference between them when buying because they are very similar. BME280 sensors are usually more expensive than BMP280 sensors. The downside of having a BMP280 is that it doesn&#8217;t measure humidity, it only measures temperature and pressure.<\/p>\n\n\n\n<p>How to tell if you got a BMP280 sensor? In the following picture, you can see that the BME280 sensor chip is square-shaped, while the BMP280 is more like a rectangle shape. <\/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=\"366\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BMP280vsBME280.jpg?resize=750%2C366&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"BMP280 vs BME280\" class=\"wp-image-108686\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BMP280vsBME280.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BMP280vsBME280.jpg?resize=300%2C146&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>To be sure that you have a BMP280 sensor, you can install a library compatible with the BMP280 sensor and run an example sketch.<\/p>\n\n\n\n<p>I usually recommend installing the <a href=\"https:\/\/github.com\/adafruit\/Adafruit_BMP280_Library\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit BMP280 library<\/a> and running the <a href=\"https:\/\/github.com\/adafruit\/Adafruit_BMP280_Library\/blob\/master\/examples\/bmp280test\/bmp280test.ino\" target=\"_blank\" rel=\"noreferrer noopener\">bmp280test sketch that you can find here<\/a>. <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Library: <a href=\"https:\/\/github.com\/adafruit\/Adafruit_BMP280_Library\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit BMP280 Library<\/a><\/li><li>Sketch: <a href=\"https:\/\/github.com\/adafruit\/Adafruit_BMP280_Library\" target=\"_blank\" rel=\"noreferrer noopener\">bmp280test.ino<\/a><\/li><\/ul>\n\n\n\n<p>You can use the sketch straight away if you&#8217;re using I2C communication protocol, or if you want to use SPI, you need to modify the sketch to use the right SPI pins.<\/p>\n\n\n\n<p>If you got it working with the BMP280 test sketch, it means you have a BMP280 and not a BME280.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this article, we&#8217;ve described the most common issues that might cause the &#8220;<em>Could not find a valid BME280 sensor, check wiring<\/em>!&#8221; error when using a BME280 sensor with the ESP32, ESP8266, Arduino, or other development boards.<\/p>\n\n\n\n<p>We hope you were able to solve your issue with our tips.<\/p>\n\n\n\n<p>We have many BME280 sensor guides that you might find useful:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\">ESP32 with BME280 Sensor using Arduino IDE (Pressure, Temperature, Humidity)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-bme280-arduino-ide\/\">ESP8266 with BME280 using Arduino IDE (Pressure, Temperature, Humidity)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/bme280-sensor-arduino-pressure-temperature-humidity\/\">Guide for BME280 Sensor with Arduino (Pressure, Temperature, Humidity)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/micropython-bme280-esp32-esp8266\/\">MicroPython: BME280 with ESP32 and ESP8266 (Pressure, Temperature, Humidity)<\/a><\/li><\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a troubleshooting guide for the BME280 temperature, humidity, and pressure sensor when using ESP32, ESP8266, Arduino, or similar boards. If you get an error message in your Serial &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"[SOLVED] Could not find a valid BME280 sensor, check wiring!\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/solved-could-not-find-a-valid-bme280-sensor\/#more-108681\" aria-label=\"Read more about [SOLVED] Could not find a valid BME280 sensor, check wiring!\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":108689,"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":[305],"tags":[],"class_list":["post-108681","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-other"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BME280-troubleshooting.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\/108681","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=108681"}],"version-history":[{"count":17,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/108681\/revisions"}],"predecessor-version":[{"id":108721,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/108681\/revisions\/108721"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/108689"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=108681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=108681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=108681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}