Sketch for transmitting BME280 sensor data via HC-05 bluetooth to Android


This is my first ever foray into Arduino.

I am looking for some help with a sketch for transmitting realtime BME280 sensor data (Temp, pressure, humidity, altitude) via HC-05 bluetooth to Android.

So far I've had no problems displaying BME280 data on an OLED display.

So far I've had no problems doing basic things with the HC-05, such as sending typed data to and from a bluetooth serial monitor on my Android phone to the IDE serial monitor on my computer and vice versa.

All hardware is working fine. I'm using a 3.3v pro mini, 18650 battery (4.2-3.5v) connected to RAW/GND, the BME280 is on a GY-BM breakout connected via I2C, the HC-05 bluetooth is connected to RAW/GND and RX/TX TX/RX connections.

I am not a programmer, basically I have been copying/pasting and tweaking sketches to what I want, I have a very basic understanding of the programming so far.

I have spent more than 12 hours searching online for any useful sketches, but have not found a single sketch that comes close to doing what I want (at least not for I2C sensors).

Can anyone help with a sketch or at least point me in the right direction to get started?

Is it even possible to transmit 4 different sets of I2C sensor data via bluetooth using Arduino?

Any help/advice will be gratefully received.

using an Arduino Due with a HC-06 as a bluetooth slave (HC-05 can act as master) running the following code

// HC-06 Bluetooth module AT commands
// note Serial1 baudrate is 9600
// using Arduino Due connect HC-06 Tx to due pin 19
// using Arduino Due connect HC-06 Rx to due pin 18

// when paired with PC creates two COM ports, e.g. COM13 and COM14
//  using teraterm at 9600 baud connect to COM13
//  send/receives OK

void setup()
  Serial.println("Enter AT commands:");
  Serial1.begin(9600);//38400);       // HC-05 default speed in AT command more

void loop()
  if ( Serial1.available())    // read from HC-05 and send to Arduino Serial Monitor

  if (Serial.available())     // Keep reading from Arduino Serial Monitor and send to HC-05

I can pair the Android with HC-06 and using app Serial Bluetooth Terminal communicating OK transfering characters both ways

you can certainly send data from 4 sensors - you will need to define some protocol

in this example I am sending a record with system configuration data in YAML from the Android to a target microcontroller

System configuration
  name Main controller
  Control algorithm ON
  SYSTEM_serial_No: 4 (0-0)
  LEVEL_MAX_ERROR: 25 (0-1000)
  UNIT_ON_HOUR: 700 (0-2359)
  UNIT_OFF_HOUR: 2200 (0-2359)
  CRC16 0x6c87

various parameters are set, e.g. Unit on hour to 7.00 (followed by valid range)
the last field is a CRC16 check of the record in case of data corruption

Thanks Horace, that was very useful! I'll play around with it some more.

I've managed to get it going using an Android app and a sketch made by someone else (Geniezito) that I've 'tweaked' to my needs - from Weather Station Bluetooth - Arduino Project Hub.

I just need to have a go at modifying the android app now...


So far I've had no problems displaying BME280 data on an OLED display.

In that case, you should be able to send the same data to serial monitor, and then no further coding is required. The fact that your sensors are I2C is completely irrelevant. About the only thing left that can go wrong is proper power supply to HC-05. IF this is on a breakout board like ZS-040, and is working OK off 3.3v from pro Mini, it may be fine but that is probably more down to good luck than good management. I imagine running it directly off the battery is a better bet. If your Bluetooth is a bare module then, clearly, no problem.

ANY bluetooth terminal will do the job, and any modification of yours is by choice, not need, so just make sure you aren't re-inventing the wheel. I use Bluetooth Graphics Terminal, which is fine, but you will need the paid version for four inputs - money well-spent, I would reckon.

Thanks Nick,

I am using a ZS-040, which I’ve got connected to RAW/GND, so it should run fine on the one 18650 battery.

I’ve finally worked it out, I’ve included the sketch below.

Last question, is it possible to send data from the BT terminal to the HC-05 connected to the pro mini to change the value for #define SEALEVELPRESSURE_HPA (1023)? Or some other equivalent code that would achieve the same result?

Or is it possible to set this value by pressing a button somehow?

This would be extremely useful for calibrating the altitude measurement without having to upload a new sketch every time I want to calibrate it, which is once or twice a day.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <SoftwareSerial.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define SEALEVELPRESSURE_HPA (1023) //###Enter local mean sea level pressure (MSLP) for accurate altitude, or 1013.25 hPa for generic average altitude
Adafruit_BME280 bme;
SoftwareSerial bt(2, 3); //BlueTooth HC-05 ZS-040 connected to arduino pins 2 (BT TXD) and 3 (BT RXD)

void setup()
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
if (!bme.begin(0x76))
Serial.println(F(“Could not find a valid BME280 sensor, check wiring!”));
while (1);

void loop()
Serial.println(F(" MSLP = 1023 hPa"));
bt.println(F(" (MSLP = 1023 hPa)"));


Serial.print(F(“Temperature = “));
Serial.println(F(” *C”));
display.print(F("T "));
display.print(bme.readTemperature(), 1);
bt.print(F(“Temperature = “));
bt.print(bme.readTemperature(), 1);
bt.println(F(” *C”));

Serial.print(F(“Pressure = “));
Serial.print(bme.readPressure() / 100.0F);
Serial.println(F(” hPa”));
display.print(F("P "));
display.print(bme.readPressure() / 100, 0);
bt.print(F(“Pressure = “));
bt.print(bme.readPressure() / 100, 0);
bt.println(F(” hPa”));

Serial.print(F(“Humidity = “));
Serial.println(F(” %”));
display.print(F(“H “));
display.print(bme.readHumidity(), 0);
bt.print(F(“Humidity = “));
bt.print(bme.readHumidity(), 0);
bt.println(F(” %”));

Serial.print(F(“Altitude = “));
Serial.println(F(” m”));
display.print(bme.readAltitude(SEALEVELPRESSURE_HPA), 0);
bt.print(F(“Altitude = “));
bt.print(bme.readAltitude(SEALEVELPRESSURE_HPA), 0);
bt.println(F(” m”));









BME280_BT_OLED_Serial.ino (3.21 KB)

I'm not familiar with the RAW terminal, but it is working and, so long as you are leaning every volt you can get against ZS-040, it should be OK.

You should have no problem inputting a variable. I have only done it with filenames for downloading but the principle is about the same.

I suspect you are printing a lot of text repetitively and a lot if it should go in setup. (clearly, not fatal)

Last question, is it possible to send data from the BT terminal to the HC-05 connected to the pro mini to change the value for #define SEALEVELPRESSURE_HPA (1023)? Or some other equivalent code that would achieve the same result?

If you are going to send data from the BT terminal to the Arduino it would serve you well to review the methods presented in Robin2's excellent tutorial on Serial Input Basics.

Thanks for your replies,

I can see that I've got a bit of reading to do to work out the code I need to change the value of #define SEALEVELPRESSURE_HPA (1023) via serial data sent by bluetooth.

Well, it's just a float variable isn't? I think you are making this look harder than it really is. Once you get past the cultural block, the links above should be all you need.