Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hadim/bain
A DIY IoT wireless sensor for temperature, humidity and pressure.
https://github.com/hadim/bain
adafruit arduino bme280 diy home-assistant iot thermometer
Last synced: 30 days ago
JSON representation
A DIY IoT wireless sensor for temperature, humidity and pressure.
- Host: GitHub
- URL: https://github.com/hadim/bain
- Owner: hadim
- License: mit
- Created: 2019-02-07T00:17:33.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-08T12:21:15.000Z (over 4 years ago)
- Last Synced: 2024-10-30T03:23:25.278Z (3 months ago)
- Topics: adafruit, arduino, bme280, diy, home-assistant, iot, thermometer
- Language: C++
- Homepage:
- Size: 5.14 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bain
[![Build Status](https://travis-ci.com/hadim/bain.svg?token=fC6e2psPPR69RiF4UxYh&branch=master)](https://travis-ci.com/hadim/bain)
A DIY IoT wireless sensor for temperature, humidity and pressure. It is made of two parts:
- [Adafruit Feather HUZZAH with ESP8266](https://www.adafruit.com/product/2821): it's an Arduino compatible board that has WiFi capability and a connector to plug any Adafruit 3.7V Lithium polymer batteries. Note that any ESP8266 board should work.
- [Adafruit BME280 I2C or SPI](https://www.adafruit.com/product/2652): It's an environmental sensor with temperature, barometric pressure and humidity from Bosch.This repository contains all the instructions to build the Bain sensor yourself.
## Features
- ๐ก Monitor **temperature**, **pressure** and **humidity**.
- โ Data are sent to a custom **MQTT** broker as a **JSON** string.
- ๐ **Time is syncronized** every 6h with NTP and the **timezone** can be specified.
- ๐ด Deep sleep mode can be enabled to **reduce power consumption**. A standard LiPo battery of [1200 mAh](https://www.adafruit.com/product/258) can last about a week. Consumption is ~6.5mA while in deep sleep mode (optional).
- ๐ Monitor **battery level** (optional).
- ๐ก The source code is profusely commented and factorized. It should be **easy to adapt** to your needs.## Instructions
### Assembly on a breadboard
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.
![Feather ESP8266](diagrams/bain_bb.png)
### Flash the controller
#### Environement Setup
You should use the [Arduino IDE](https://www.arduino.cc/en/main/software) to flash the controller to the board. Note that [a VSCode extension for Arduino IDE](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.vscode-arduino) 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**):
- [Adafruit ESP8266](https://github.com/adafruit/Adafruit_ESP8266): Arduino board with WiFi capability.
- [Adafruit BME280 Library](https://github.com/adafruit/Adafruit_BME280_Library): Sensor library.
- [Adafruit Unified Sensor](https://github.com/adafruit/Adafruit_Sensor): Needed for Adafruit BME280 Library.
- [ArduinoJson](https://github.com/bblanchon/ArduinoJson): a JSON library.
- [NTPClient](https://github.com/arduino-libraries/NTPClient): an NTP client library to get date and time.#### Controller Configuration
- Configure WiFi and MQTT credentials:
- Copy `bain/secret.h.template` to `bain/secret.h`.
- Edit `bain/secret.h`.```cpp
#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
```- Configure other parameters by editing `bain/parameters.h`.
```cpp
#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
```#### Upload Firmware
Now you're ready to flash the controller.
- From you editor, open [`bain/bain.ino`](bain/bain.ino).
- Compile it.
- After connecting the board to your computer, upload the controller.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:
```json
{
"temperature": 25.23,
"pressure": 1018.4,
"humidty": 90.12,
"timestamp": "2019-02-15 15:45:23",
"batteryLevel": 82.3,
"batteryCharging": false,
"batteryVoltage": 3.76
}
```### Battery Level Monitoring
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:
- 1 x 10 kฮฉ resistor
- 1 x 47 kฮฉ resistor
- 1 x 1 Mฮฉ resistor
- 1 x 1 ยตF capacitor![Feather ESP8266](diagrams/bain_battery_monitor_bb.png)
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._
### Final Assembly
Once you've checked your assembly works you can solder everything together using a [FeatherWing proto board](https://www.adafruit.com/product/2884). Here is the final assembly diagram:
![Bain Final Assembly](diagrams/bain_final_assembly_bb.png)
## Case
**TODO.**
## Home Assistant
If your MQTT broker is connected to an [Home Assistant](https://www.home-assistant.io) instance, Bain sensors should be automatically discovered.
## License
[MIT](./LICENSE).
## Author
- [Hadrien Mary](mailto:hadrien.mary_AT_gmail.com)