- 1 What the project consists of
- 2 The BME280 sensor
- 3 Connecting the BME280 to the NodeMCU
- 4 Connection of the BME280 to the Wemos D1 Mini
- 5 Connection to OLED display SSD1306
- 6 Connecting the BME280 to other microcontrollers
- 7 BME280 price and where to buy it
- 8 A variation, the BMP280 sensor
- 9 Configuration
- 10 Step-by-step video instructions
- 11 Practical advice
- 12 Integration with the Home CO2 Meter
In this tutorial we are going to see, step by step, how we can adding a temperature, humidity and atmospheric pressure sensor, BME280, to our ESP8266 project with NodeMCU or Wemos D1 Mini and ESPEasy.
It is a very simple project, ideal for beginnersbut which has been highly requested by regular readers of the blog, so here it is, in the hope that it will be useful for you too.
There are many temperature sensors, quite a few humidity sensors, some atmospheric pressure sensors, and fewer that combine all three and do all three. with a certain quality in their measurements. The BME280 is an example of the latter type.
Considering what it delivers, and how well it does it, the BME280 is a very economical and highly recommended sensor when we want to obtain these three environmental measures.
What the project consists of
This is a project that allows us to obtain measurements, with a fairly high degree of precision, of ambient temperature, relative humidity, and atmospheric pressure and display them on a web page, make graphs, send them to any system by means of MQTT, HTTP and others.
The project consists of only two components:
- A BME280 sensor, manufactured by Bosch.
- An ESP8266 board such as NodeMCU, Wemos D1 Mini or any other board.
On the firmware side, we will be using ESP Easy, which will allow us to do a whole host of things without the need for programming.
One of the advantages of ESP Easy (and my favouriteis that it enables us to connect to our project many different accessories without having to program or complicate our lives. with firmware modifications or adaptations.
The BME280 sensor
The BME280 sensor, as we are going to use it, comes on a tiny printed circuit board of less than one square centimetre.
This sensor allows temperature measurement in the range -40 to + 85 °C with an accuracy of ±1 °C and a resolution of 0.01 °C.
Its range as a barometer is 300hPa to 1110 hPa, equivalent to an altitude of -500m to 9000m above sea level (you can also use it as an altimeter). With an absolute accuracy of ±1.0C and 1.0 hPa, and relative pressure of 0.12 hPa, equivalent to an accuracy of approximately ±1m.
As a hygrometer, the BME280 has a relative humidity measurement range of 0 to 100%, with an accuracy of ±3% Pa and a resolution of 0.008%.
The sensor's very low power consumption of only 3.6 µA for measurements at 1Hz (once per second) means that the sensor can run for years and years on even a small battery. In deep sleep mode it consumes only 0.1 µA, which means that the sensor can run for years and years on even a small battery. could be powered for tens of years from a single button cell battery..
The module can communicate via I2C (up to 3,4 MHz) or SPI (up to 10 MHz), making it very easy to connect to a microprocessor such as the ESP8266, ESP32, Arduino and others.
In our case, we are going to communicate with it via I2C, which has the additional advantage of using only two pins of the ESP8266 (which we can also use at the same time to communicate with other I2C devices, all of which can be used to communicate with other I2C devices). connected in parallel), leaving many ESP8266 pins free for other uses.
The power supply voltage of the sensor is 1.8 to 3.6V, but is available in either 3.3V modules as well as 5V modulesThe power supply, such as the one we are going to use in this tutorial, already incorporates the necessary level matching. You could use a 3.3V power supply by simply connecting the power supply to the 3V3 pin of the NodeMCU or Wemos D1 Mini.
There is a physically identical sensor, called the BMP280, which does not include atmospheric pressure measurement in exchange for being cheaper.
These are the main characteristics of the BME280 sensor:
|Operating range||Pressure: 300...1100 hPa|
Temperature range: -40...85°C
|Supply voltage VDDIO|
Supply voltage VDD
|1.2 ... 3.6 V|
1.71 ... 3.6 V
|Interface||I²C and SPI|
|Average current consumption (typ.) (1Hz data refresh)||1.8 μA @ 1 Hz (H, T)|
2.8 μA @ 1 Hz (P, T)
3.6 μA @ 1 Hz (H, P, T)
T = temperature
|Average power consumption in sleep mode||0.1 μA|
Response time (τ63%)
±3% relative humidity
≤2% relative humidity
Temperature coefficient offset
0.2Pa (equiv. to 1.7cm)
±0.25% (equiv. to 1m at 400m change altitude)
±1.5Pa/K (equiv. to ±12.6cm at 1 °C temperature change)
|RoHS compliant, halogen-free, MSL1|
|Sensor dimensions||8-Pin LGA with metal|
2.5 x 2.5 x 0.93 mm³ 2.5 x 2.5 x 0.93 mm³ 2.5 x 2.5 x 0.93 mm³
Connecting the BME280 to the NodeMCU
The connection couldn't be easier. We have to make four connections. Two for power and two for data.
All we have to do is connect:
- VDD from BME280 to Vin of NodeMCU
- GND from BME280 to GND of NodeMCU
- SCL from BME280 to D2 of NodeMCU
- SDA from BME280 to D1 of NodeMCU
Click on the image for a larger view.
Be careful because the silkscreen on many NodeMCU boards is wrong and says D2 instead of D1 (there are two D1).
Obviously D1 is the one that is erroneously marked as D2 between D0 and "the other" D2.
IMPORTANT: Don't rely on the order of the connections and double check them on your board. Sometimes different manufacturers make such changes that can make our day, if we are not careful.
Connection of the BME280 to the Wemos D1 Mini
I leave you also the diagram with a plate Wemos D1 Miniif you prefer to do it with her.
Other boards will be very similar and you will probably have no problem fitting it yourself.
If you have any questions, feel free to ask below in the comments.
Click on the image for a larger view.
Connection to OLED display SSD1306
One of the advantages of devices with I2C BUS communication (and both the BME280 and the OLED display SSD1306 are I2C devices) is that their connection couldn't be simpler. All you have to do is connect the devices in parallel to make them work.
The big advantage is that you can have a lot of devices with only two wires and using only two pins of the microcontroller (leaving free pins for other things).
In the following image you can see an example with a BME280 and an OLED display SSD1306 connected together:
Please note that in this example both devices are powered at 5VIf your case is different (e.g. SSD1306 3.3V) you will have to adapt it and connect its power supply to the correct pin.
Connecting the BME280 to other microcontrollers
The connection to another board, other than the NodeMCU or the Wemos D1 Mini, based on ESP8266, or another board based on ESP32, will be very similar. We will only have to be watch out for the change in connections.
BME280 price and where to buy it
The BME280 sensor is fairly inexpensive (especially for what it offers).
There is various versions of the sensorThe two are very similar physically, but with some differences: different form of communication, different voltage, etc., so that make sure you buy the same sensoror you will have to adapt the tutorial to the sensor you have received.
You can buy the BME280 on AliExpress here:
If you prefer to buy it on Amazon and get it home quicklyEven if it costs a little more, you can do it here:
A variation, the BMP280 sensor
The BM sensorP280 is a scaled-down, cheaper version of the BME280. The main difference is that it does not have a relative humidity sensor, but it is cheaper.
If you don't need relative humidity data you can save some money.
The connection and configuration are exactly the same as for the BME280, so you can use this same tutorial.
- ✔️ The BMP280 atmospheric pressure sensor / barometer is a very accurate module for measuring atmospheric pressure and is ideal for determining temperature, weather, flight altitude and much more.
- ✔️ This air pressure sensor is the best low-cost solution for DIY projects! It is based on the Bosch BMP280 sensor and is much more accurate and efficient than its predecessor, the BMP180, which makes it suitable as an upgrade instead of the BMP085 and BMP183 sensors.
- ✔️ Thanks to its small dimensions of 3.6 x 3.8 x 0.93 mm and its low power consumption, this module is ideal for mobile devices. The atmospheric pressure measurement makes it possible, for example, to determine the altitude on the ground or the flight altitude of an RC multicopter.
- ✔️ The module can be controlled with I2C or SPI, is perfectly suitable for Raspberry Pi projects and has an operating voltage of 1.8V to 3.6V. With the free eBook 📖 from AZDelivery, you can start your project directly without having to spend a lot of time configuring the product.
- ✔️ This product includes an E-Book that provides useful information on how to start your project, helps with quick setup and saves time in the configuration process. We provide a number of application examples, comprehensive installation guides and libraries.
Here I will show you how to set up ESP Easy to use the sensor (use the video for now, it is well explained).
Step-by-step video instructions
Although the process is simple, and shouldn't give anyone too much trouble, I have recorded a video with step-by-step instructions for connecting the BME280 to the NodeMCU and configuring ESP Easy.
Here are some of them practical tipsThe following are basic, based on my experience with different sensors that you should comply with, yes or yesin order to obtain the better measures of the sensor.
No matter which sensor you are usingIf the sensor is mounted on the sensor, you have to take into account that there are some points concerning the mounting of the sensor that will cause that sensor to measure better or worse. Let's take a look at some of them:
- Make sure your sensor is sufficiently aired for to come into contact with the air that surrounds your assembly, but avoid draughts or large movements of air masses impacting directly on it.
- Keep it away from heat sources. Do not place it close to the microcontroller you are using, its power stage components or other sensors that may be in contact with the microcontroller. emit heat.
- Try to isolate it. In my assemblies with temperature sensors I usually create two distinct zones. One for the temperature sensor and a separate one for all other electronics.
What I usually do, for example, when I design the boxes, is to create a separate area to place the temperature sensorThe air communication with the rest of the enclosure where the other components are located is missing.
I take this opportunity to design it in such a way that the air currents cannot easily reach the sensor and I leave the just the right outlet to pass the cables through from the sensor to the microcontroller then sealing this outlet with a piece of foam, hot glue or similar.
Integration with the Home CO2 Meter
Here I will show you how to integrate it with the Home CO2 Meter I published previously.