Send BMP280 sensor data with ESP8266 to ThingSpeak

Got my temperature, pressure and humidity data logging working.
I started by trying out the BPM280 nodemcu module with some lua scripts.
The I2C setup was easy and soon I was seeing sensor readings.
After getting the ESP8266 talking to my WiFi access point and I tried to post data to ThinkSpeak. I followed these instructions: substituting the sensors used with the BMP280.
Somehow I couldn't send anything to ThingSpeak so I decided to go the Arduino IDE way as proposed in the Vaasa Hacklab instructions comments section.

To set up the Arduino IDE with the ESP8266 you could follow some guide like:
First I had some problems to blink the on-board led on my NodeMCU 12E 1.0 fake from Ebay.
The pin# 2 did the trick. After a lot of hammering and realizing the I hadn't downloaded the newest Adafruit_BME280 library I got the following code to do my bidding:

  • Change in Adafruit_BME280.h #define BME280_ADDRESS (0x77) to #define BME280_ADDRESS (0x76)
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <ESP8266WiFi.h>
#include <ThingSpeak.h>

unsigned long myChannelNumber = YOURCHANNERNUMBER;  
const char * myWriteAPIKey = "YOURAPIKEY";  
const char* ssid = "YOURSSID";  
const char* password = "YOURPW";

const char* server = "";  
WiFiClient client;

Adafruit_BME280 bme; // I2C

void setup() {  
  Wire.begin(0, 2);

  WiFi.begin(ssid, password);

  Serial.print("Connecting to ");

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
  Serial.println("WiFi connected");

  if (!bme.begin()) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);

void loop() {  
  float t = bme.readTemperature();
  float p = bme.readPressure();
  float h = bme.readHumidity();

  Serial.print("Temperature: ");
  Serial.print(" degrees Celcius Pressure: ");
  Serial.print(" Humidity: ");
  Serial.println("% send to Thingspeak");
  ThingSpeak.setField(1, t);
  ThingSpeak.setField(2, p);
  ThingSpeak.setField(3, h);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

Here is the channel:


So many projects to make! I Enjoy building electronics, especially radios. I also like web development, playing with hardware like the Raspberry Pi and spending time outdoors. Love combining it all!

comments powered by Disqus