Subhrajit Majumder
Published © MIT

Building your own Environmental sensor using BME680 with ESP

Design and Implementation of an Environmental Sensor with Integrated BME680 for Multi-Parameter Measurements.

IntermediateFull instructions provided1 hour557
Building your own Environmental sensor using BME680 with ESP

Things used in this project

Hardware components

Tripler adaptor for DI Mini
Developed by Carenuity
×1
BME680 breakout for D1 Mini
Developed by Carenuity
×1
Wemos D1 Mini
Espressif Wemos D1 Mini
×1
0.66 inch OLED Display
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Mastech MS8217 Autorange Digital Multimeter
Digilent Mastech MS8217 Autorange Digital Multimeter
Soldering Station, Temperature Controlled
Soldering Station, Temperature Controlled

Story

Read more

Schematics

BME680_OLED_Tripple_adapter/BME680_OLED_Tripple_adapter

Code

BME680_OLED_Tripple_adapter/BME680_OLED_Tripple_adapter.ino

C#
BME680_OLED_Tripple_adapter using ESP8266 D1 Mini
/*
Firmware name: BME980_OLED_Tripple_adapter
Created by Subhrajit Majumder 
Modified on: 26/11/2023
More technical details: https://carenuity.com/

Required Hardware components:
A. Carenuity BME680 Shild.
B. D1 Mini
C. 0.66" OLED Display
D. Tripple Adapter.

This code is in the private (Organization) domain .
*/

#include <SPI.h>
#include <Wire.h>
#include "Adafruit_BME680.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

/*                      OLED Definations                        */
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for SSD1306 display connected using I2C
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

/*                    BME680 Definations                       */
#define BME_SCK D5
#define BME_MISO D6
#define BME_MOSI D7
#define BME_CS D8

#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME680 bme; // I2C

/*                    User define variables                       */
int temp, pres, RH, gas, alt;


void setup(){
  // Defination of Serial monitor for debugger
  Serial.begin(9600);

  //  Searching for Display.
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
  Serial.println(F("SSD1306 allocation failed"));
  for(;;); // Don't proceed, loop forever
  }

  // Searching for BME680.
  if (!bme.begin()) {
    Serial.println("Could not find a valid BME680 sensor, check wiring!");
    
    // Clear the buffer.
    display.clearDisplay();
    // Display Text
    display.setTextSize(1);
    display.setTextColor(BLACK, WHITE);
    display.setCursor(32,15);
    display.println("No Sensor");
    display.display();
    delay(500);

    while (1);
  }

  // Set up oversampling and filter initialization
  bme.setTemperatureOversampling(BME680_OS_8X);
  bme.setHumidityOversampling(BME680_OS_2X);
  bme.setPressureOversampling(BME680_OS_4X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
  bme.setGasHeater(320, 150); // 320*C for 150 ms

  // Clear the buffer.
  display.clearDisplay();
  // Display Text
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(44,20);
  display.println("BME680");
  display.setCursor(55,34);
  display.println("by");
  display.setCursor(36,49);
  display.println("CARENUITY");
  display.display();
  delay(4000);
  display.clearDisplay();
}

void loop(){

  if (! bme.performReading()) {
    Serial.println("Failed to perform reading :(");
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(32,15);
    display.println("BME_Fail");
    display.display();
    delay(500);
    return;
  }
//  Data fetch from sensor
  temp = bme.temperature;
  pres = (bme.pressure / 100.0);
  RH = bme.humidity;
  gas = (bme.gas_resistance / 1000.0);
  alt = (bme.readAltitude(SEALEVELPRESSURE_HPA));

  // Serial Printing (For debug).
  // Serial.println(temp);
  // Serial.println(pres);
  // Serial.println(RH);
  // Serial.println(gas);
  // Serial.println(alt);

// Dispaly function
  display.setTextSize(1);
  display.setTextColor(WHITE);

/*                                1st Screen                               */
  // Display Temperature
  display.setCursor(32,20);
  display.println("Temp:");
  display.setCursor(62,20);
  display.println(temp);
  display.setCursor(79,20);
  display.println("C");
// Display Humidity
  display.setCursor(32,34);
  display.println("RH: ");
  display.setCursor(52,34);
  display.println(RH);
  display.setCursor(70,34);
  display.println("%");
// Display Altitude
  display.setCursor(32,49);
  display.println("ALT: ");
  display.setCursor(62,49);
  display.println(RH);
  display.setCursor(79,49);
  display.println("m");
 
  display.display();
  delay(4000);
  display.clearDisplay();

  /*                                2nd Screen                               */
  display.setTextSize(1);
  display.setTextColor(WHITE);

  // Display Pressure
  display.setCursor(32,20);
  display.println("P:");
  display.setCursor(45,20);
  display.println(pres);
  display.setCursor(70,20);
  display.println(" hPa");
// Display Gas
  display.setCursor(32,34);
  display.println("GAS: ");
  display.setCursor(55,34);
  display.println(gas);
  display.setCursor(70,34);
  display.println("KOhm");
  // Display End data
  display.setCursor(32,49);
  display.println("------------");

  display.display();
  delay(4000);
  display.clearDisplay();
}

Credits

Subhrajit Majumder

Subhrajit Majumder

2 projects • 3 followers
Master's (MTech) on Embedded System (Engineering) from CDAC Mohali Effective technological skills in Robotics, Microcontrollers, LoRa & BMS.

Comments