Smart IoT Sensor Built With XIAO ESP32C6: WiFi, MQTT, BME280/BME680 Integration & Power Management

by BegoonLab in Circuits > Sensors

445 Views, 3 Favorites, 0 Comments

Smart IoT Sensor Built With XIAO ESP32C6: WiFi, MQTT, BME280/BME680 Integration & Power Management

IMG_9927.jpg
IMG_9954.jpg

The project uses a Seeed XIAO ESP32C6 to build a low-cost, Wi-Fi-enabled sensor, ideal for applications where you need remote environmental monitoring. It includes instructions to set up a temperature, RSSI, and battery voltage sensor using MQTT to relay data to a Home Assistant setup or similar platform.

Supplies

IMG_9929.jpg
  1. Seeed XIAO ESP32C6 – Main microcontroller
  2. Temperature sensor (BME280/BME680) - For monitoring environment
  3. Li-ion battery 3.7V – Power source for the sensor. The enclosure is designed for the usage of 18650.
  4. Soldering iron and solder
  5. Cable USB Type C – For programming and power
  6. Wi-Fi Antenna with U.FL connector - Highly recommended
  7. A few 3D printed parts
  8. Wires to solder up everything together.
  9. PC – For flashing firmware
  10. (Optional) two THT resistors 220k. One THT capacitor 100n.

Printing Enclosure

printing_setup_1.png
printing_setup_0.png

The sensor is housed in a customizable 3D-printed enclosure. STL files are available for download and 3D printing. To customize a model use a FreeCAD project. A 3D preview is available here.

When printing, it is recommended to orient the parts on the hotbed as shown in the picture.

Enclosure Assembly - Insert XIAO Board Into SoC Holder

SensorXIAO_assemby_0.jpg

Enclosure Assembly - Insert SoC Holder Into the Core Part

IMG_9938.jpg
IMG_9940.jpg

Pull down until it can't go any farther

Enclosure Assembly - Insert SoC Bracket

IMG_9942.jpg

Enclosure Assembly - Insert Lock Into the Core Part

IMG_9950.jpg

Wire All Components

IMG_9944.jpg
IMG_9946.jpg
IMG_9945.jpg
SensorXIAO_battery_connection.png
SensorXIAO_connect_bme.png
SensorXIAO_voltage_divider.png

Now solder up everything together according to schematics. And repeat an assembly steps if everything fits nicely.

Attach an antenna. Put the coaxial wire into the channels in the core part. Use a couple of drops of glue or double-sided tape to secure the antenna in its place.

Avoid blocking environmental sensors. Keep it away from SoC board, because when charging a battery it can be affected by built-in BMS heat exposure.

Pull the Wrapper

IMG_9951.jpg

Finally, pull the wrapper onto the core part. Ensure that the lock is securing the wrapper.

At this step the enclosure is done, and you can plug in USB Type C and start flash the firmware.


Flash Firmware

FAPKQH0M1RVP02F.jpg
SensorXIAO_menu.png

Connect USB Type C.

  1. Install ESP-IDF - Official development framework for Espressif chips. Follow the ESP-IDF Getting Started Guide to set up the development environment.
  2. Clone the Repository of this project:
git clone https://github.com/BegoonLab/xiao-esp32c6-wifi-sensor
cd xiao-esp32c6-wifi-sensor
git submodule update --init --recursive
  1. Configure the Project
idf.py menuconfig
  1. go to XIAO Sensor Configuration
  2. Wi-Fi Configuration: Set up your Wi-Fi credentials to enable network connectivity.
  3. MQTT Configuration: Connect the sensor to your MQTT server by providing the necessary broker details.
  4. Battery Check (Optional): Enable battery voltage monitoring if power management insights are needed.
  5. BME Sensor Configuration (Optional): Choose between BME280 and BME680 sensors based on your requirements.
  6. Power Management Configuration: Set up wakeup duration, which is the duration in seconds that the device will remain in deep sleep before waking up.
  7. Then build a firmware
idf.py build
  1. And flash
