A DIY IoT wireless sensor for temperature, humidity and pressure. It is made of two parts:
This repository contains all the instructions to build the Bain sensor yourself.
Follow the connections shown below. There is 4 connections (blue, red, yellow and green) in between the Feather ESP8266 board the BME280 chip. And also a last connection in purple to enable deep sleep mode and reduce battery consumption (optional).
Warning: Apparently, the Feather ESP8266 chip can't be flashed with the purple connection so you have to disconnect it, then flash and then reconnect it.
You should use the Arduino IDE to flash the controller to the board. Note that a VSCode extension for Arduino IDE is also available and works well.
You need to add the following URL to the Arduino Board Manager: http://arduino.esp8266.com/stable/package_esp8266com_index.json
.
Then in the Arduino Board Manager, install the ESP8266
package. After this, you should be able to select the correct board from the Board Manager: Adafruit Feather HUZZAH ESP8266
.
Then you need to install the following Arduino libraries (use the Arduino Library Manager):
Configure WiFi and MQTT credentials:
bain/secret.h.template
to bain/secret.h
.bain/secret.h
.#ifndef BAIN_SECRET
#define BAIN_SECRET
#define WIFI_SSID "myssid"
#define WIFI_PASSWORD "mypassword"
#define MQTT_SERVER "your_server"
#define MQTT_PORT 1883
#define MQTT_CLIENT_ID "sensor1"
#define MQTT_MESSAGE_TOPIC "/bain_sensor/1"
// Leave blank to disable auth.
#define MQTT_USERNAME "your_username"
#define MQTT_PASSWORD "your_password"
#endif
bain/parameters.h
.#ifndef BAIN_PARAMETERS
#define BAIN_PARAMETERS
// Timezone
const int timeOffsetHours = -5;
// Delay between two measures in seconds.
const int loop_delay_s = 60;
// Enable deep sleep mode.
const boolean deep_sleep = true;
// Monitor battery level.
const boolean monitorBattery = true;
// LEDs. Disable by setting value to `-1`.
// Warning: Unused at the moment.
const int state_LED = -1;
#endif
Now you're ready to flash the controller.
bain/bain.ino
.By reading on the serial port, you should see logging messages about WiFi, the sensor and also the JSON string sent to the MQTT broker:
{
"temperature": 25.23,
"pressure": 1018.4,
"humidty": 90.12,
"timestamp": "2019-02-15 15:45:23",
"batteryLevel": 82.3,
"batteryCharging": false,
"batteryVoltage": 3.76
}
If you want to monitor the LiPo battery level, you need to add some connections to your circuit as shown below. For this you need the following parts:
Then you need to set monitorBattery
to true
in bain/parameters.h
.
This setup comes from https://github.com/lobeck/adafruit-feather-huzzah-8266-battery-monitor.
Once you've checked your assembly works you can solder everything together using a FeatherWing proto board. Here is the final assembly diagram:
TODO.
If your MQTT broker is connected to an Home Assistant instance, Bain sensors should be automatically discovered.
MIT.