BME680 and ESP

I’ve been trying to add some BME680 sensors to my IKEA air quality sensors. My goal was to add a bit more environmental sensors around my house to keep track of temperature, humidity, etc. In doing this I also ran into some odd problems with my D1 minis to work through.

The Wrong Connections

I first started out by connecting up the BME680 to VIN and ground for power, and D7 and D8 for data. This was about all the wrong choices I could make all in one. It wouldn’t connect to Wi-Fi, nor could I reflash it with my PC. It was basically dead in that configuration. If I disconnected the sensor from power, the ESP would start working again, could be flashed and connect to Wi-Fi just fine.

Why doesn’t it work

My initial thought was that maybe the D1 mini wasn’t providing enough power, however this was not the case. I was able to get the sensors to work on a Node MCU without issues, so I had something up with my D1 mini pin out and wiring.

Disconnected Power

I determined that I couldn’t plug the sensor into D7 and 8 as it kept the ESP from booting properly. Also with some experimenting I found that the sensor needed 3.3v instead of 5v, so I made sure to use the ESP 3.3v feed afterwards

The Right Way

Connect up the BME680 to 3.3v and ground on the ESP for power, and then to TX and RX for data.

  • D1 mini Tx (GPIO1) to BME680 SDA
  • D1 mini Rx (GPIO3) to BME680 SCL
  • 3.3v and ground
Wired up Correctly

Next up is getting the YAML file updated for the new sensor. My YAML is below, basically making use of the default YAML provided by ESPHome for the BME680 with some tweaks. I included a small offset to bring the sensor more in line with other temperature sensors I had in the house, and I changed the update interval to every 2 minutes so that the sensor wouldn’t heat up in the measurement process skewing the temperatures.

uart:
  rx_pin: GPIO4
  baud_rate: 9600
i2c:
  sda: 1
  scl: 3

sensor:
  - platform: pm1006
    pm_2_5:
      name: "Particulate Matter <2.5µm"
  - platform: bme680
    temperature:
      name: "BME680 Temperature"
      oversampling: 16x
      filters:
        - offset: -1.0
    pressure:
      name: "BME680 Pressure"
    humidity:
      name: "BME680 Humidity"
      id: humidity
    gas_resistance:
      name: "BME680 Gas Resistance"
      id: gas_resistance
    address: 0x77
    update_interval: 120s
  - platform: template
    name: "BME680 Indoor Air Quality"
    id: iaq
    state_class: measurement
    icon: "mdi:gauge"
    # caulculation: comp_gas = log(R_gas[ohm]) + 0.04 log(Ohm)/%rh * hum[%rh]
    lambda: |-
      return log(id(gas_resistance).state) + 0.04 *  id(humidity).state;
text_sensor:
  - platform: template
    name: "BME680 IAQ Classification"
    icon: "mdi:checkbox-marked-circle-outline"
    lambda: |-
      if (int(id(iaq).state) <= 50) {
        return {"Excellent"};
      }
      else if (int(id(iaq).state) <= 100) {
        return {"Good"};
      }
      else if (int(id(iaq).state) <= 150) {
        return {"Lightly polluted"};
      }
      else if (int(id(iaq).state) <= 200) {
        return {"Moderately polluted"};
      }
      else if (int(id(iaq).state) <= 250) {
        return {"Heavily polluted"};
      }
      else if (int(id(iaq).state) <= 350) {
        return {"Severely polluted"};
      }
      else if (int(id(iaq).state) <= 500) {
        return {"Extremely polluted"};
      }
      else {
        return {"unknown"};
      }

To give the sensor a bit more fresh air (further from the heat generated by the ESP), I just cut between 4 of the holes in the back to form a diamond shaped hole not much larger than the sensor. I made sure the sensor fit, then hot glued it into place. I then hot glued the D1 mini into place.

Conclusion

I’ve modified 4 of my IKEA sensors in this way so far, so I’m happy with the results even if it was frustrating to get to this point with the sensors. They’re reasonably accurate and nice to have additional data coming from one unit rather than needing multiple ESPs for the environmental data in my house.