ESP8266 BME280 IoT Weather Station using Blynk App

ESP8266 & BME280 IoT Weather Station

ESP8266 IoT Projects

Today in this tutorial, we will learn to interface the BME280 sensor with the NodeMCU ESP8266 development board, then Monitors its parameters like temperature, humidity, barometric pressure, altitude, and dew point on the Blynk IoT Platform. This IoT Project provides your NodeMCU ESP8266 board the ability to sense the environment with a BME280 Barometric Pressure sensor. Overall, we are building ESP8266 & BME280 based IoT Weather Station.

The BME280 is a widely used sensor that measures temperature, humidity, barometric pressure, dew point, and altitude. Actually, it is pre-calibrated and is relatively simple to use. Because you don’t require any extra components. So you can start measuring its data using NodeMCU ESP8266 and BME280 sensor.


Components Required

The following are the lists of the components that are required for ESP8266 & BME280 IoT Weather Station.

S.NComponents NameDescriptionQuantityGet Products from Amazon
1NodeMCUESP8266 12E Board1https://amzn.to/3mTuL95
2BME280Barometric Pressure Sensor1https://amzn.to/38s2WPo
3Jumper WiresMale to Male Jumper Wires4https://amzn.to/2JWSR44
4BreadboardSolderless Breadboard MIni1https://amzn.to/3n33uRT

Introduction to BME280 Sensor

The BME280 sensor contains Bosch next-generation digital temperature, humidity, and pressure sensor. It is the successor of the sensors like BMP180, BMP280, or BMP183.

BME280 Sensor Measures

As I already mentioned above, The BME280 is a Five in one Environmental digital sensor that measures:

BME280 Barometric pressure sensor
  • Temperature
  • Humidity
  • Barometric pressure
  • Altitude
  • Dew Point

Accuracy and Operation Range of BME280 Sensor

The following table shows the Accuracy and operation range of the temperature, humidity, pressure, and altitude of the BME280 Sensor:

SensorAccuracyOperation Range
Temperature+/- 1.0ºC-40 to 85 ºC
Humidity+/- 3%0 to 100 %
Pressure+/- 1 hPa300 to 1100 hPa
Altitude+/- 1 M0 – 30,000ft
Dew Point+/- 1.5ºCDepends on Temperature & Humidity

Note: Dew Point is measured using temperature and relative humidity parameters. Through some mathematical calculations, the program returns the dew point in Celsius.

BME280 Sensor Pinout

The following table is the BME280 sensor Pinout table:

BME280 Sensor
VCCPowers the sensor
GNDGround Pin
SCLSCL pin for I2C communication
SDASDA pin for I2C communication
CSBChip select pin for SPI communication
SDOSDO/MISO pin for SPI communication

Recommended Readings


Circuit Diagram For ESP8266 & BME280 IoT Weather Station

Now, Let’s wire the BME280 sensor with the NodeMCU ESP8266. The Connections are fairly simple. Start by connecting the VIN pin to the 3.3V output on the NodeMCU and connect GND to the Ground Pin.

We use now the remaining SCL and SDA pins for I2C communication. Connect the SCL pin to GPIO 05 and the SDA pin to the GPIO 04 pin of NodeMCU ESP8266 Module, respectively.

BME280 Based Mini Weather Station using ESP8266
BME280ESP8266 NodeMCU
Vin3.3V
GNDGND
SCLGPIO 05 (D1)
SDAGPIO 04 (D2)


Programming ESP8266 & BME280 Sensor

To program the ESP8266 & BME280 sensor with Arduino IDE, we need to install the NodeMCU board Manager add-on and the following libraries.

Preparing Arduino IDE For ESP8266 & BME680

Actually, We’ll program the ESP8266 board using Arduino IDE. So, make sure you have the ESP8266 add-on installed.

Basically, to compile this program we also need to install the Adafruit BME280 library and the Adafruit Unified Sensor library.

Installing Adafruit BME280 and Adafruit Unified Sensor Library

To install the library, navigate to the Sketch > Include Library > Manage Libraries… Wait some time for Arduino IDE to update the list of installed libraries.

Now in the search field search for “Adafruit BME280” and install the library as shown in the image below. 

Installing Adafruit BME280 sensor library

Secondly, search for “Adafruit Unified Sensor” and install that library as well.

Installing Adafruit unified sensor library

Finally, search for “Blynk Library” and install it as well.

Check the Default I2C address for BME280 Sensor

To check the default I2C address of your BME280 sensor with NodeMCU. Simply upload the I2C Address Scanner code provided below. Now, open the serial monitor to check your BME280 default I2C address. This code will also help you to check your sensor working or not. 

