TinyML Pet Activity Tracker: From XIAO BLE Sense to Edge Impulse
Share this article
TinyML Pet Activity Tracker: From XIAO BLE Sense to Edge Impulse
The project, showcased on Hackster.io, turns a compact XIAO BLE Sense microcontroller into a real‑time activity monitor for dogs. By streaming 3‑axis IMU data over Bluetooth to a Flutter app, the system feeds raw accelerometer samples into Edge Impulse’s cloud platform, where a lightweight neural network classifies activity into rest, walk, or run.
Hardware Foundations
The XIAO BLE Sense packs a Nordic nRF52840 MCU, a 32‑bit ARM® Cortex‑M4 core, and a 6‑axis IMU. Its Bluetooth 5.0 stack allows continuous, low‑latency data transfer, while the 50 Hz sampling rate yields 50 readings per second—sufficient granularity for motion analysis.
Data Capture Without USB
Because the device must stay on the dog’s collar, the author built a custom Flutter app, EI Blue, to wirelessly collect IMU samples and push them directly to Edge Impulse Studio. The app scans a QR code that configures the project, then streams 5‑second windows of accelerometer data via Bluetooth.
// Simplified data‑streaming snippet from EI Blue
BluetoothDevice device = await BluetoothAdapter.instance.connect(deviceId);
await device.startListening();
device.onDataReceived.listen((data) {
EdgeImpulseClient.uploadSample(data);
});
Feature Extraction with Spectral Analysis
Edge Impulse’s Spectral Analysis block transforms raw time‑series data into frequency‑domain features. The author enabled Calculate feature importance, revealing that accX Spectral Power was the most discriminative metric for distinguishing rest, walk, and run.
Model Training and Accuracy
A small fully‑connected network, trained on roughly six minutes of labeled data, achieved 90 % test accuracy. While the dataset is limited to a single dog, the model demonstrates the viability of TinyML for animal‑activity classification.
Firmware and Deployment
After training, the user downloads the generated Arduino library and uploads the provided sketch, XIAO_BLE_Pet_Activity.ino, to the board. The firmware continually predicts activity every minute and transmits the result to the paired phone.
#include "PetActivity.h"
void setup() {
Serial.begin(115200);
BLE.begin();
model.begin();
}
void loop() {
IMU.read();
float prediction = model.predict(IMU.data());
BLE.send(prediction);
delay(60000); // one minute
}
Mobile App and Cross‑Platform Reach
The Flutter front‑end visualizes predictions on live graphs and stores them locally. Although the author built the iOS version first, the same codebase supports Android, enabling rapid deployment across devices.
Implications for Pet‑Health Tech
- Scalable Monitoring: The low power consumption of the XIAO BLE Sense makes continuous monitoring feasible for long‑term studies.
- Edge‑to‑Cloud Pipeline: Leveraging Edge Impulse abstracts model training, allowing developers to focus on data collection and feature engineering.
- Customizable Models: The spectral‑feature approach can be extended to other animals or activity classes with minimal code changes.
By demonstrating a complete TinyML stack—from sensor to cloud to mobile UI—this project provides a practical template for developers seeking to build health‑tracking solutions in the growing pet‑tech market.
Source: https://www.hackster.io/mithun-das/pet-activity-tracker-using-xiao-ble-sense-edge-impulse-858d73