member
Basics: Project 086b ESP8266 ESP-12E module, BME280 sensor - Thingspeak
of Acoptex.com in ESP8266 ESP-12
Basics: Project 086b
Project name: ESP8266 ESP-12E module, BME280 sensor - Thingspeak
Tags: Arduino, Arduino IDE, ESP8266 ESP-12E module, ESP, ESP8266, WI FI module, ESP-12E, LoLin NODEMCU V3, NODEMCU, BME280, BME280 sensor, humidity, temperature, pressure, altitude, GY-BME280, Digital Sensor, SPI I2C Humidity Temperature and Barometric Pressure Sensor Module, GY-BME280-3.3, Thingspeak
Attachments: I2Cscannersketch,MATLAB.txt,sketch,library1and library2
ESP8266-NodeMCU-12E-with-BME280-master.zip
In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):
1.ESP8266 ESP-12E module with micro USB cable 1pc
2. Jumper cables F-M
3. Breadboard 1 pc
4. BME280 sensor module 1 pc
General
We will learn how to use ESP8266 ESP-12E module with BME280 sensor module.
Understanding the ESP8266 ESP-12E WI FI module (LoLin NODEMCU V3)
You can read more about it here.
Understanding the BME280 module
The BME280 is the next-generation of sensors from Bosch, and is the upgrade to the BMP085/BMP180/BMP183 - with a low altitude noise of 0.25m and the same fast conversion time.
The BME280 sensor module reads temperature, humidity, and pressure. You can also estimate altitude as the pressure changes with altitude.
The sensor can communicate using either SPI (supports 3-, 4-wire SPI) or I2C communication protocols (there are modules of this sensor that just communicate with I2C, these just come with four pins).
The sensor comes with an on-board LM6206 3.3V regulator and I2C Voltage Level Translator, so you can use it with a 3.3V or 5V logic microcontroller like Arduino without worry.
The BME280 consumes less than 1mA during measurements and only 5μA during idle. This low power consumption allow the implementation in battery driven devices such as handsets, GPS modules or watches.
Specifications:
- Supply Voltage: 1.8 - 5V DC
- Interface: I2C (up to 3.4MHz), SPI (up to 10 MHz)
- Operational Range: Temperature: -40 to +85° C
- Humidity: 0-100%
- Pressure: 300-1100 hPa
- Resolution:Temperature: 0.01°C Humidity: 0.008% Pressure: 0.18Pa
- Accuracy:Temperature: +-1°C Humidity: +-3% Pressure: +-1Pa
- I2C address SDO LOW : 0x76 SDO HIGH: 0x77
The module features a simple two-wire I2C interface which can be easily interfaced with any microcontroller of your choice. The default I2C address of the BME280 module is 0x76 and can be changed to 0x77 easily with the solder jumper besides chip.
How to change I2C Address?
- Locate the solder jumper besides chip. By default the middle copper pad is connected to the left pad.
- Scratch the connection between the middle and the left copper pad to disconnect those using a sharp knife.
- Add a solder blob between the middle and the right copper pad to join them. It allows you to set the I2C address 0x77.
To use SPI communication protocol, you must have the following pins:
VIN - power supply 3.3V DC
GND - ground
CLK (or SCK or SCL) (Serial Clock) - The clock pulses which synchronize data transmission generated by the master
MISO (or DO or SO or SDO) (Master In Slave Out) - The Slave line for sending data to the master
MOSI (or DI or SI or CMD or SDI or SDA) (Master Out Slave In) - The Master line for sending data to the peripherals
CS (or SS or D3 or CSB) (Chip Select or Slave Select) - the pin on each device that the master can use to enable and disable specific devices
If your BME280 sensor module has 4 pins it can use I2C communication protocol only:
VIN - power supply 3.3V DC
GND - ground
SDA - Serial Data Line
SCL - Serial Clock Line
TX - transmit pin. GPIO pin
RX - receive pin. GPIO pin
3V3 (or 3V or 3.3V) - power supply pin (3-3.6V).
GND ( or G) - ground pin.
RST - reset pin. Keep it on high (3.3V) for normal operation. Put it on 0V to reset the chip.
EN - Chip enable. Keep it on high (3.3V) for normal operation.
Vin - External power supply 5VDC.
D0-D8 - GPIO (General Purpose Input Output) pins
D5-D8 - SPI interface
D1-D2– I²C/TWI Interface
SC (or CMD) - (Chip Select) - the pin that the master can use to enable and disable specific devices. GPIO pin
SO (or SDO) - Master In Slave Out (MISO) - SPI communication. The Slave line for sending data to the master. GPIO pin
SK (or CLK) - SCK (Serial Clock) - SPI communication.The clock pulses which synchronize data transmission generated by the master. GPIO pin
S1 (or SD1) - Master Out/Slave In (MOSI). SPI communication. The Master line for sending data to the peripherals. GPIO pin
S2 (or SD2) - GPIO pin
S3 (or SD3) - GPIO pin
VU (or VUSB) - external power 5VDC.
A0 - ADC output.
RSV - reserved
Wiring
BME280 sensor Nodemcu 1.0
GND G (GND)
VIN 3V3
SCL D4 (GPIO 2)
SDA D3 (GPIO 0)
Step by Step instruction
1. Adding ESP8266 platform to Arduino IDE
The Arduino environment has to be set up to make it compatible with the ESP8266 ESP-12E module. We are using PC with Windows 7 64 bit OS.
- Download and install the Arduino IDE. You can download it here
- Open Arduino IDE.
- Open the Preferences window from the Arduino IDE. Go to File -> Preferences.
- Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field and click the “OK” button. If you already have a URL in there, and want to keep it, you can separate multiple URLs by placing a comma between them. (Arduino 1.6.5 added an expanded text box, separate links in here by line.)
- Open Boards manager. Go to Tools -> Board -> Boards Manager…
- There should be a couple new entries in addition to the standard Arduino boards. Look for esp8266. or scroll down to the ESP8266 entry (usually at the bottom). Select the ESP8266 entry. When you click it an install option will appear. Select the latest version and click install.
- The board definitions and tools for the ESP8266 include a whole new set of gcc, g++, and other reasonably large, compiled binaries, so it may take a few minutes to download and install (the archived file is ~110MB). Once the installation has completed, an Arduino-blue “INSTALLED” will appear next to the entry.
2. Registering with Thing Speak and creating a channel
Thing Speak (ThingSpeak.com) allows you to send and publish your sensor readings to their website and display them in a plot with time stamps. You can access your readings from anywhere in the world. Of course this project can be easily modified to publish the values to your home automation hub or another application instead of Thing Speak.
We will show you how you can put your ESP8266 in deep sleep mode, publishing a value every 24 hours.
- Go to ThingSpeak.com
- If you don’t have an account on Thing Speak you need to make it. Enter your email address, User ID, password, first name, last name and select the place you leave. Tick on box for I accept Online Services Agreement:
- Press Continue button. Email will be automatically sent to your email address.
- Go to your inbox for your email address.
- Click on the link in email which you received from mathworks.com.
- After your account is ready, sign in and open the Channels tab.
- Press the New Channel button to make a new channel.
- Let's make the First Channel. Type a name for your channel, add a description, and enable a second field. Field 1 will receive the Temperature readings, Field 2 the Humidity readings and Field 3 the Pressure readings.
- You can also add additional data.
- Once you’ve completed all these fields, press Save channel button to save your First Channel.
- Take note of your new channel ID XXXXXX under Channel Settings. We had First Channel ID: 824485.
- Open the First Channel API Keys tab and copy the Write API Key and Read API Keys because you will need them later.
- Make this a public channel under sharing.Go to Sharing tab. Select Share channel with everyone.
- Create the Second Channel that will hold the Today (since midnight) High Low data. This channel should have 6 fields named Tmax, Tmin, Hmax, Hmin, Pmax, Pmin. Press on Save Channel button.
- Take note of the Second Channel ID (we had 824511), Read API keys and Write API key same way as in the steps before.
- Open the provided ESP8266-NodeMCU-12E-BME280.html file in a text editor (We used Notepad plus) and enter your First channel ID (as chan1) and Read API Keys (as key1).
- Enter the Second Channel ID (as chan2) and Read API Keys (as key2).
- Enter your timezone offset from UTC. (we have +3).
- Save and exit the text editor.
2. Uploading sketch to ESP8266 ESP-12E development board
If you’re using an ESP-12E NodeMCU Kit, uploading the sketch is very simple, since it has built-in programmer.
Before use ESP8266 ESP-12E WI FI module (LoLin NODEMCU V3), you need to download the manufacture's driver (CH340) for this chip and install it in your PC. Here is the link. See the description of driver installation package below: CH340 / CH341 USB to serial WINDOWS driver installation package that supports 32/64 bit Windows 10 / 8.1 / 8/7 / VISTA / XP, SERVER 2016/2012/2008/2003, 2000 / ME / 98, through Microsoft digital signature authentication, support USB to 3-wire and 9-wire serial port, with the product release To the end user. Applicable scope: CH340G, CH340C, CH340B, CH340E, CH340T, CH340R, CH341A, CH341T, CH341H chips.
If you have CP2102 chip then you need to download the manufacture's driver for this chip and install it in your PC. Driver for Mac, Windows, Linux or more..
- Do wiring.
- Open Arduino IDE.
- Plug your ESP8266 ESP-12E module into your PC USB port.
- Choose your NodeMCU board. Go to Tools -> Board -> NodeMCU 1.0 (ESP-12E Module
)
- Select the correct com port.
- Find your BME280 I2C address. Each device has an I2C address that it uses to accept commands or send messages. Compile and upload the I2Cscannersketch to your ESP8266 ESP-12E module.
- Open the Serial Monitor at a baud rate of 115200. Arduino will scan the address range looking for a reply. Even though the documentation said it was 0x77, this scanner can detect different (in our case 0x76). Adafruit_BME280 library has default I2C address 0x77 and if you are getting 0x76 you need to modify line of code in bme280testsketch1: status = bme.begin(); to status = bme.begin(0x76);
- Modify the sketch with your First Channel ThingSpeak Write API Key and local network SSID and password, compile and upload to your ESP8266 ESP-12E module.
- The default I2C address for BME280 sensor module set in the Adafruit_BME280.h file (look for the line #define BME280_ADDRESS 0x77) inside the Adafruit_BME280_Library folder. Adafruit’s BME sensor modules are hard-wired to use the I2C address of 0x77. But the BME280 can have a slightly different I2C address (0x76) if its external SDO pin is grounded. If you are using the sensor modules from a third party, it is likely that it’s address would not match with the default value in the Adafruit library. If you don't get a response from the sensor using the default address set in the Adafruit_BME280.h file, you might need to change it to 0x76.
- Open Serial monitor at 115200 baud. You can see the data from BME280 sensor module now. The data gets sent to Thingspeak at 30 seconds intervals so it will be some time before you have meaningful chart data but you should have gauge readings after 40 seconds.
- While the data from BME280sensor is uploading to Thingspeak lets do some tweaking to get some additional data from whats being uploaded. Go to the ThingSpeak Second Channel page and click on green MATLAB Analysis button.
- Select Template Custom (No Starter Code) and click on green Create button.
- Type the name - for example, Calculate Min Max Since Midnight.
- Copy the MATLAB.txt code into the provided space. Enter the First Channel ID into readChannelID. Enter the Second Channel ID and Write API Key into writeNewChannelID and writeAPIKey respectivly. Click the green Save and run button.
- If you did everything correcty and the read channel is set as public you will see no errors and it successfully prints the values.
- We need to create a Time Control to fire this code every 30 seconds and our data gets written to the Second channel. Go to Apps. Click on TimeControl then the Green button New TimeControl.
- Type the name, for example, Send High Low Temps ESP8266 ESP-13E.
- Select your time zone if needed and select Recurring under Frequency.
- Select Minute under Recurrence. Set to run every 5 Minutes. Action should be MATLAB Analysis and Code to Execute is Calculate Min Max Since Midnight.
- Click on Save TimeControl.
- Congrats! You can see the data on ThingSpeak First Channel grapth now.
- You can see the ThingSpeak Second Channel grapths updated too.
-
Open the provided ESP8266-NodeMCU-12E-BME280.html file in your web browser and you should see the gauges and chart.
-
-
Some of the text fields and the weekly chart will not populate correctly until you have a full day and full week of data for the 24 Hr and Week section and chart. Once you have a bunch of data you can zoom in on the charts with the mouse wheel (Right Click to Reset).
-
You can also have a fourth gauge (as seen in the screenshots) from another sensor from another channel - they are commented out. There is also some timing issues to be aware of. You likely will not have the absolute most current data but it should always be less than 5 Minutes old. This comes from when the timing control gets started, when the data was sent from the ESP8266 and when you loaded / refreshed the web page.
Summary
We have learnt how to use ESP8266 ESP-12E module with BME280 sensor module data in ThingsSpeak. We used the .html webpage and attachments made by author here.
Libraries
- All libraries attached on the begining of this project description.
- Wire and ESP8266WiFi libraries included in Arduino IDE.
- Adafruit BME280 library included. Download, unzip and add to libraries in our PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. You can read more about it here.
- Adafruit_Sensor library included. Download, unzip and add to libraries in our PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. You can read more about it here.
Sketch
- See on the begining of this project
Other projects of Acoptex.com










Viewed: 5309 times