// I2C address Scanner code  
#include <wire.h>  
 void setup()
 {
   Wire.begin();
 Serial.begin(9600);
   while (!Serial);             // Leonardo: wait for serial monitor
   Serial.println("I2C Scanner");
 }
 void loop()
 {
   byte error, address;
   int nDevices;
 Serial.println("Scanning…");
 nDevices = 0;
   for (address = 1; address < 127; address++ )
   {
     // The i2c_scanner uses the return value of
     // the Write.endTransmisstion to see if
     // a device did acknowledge to the address.
     Wire.beginTransmission(address);
     error = Wire.endTransmission();
 if (error == 0) {   Serial.print("I2C device found at address 0x");   if (address < 16)     Serial.print("0");   Serial.print(address, HEX);   Serial.println("  !");   nDevices++; } else if (error == 4) {   Serial.print("Unknown error at address 0x");   if (address < 16)     Serial.print("0");   Serial.println(address, HEX); }
 }
   if (nDevices == 0)
     Serial.println("No I2C devices found");
   else
     Serial.println("done");
 delay(5000);           // wait 5 seconds for next scan
 }
Default I2C address scanner for BME280

Configure Blynk App for ESP8266 based BME280 Weather Station

To set up a Blynk IoT App for Wireless Weather Station you need to first download the app from the Play Store for Android users and the App Store for iOS users. Once the installation is complete, open the app and sign-up using your email address and password.

  • Click on create a new project
  • Provide the Name of your project as “BME280 IoT Weather Station
  • Choose NodeMCU Dev Board
  • Select connection type as Wi-Fi, then click on Create Button.
  • The Blynk authentication token is sent to your email address. (We need it later on programming)
ESP8266 and DHT11 weather station on blynk app
  • Now, click on the (+) icon at the top right corner of the screen.
  • Search for “Gauges” and add 5 of them to your main screen.
  • Click on the First Gauge.
  • Name it as “Temperature
  • Set the Input Pin to Virtual Pin V1, Enter input Range & Choose the refresh rate as 1sec.
Temperature Gauge Settings for Weather Station

Similarly, do the same for Humidity, Pressure, Altitude, and Dewpoint, with the help of the images below.

  • Pressure Gauge Settings for BME280 IoT Weather Station
  • Humidity Gauge Settings for IoT Weather Station
  • Altitude Gauge Settings for Weather Station
  • Dew Point Gauge Settings for IoT BME280 Weather Station
  • Add Gauges to Blynk App
  • BME280 Live weather station on Blynk

Finally, the Blynk App setup for IoT based BME280 Wireless weather station using NodeMCU ESP8266 is completed.

When the code is uploaded, ESP8266 will connect to the Blynk server. Now you can check the Blynk app on your mobile phone. The mobile phone receives BME280 weather station data.


Program Code for BME280 IoT Weather Station using ESP8266

Firstly, the code starts by including the required libraries: Wire.h Library to use the I2C communication protocol. Secondly, Adafruit_Sensor and Adafruit_BME680 libraries to read data from BME680 sensors. Thirdly, Blynk.h to connect our device to Blynk IoT Cloud. Finally, ESP8266WiFi.h is used to connect the NodeMCU ESP8266 board to our WiFi Network.

 #include <Wire.h>
 #include <Adafruit_Sensor.h>
 #include <Adafruit_BME280.h>
 #include <Blynk.h>
 #include <ESP8266WiFi.h>
 #include <BlynkSimpleEsp8266.h>

Change the WiFi credentials and the Blynk Authentication token that you have received on your email address.

char auth[] = "XXXXXX-XXXX-XXXX";       // You should get Auth Token in the Blynk App.
 char ssid[] = "XXXXXX-XXXX-XXXX";                       // Your WiFi credentials.
 char pass[] = "XXXXXX-XXXX-XXXX";

Defined I2C communication protocol with BME280 sensor.

Adafruit_BME280 bme; // For I2C interface

In the Setup part, first, we start a serial communication. Second, start the Blynk IoT cloud account authentication process. Third, Initialize the BME280 barometric pressure sensor.

void setup() {
   Serial.begin(9600);
   Blynk.begin(auth, ssid, pass);
  
   Serial.println(F("BME280 Sensor event test"));
   if (!bme.begin(0x76))
   {
     Serial.println("Could not find a valid BME280 sensor, check wiring!");
     while (1);
   }
  
 }

In a loop, we initiate the blynk library and also start to read data from the BME280 sensor.

  • bme.readTemperature: provides a temperature reading
  • bme.readPressure: provides a pressure reading
  • bme.readHumidity: provides humidity reading
  • bme.readAltitude: provides Approx. Altitude
  • dewPointFast(temperature, humidity): Provides Dew Point
