{"id":13152,"date":"2017-02-05T16:21:45","date_gmt":"2017-02-05T21:21:45","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=13152"},"modified":"2023-04-11T22:17:09","modified_gmt":"2023-04-12T02:17:09","slug":"tutorial-6-esp8266-bme280-make-localremote-weather-station","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/tutorial-6-esp8266-bme280-make-localremote-weather-station\/","title":{"rendered":"Tutorial 6: ESP8266 and BME280 make a local\/remote weather station"},"content":{"rendered":"<p>In previous tutorials, we explored\u00a0how to connect an <strong><a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-3-connecting-oled-display-esp8266\/\" target=\"_blank\" rel=\"noopener noreferrer\">SSD1306-based I2C OLED<\/a><\/strong>\u00a0to ESP8266 for displaying texts and graphics, as well as to setup an <strong><a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-5-setting-esp8266-web-server\/\" target=\"_blank\" rel=\"noopener noreferrer\">ESP8266-based web server<\/a><\/strong>. This tutorial combines the knowledge gained before\u00a0to make a standalone weather station that will display the local weather data on an OLED screen. In addition, the weather station will also run a web server that would allow a remote computer to access\u00a0the weather data via web browser.<\/p>\n<div id=\"attachment_13158\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135929.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13158\" class=\"size-full wp-image-13158\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135929.jpg\" alt=\"dsds\" width=\"800\" height=\"571\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135929.jpg 800w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135929-580x414.jpg 580w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><p id=\"caption-attachment-13158\" class=\"wp-caption-text\">BME280 weather station<\/p><\/div>\n<h4>Hardware Setup<\/h4>\n<p>This project uses the <strong><a href=\"http:\/\/embedded-lab.com\/blog\/easyesp-1-rapid-prototyping-development-board-esp8266\/\" target=\"_blank\" rel=\"noopener noreferrer\">EasyESP-1 board<\/a><\/strong>\u00a0and the\u00a0following hardware devices.<\/p>\n<p><a href=\"https:\/\/www.elecrow.com\/crowtail-bme280-atmospheric-sensor-2518.html\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>BME280 sensor module<\/strong><\/a>: BME280 is a\u00a0fully integrated environmental unit from Bosch that combines sensors for pressure, humidity, and temperature in a tiny 8-pin metal-lid LGA package of size 2.5 x 2.5 x 0.93 mm\u00b3. Because of its compact size, ease of use (BME280 supports standard I2C and SPI interfaces), and availability of supporting open-source Arduino libraries, BME280 is very popular among weather enthusiasts. You can buy a BME280 sensor module in Grove form factor from <a href=\"https:\/\/www.elecrow.com\/crowtail-bme280-atmospheric-sensor-2518.html\" target=\"_blank\" rel=\"noopener noreferrer\">Elecrow<\/a>.<\/p>\n<p><a href=\"https:\/\/www.elecrow.com\/crowtail-oled-p-1276.html\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>SSD1306 I2C OLED module<\/strong><\/a>: As described in <strong><a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-3-connecting-oled-display-esp8266\/\" target=\"_blank\" rel=\"noopener noreferrer\">Tutorial 3<\/a><\/strong>, the SSD1306 OLED controller supports both SPI and I2C interfaces. We will use an I2C version with a 0.96&#8243; diagonal length and 128\u00d764 monochrome pixels OLED Grove\u00a0board. Despite its small size, the readability is pretty good due to its high contrast.<\/p>\n<p>For this experiment, the 4-pin Grove connectors of BME280 and OLED modules are directly plugged into the two I2C ports on the EasyESP-1 board,\u00a0as shown below. This connects the the\u00a0SDA and SCK pins of BME280 and OLED modules to D2 and D1 pins of EasyESP-1, respectively.<\/p>\n<div id=\"attachment_13156\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135816.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13156\" class=\"size-full wp-image-13156\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135816.jpg\" alt=\"Complete project setup\" width=\"800\" height=\"482\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135816.jpg 800w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135816-580x349.jpg 580w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><p id=\"caption-attachment-13156\" class=\"wp-caption-text\">Complete project setup<\/p><\/div>\n<div id=\"attachment_13155\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135711.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13155\" class=\"size-full wp-image-13155\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135711.jpg\" alt=\"BME280 and OLED connect to I2C Grove ports\" width=\"800\" height=\"637\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135711.jpg 800w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135711-580x462.jpg 580w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><p id=\"caption-attachment-13155\" class=\"wp-caption-text\">BME280 and OLED connections to I2C Grove ports<\/p><\/div>\n<h4>Software<\/h4>\n<p>The ESP8266 firmware for this project is developed using Arduino IDE. You need to install the <strong><a href=\"https:\/\/github.com\/esp8266\/Arduino\">ESP8266 core<\/a><\/strong> to enable the Arduino IDE for ESP8266 programming. Instructions can be found\u00a0<a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-1-setting-arduino-ide-easyesp-1\/\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>here<\/strong><\/a>.\u00a0You will also need the following Adafruit libraries for reading data from the BME280 sensor. The I2C address of BME280 sensor on Elecrow&#8217;s sensor board is 0x77, which is also the default address set in the Adafruit&#8217;s library.<\/p>\n<p><strong><a href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\" target=\"_blank\" rel=\"noopener noreferrer\">Adafruit unified sensor library<\/a><\/strong><\/p>\n<p><a href=\"https:\/\/github.com\/adafruit\/Adafruit_BME280_Library\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Adafruit BME280 library<\/strong><\/a><\/p>\n<p>Besides, you also need\u00a0<em>Daniel Eichhorn<\/em>&#8216;s OLED library for ESP8266. Read <strong><a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-3-connecting-oled-display-esp8266\/\" target=\"_blank\" rel=\"noopener noreferrer\">Tutorial 3<\/a><\/strong> for more details on this.<\/p>\n<p>The complete code for this weather station project can be downloaded from the following link:<\/p>\n<p><strong><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/BME280_Webserver_OLED.zip\">Download BME280 Weather Station Code<\/a><\/strong><\/p>\n<div id=\"tile1\" data-google-query-id=\"CN-2-Zjr-dECFY11YgodHDQOVg\">\n<p style=\"text-align: left;\">The code for a very basic HTML webpage with the BME280 sensor output and auto refresh meta tag is included in the code. Note that you need to edit\u00a0the SSID name and password in the program to match with your WiFi network before uploading it to the EasyESP-1 board.<\/p>\n<h3 style=\"text-align: left;\">Output<\/h3>\n<p style=\"text-align: left;\">After uploading the program to EasyESP-1, when the\u00a0ESP8266 restarts\u00a0it prints out on the\u00a0serial monitor\u00a0the local IP address that was allocated to it in the WiFi\u00a0network. The BME280 sensor readings for temperature, pressure and humidity are displayed on the OLED screen. In order to access these data over the web server, you need to open a web browser on any computer, tablet, or smartphone connected to the same WiFi network and type in the ESP8266\u00a0IP address in the URL field and hit enter. On receiving a client request, the ESP8266 serves a webpage containing\u00a0the BME sensor readings, as shown below.<\/p>\n<\/div>\n<div id=\"attachment_13157\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135913.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13157\" class=\"size-full wp-image-13157\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135913.jpg\" alt=\"BME280 local weather station\" width=\"800\" height=\"500\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135913.jpg 800w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/P_20170204_135913-580x363.jpg 580w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><p id=\"caption-attachment-13157\" class=\"wp-caption-text\">BME280 local weather station<\/p><\/div>\n<div id=\"attachment_13162\" style=\"width: 916px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/weather.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13162\" class=\"size-full wp-image-13162\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/weather.png\" alt=\"Web\" width=\"906\" height=\"628\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/weather.png 906w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/02\/weather-580x402.png 580w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/a><p id=\"caption-attachment-13162\" class=\"wp-caption-text\">Weather data displayed on client&#8217;s browser<\/p><\/div>\n<h4><a href=\"https:\/\/www.elecrow.com\/cde82664e.html\" target=\"_blank\" rel=\"noopener noreferrer\">Buy EasyESP-1 board<\/a><\/h4>\n<h4><strong><a href=\"https:\/\/www.elecrow.com\/crowtail-bme280-atmospheric-sensor-2518.html\" target=\"_blank\" rel=\"noopener noreferrer\">Buy BME280 sensor module<\/a>\u00a0<\/strong><\/h4>\n<h4><strong><a href=\"https:\/\/www.elecrow.com\/crowtail-oled-p-1276.html\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Buy SSD1306 I2C OLED module<\/strong><\/a><\/strong><\/h4>\n<h4>More tutorials<\/h4>\n<h5 class=\"post-title\"><a href=\"http:\/\/embedded-lab.com\/blog\/easyesp-1-rapid-prototyping-development-board-esp8266\/\" target=\"_blank\" rel=\"noopener noreferrer\">EASYESP-1: A RAPID PROTOTYPING AND DEVELOPMENT BOARD FOR ESP8266<\/a><\/h5>\n<h5 class=\"post-title\"><a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-1-setting-arduino-ide-easyesp-1\/\" target=\"_blank\" rel=\"noopener noreferrer\">TUTORIAL 1: SETTING UP THE ARDUINO IDE FOR EASYESP-1<\/a><\/h5>\n<h5 class=\"post-title\"><a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-2-easyesp-1-hello-world-example\/\" target=\"_blank\" rel=\"noopener noreferrer\">TUTORIAL 2: EASYESP-1 \u201cHELLO WORLD\u201d EXAMPLE<\/a><\/h5>\n<h5 class=\"post-title\"><a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-3-connecting-oled-display-esp8266\/\" target=\"_blank\" rel=\"noopener noreferrer\">TUTORIAL 3: CONNECTING AN OLED DISPLAY TO ESP8266<\/a><\/h5>\n<h5 class=\"post-title\"><a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-4-working-esp8266-wifi-scan-class\/\" target=\"_blank\" rel=\"noopener noreferrer\">TUTORIAL 4: WORKING WITH ESP8266 WIFI SCAN CLASS<\/a><\/h5>\n<h5 class=\"post-title\"><a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-5-setting-esp8266-web-server\/\" target=\"_blank\" rel=\"noopener noreferrer\">TUTORIAL 5: SETTING UP AN ESP8266 WEB SERVER<\/a><\/h5>\n","protected":false},"excerpt":{"rendered":"<p>In previous tutorials, we explored\u00a0how to connect an SSD1306-based I2C OLED\u00a0to ESP8266 for displaying texts and graphics, as well as to setup an ESP8266-based web server. This tutorial combines the knowledge gained before\u00a0to make a standalone weather station that will display the local weather data on an OLED screen. In addition, the weather station will also run a web server that would allow a remote computer to access\u00a0the weather data via web browser. Hardware Setup This project uses the EasyESP-1 board\u00a0and the\u00a0following hardware devices. BME280 sensor module: BME280 is a\u00a0fully integrated environmental unit from Bosch that combines sensors for pressure,<\/p>\n","protected":false},"author":1,"featured_media":13158,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1603,1044,1464,1467],"tags":[1623,1046],"class_list":["post-13152","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp8266-tutorials","category-esp8266","category-featured","category-projects","tag-bme280","tag-esp8266-project"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/13152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=13152"}],"version-history":[{"count":13,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/13152\/revisions"}],"predecessor-version":[{"id":15139,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/13152\/revisions\/15139"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/13158"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=13152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=13152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=13152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}