idf.py -p <TARGET_PORT> flash monitor
  1. In case of issues check the logs. Some useful debug info might occur here.

Integrate With Home Assistant

SensorXIAO_ha_card.png

Set Up MQTT Server. If you don't have an MQTT server, refer to the Home Assistant MQTT Integration guide.

The sensor publishes data to an MQTT broker in the following JSON format:

{
"ID": "7i29r9k9ltaxmbev",
"RSSI": -54,
"battery_voltage": 4.13,
"temperature": "24.28",
"humidity": "29.32",
"pressure": "999.54",
"connection_duration_ms": 1672
}
  1. ID: Unique identifier of the sensor
  2. RSSI: Wi-Fi signal strength in dBm
  3. battery_voltage: Current battery voltage
  4. temperature: Temperature reading from the BME sensor
  5. humidity: Humidity reading from the BME sensor (%)
  6. pressure: Pressure reading from the BME sensor (hPa)
  7. connection_duration_ms: Time taken to establish the MQTT connection


Configure `configuration.yaml`: Add the following configuration to your `configuration.yaml` file to define the sensor entities.

...
mqtt:
sensor:
- name: "Sensor RSSI 7i29r9k9ltaxmbev"
device_class: signal_strength
state_topic: "xiao/sensor/7i29r9k9ltaxmbev/data"
unit_of_measurement: "dBm"
value_template: "{{ value_json.RSSI }}"

- name: "Sensor Temperature 7i29r9k9ltaxmbev"
device_class: temperature
state_topic: "xiao/sensor/7i29r9k9ltaxmbev/data"
unit_of_measurement: "°C"
value_template: "{{ value_json.temperature }}"

- name: "Sensor Humidity 7i29r9k9ltaxmbev"
device_class: humidity
state_topic: "xiao/sensor/7i29r9k9ltaxmbev/data"
unit_of_measurement: "%"
value_template: "{{ value_json.humidity }}"

- name: "Sensor Pressure 7i29r9k9ltaxmbev"
device_class: pressure
state_topic: "xiao/sensor/7i29r9k9ltaxmbev/data"
unit_of_measurement: "hPa"
value_template: "{{ value_json.pressure }}"

- name: "Sensor Battery Voltage 7i29r9k9ltaxmbev"
device_class: voltage
state_topic: "xiao/sensor/7i29r9k9ltaxmbev/data"
unit_of_measurement: "V"
value_template: "{{ value_json.battery_voltage }}"

- name: "Sensor Connection Duration 7i29r9k9ltaxmbev"
device_class: duration
state_topic: "xiao/sensor/7i29r9k9ltaxmbev/data"
unit_of_measurement: "ms"
value_template: "{{ value_json.connection_duration_ms }}"
...


Restart Home Assistant. After updating the configuration, restart Home Assistant to apply the changes.

Configure Entity Card. Here is an example configuration for the entity card:

...
type: entities
entities:
- entity: sensor.sensor_temperature_7i29r9k9ltaxmbev
icon: mdi:thermometer-low
secondary_info: last-changed
name: Temperature
- entity: sensor.sensor_humidity_7i29r9k9ltaxmbev
name: Humidity
- entity: sensor.sensor_pressure_7i29r9k9ltaxmbev
name: Pressure
- entity: sensor.sensor_rssi_7i29r9k9ltaxmbev
icon: mdi:wifi-strength-3
secondary_info: none
name: RSSI
- entity: sensor.sensor_battery_voltage_7i29r9k9ltaxmbev
icon: mdi:battery-80
secondary_info: none
name: Battery
- entity: sensor.sensor_connection_duration_7i29r9k9ltaxmbev
name: Connection Duration
title: Sensor 7i29r9k9ltaxmbev
...


That's it. A simple HA configuration is ready to collect and show the data. For an extra sensor don't forget to change Sensor ID field, to distinguish them.

Follow the Project on GitHub

This is the project repository: https://github.com/BegoonLab/xiao-esp32c6-wifi-sensor/tree/main

Contributions are welcome!