void loop() {
   Blynk.run(); // Initiates Blynk
     temperature = bme.readTemperature();
     pressure = bme.readPressure() / 100.0F;
     humidity = bme.readHumidity();
     altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
     double dewPoint = dewPointFast(temperature, humidity);
 Serial.print("Temperature = ");
   Serial.print(temperature);
   Serial.println("*C");
 Serial.print("Pressure = ");
   Serial.print(pressure);
   Serial.println("hPa");
 Serial.print("Humidity = ");
   Serial.print(humidity);
   Serial.println("%");
 Serial.print("Approx. Altitude = ");
   Serial.print(altitude);
   Serial.println("m");
 Serial.print("Dew point = ");
   Serial.print(dewPoint);
   Serial.println(" *C");

Finally, send the Temperature, Pressure, Humidity, Altitude, and Dew point parameters to Blynk IoT Application using Blynk.virtualWrite function.

     Blynk.virtualWrite(V1, temperature); // For Temperature
     Blynk.virtualWrite(V2, pressure); // For Pressure
     Blynk.virtualWrite(V3, humidity); // For Humidity
     Blynk.virtualWrite(V4, altitude); //For Approx. Altitude
     Blynk.virtualWrite(V5, dewPoint); // For DewPoint

Calculating Dew Point.

double dewPointFast(double celsius, double humidity)
 {
   double a = 17.271;
   double b = 237.7;
   double temp = (a * celsius) / (b + celsius) + log(humidity * 0.01);
   double Td = (b * temp) / (a - temp);
   return Td;
 }

Final Program Code

 #include <Wire.h>
 #include <Adafruit_Sensor.h>
 #include <Adafruit_BME280.h>
 #include <Blynk.h>
 #include <ESP8266WiFi.h>
 #include <BlynkSimpleEsp8266.h>
 char auth[] = "aPeEKgUWvrgcyC-z1WAFVwpou7oIhHAx";       // You should get Auth Token in the Blynk App.
 char ssid[] = "The IoT Projects";                       // Your WiFi credentials.
 char pass[] = "XXXXXX-XXXX-XXXX";
 float temperature;
 float pressure;
 float humidity;
 float altitude;
 define SEALEVELPRESSURE_HPA (1013.25)
 Adafruit_BME280 bme; // For I2C interface
 void setup() {
   Serial.begin(9600);
   Blynk.begin(auth, ssid, pass);

   Serial.println(F("BME280 Sensor event test"));
   if (!bme.begin(0x76))
   {
     Serial.println("Could not find a valid BME280 sensor, check wiring!");
     while (1);
   }

 }
 void loop() {
   Blynk.run(); // Initiates Blynk

     temperature = bme.readTemperature();
     pressure = bme.readPressure() / 100.0F;
     humidity = bme.readHumidity();
     altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
     double dewPoint = dewPointFast(temperature, humidity);

 Serial.print("Temperature = ");
   Serial.print(temperature);
   Serial.println("*C");
 Serial.print("Pressure = ");
   Serial.print(pressure);
   Serial.println("hPa");
 Serial.print("Humidity = ");
   Serial.print(humidity);
   Serial.println("%");
 Serial.print("Approx. Altitude = ");
   Serial.print(altitude);
   Serial.println("m");
 Serial.print("Dew point = ");
   Serial.print(dewPoint);
   Serial.println(" *C");
 Serial.println();
     Blynk.virtualWrite(V1, temperature); // For Temperature
     Blynk.virtualWrite(V2, pressure); // For Pressure
     Blynk.virtualWrite(V3, humidity); // For Humidity
     Blynk.virtualWrite(V4, altitude); //For Approx. Altitude
     Blynk.virtualWrite(V5, dewPoint); // For DewPoint
   delay(1000);
 }
 double dewPointFast(double celsius, double humidity)
 {
   double a = 17.271;
   double b = 237.7;
   double temp = (a * celsius) / (b + celsius) + log(humidity * 0.01);
   double Td = (b * temp) / (a - temp);
   return Td;
 }

Finally, copy the above program code on your Arduino IDE. Now select your correct NodeMCU board and correct COM port from Tools Menu. After successfully compiling the above code without any errors. Upload it to your NodeMCU ESP8266 board.

Open the serial monitor at the baud rate of 9600 and press the RST button on the NodeMCU board to see the BME280 sensor data on Serial Monitor.


Demonstration: BME680 Environment Monitoring System with ESP8266

After uploading the code, open Serial Monitor at a baud rate of 9600 to get BME280 Weather Station data.

Read BME280 sensor data on serial Monitor

Meanwhile, ESP8266 NodeMCU will now connect to the Blynk server. Now you can check the Blynk app on your mobile phone. The newly created Blynk IoT Weather Station using ESP8266 and BME280 start receiving wireless weather station data.

BME280 Live weather station on Blynk

Wrapping Up

In this tutorial, we built ESP8266 & BME280 IoT Weather Station on Blynk. This project is very helpful for monitoring our internal (home) environment wirelessly. I hope you enjoyed reading this article. If you have any questions, comments, or ideas? Let me know in the comment section below.

Alsan Parajuli

I am a WordPress enthusiast, a hardworking and highly positive person. I always believes in practicality rather than theoretical knowledge. With my curiosity and fast learning skills, I managed to learn everything on my own. I love coding, editing, writing and rummaging around Internet. I am passionate about IoT Projects, Digital marketing, website designing, and reviewing. Moreover, I had been contributing to WordPress Biratnagar as an active member since 2018.

https://theiotprojects.com/

2 thoughts on “ESP8266 & BME280 IoT Weather Station

Leave a Reply