Smart Cattle Collar, Wearable Sensing and ML
A custom low-power wearable that predicts cattle behavior from motion and GPS data, designed end to end from PCB to a deployed real-time ML dashboard.
A fully custom wearable sensor collar that monitors cattle and predicts their behavior (grazing, walking, resting, and other) from on-animal motion and location data, in real time. I built the entire system end to end: schematic and multi-layer PCB design, a rugged 3D-printed enclosure, embedded firmware for sensor acquisition and logging, the machine learning pipeline that classifies behavior, and a deployed real-time dashboard served from a FastAPI backend. The collar is designed to stream telemetry to a local server or, in future work, an autonomous agricultural rover, laying the groundwork for closed-loop livestock management. Built and field-tested on a steer at the Texas State University Freeman Center, under USDA-NIFA Grant 2023-77040-41262.
At a glance
| Role | Lead hardware, firmware, and ML developer |
| Hardware | Custom 2-layer PCB (KiCad to JLCPCB), 3D-printed weatherproof enclosure |
| Compute | Arduino Nano 33 IoT (ARM Cortex-M0+), MPU-6050 6-axis IMU, XA1110 GNSS |
| Firmware | Multi-sensor acquisition @ 10 Hz, SPI microSD logging, RTC time-stamping |
| ML | Random Forest, XGBoost, 1D-CNN, BiLSTM, CNN-BiLSTM (focal loss) |
| Best model | Random Forest + FFT features + SMOTE: 85.4% accuracy |
| Deployment | Real-time prediction dashboard served via FastAPI |
| Connectivity | u-blox NINA-W10 Wi-Fi/BLE, designed to stream telemetry to a server or future rover |
| Funding | USDA-NIFA Grant 2023-77040-41262 |
Why it matters
Behavioral changes are among the earliest signals of illness, estrus, or distress in cattle, but spotting them by eye across a herd is labor-intensive and often too late to act on. A wearable that continuously senses motion and classifies behavior turns that into an automated, always-on signal. The longer-term vision is closed-loop: the collar would stream behavior and location to an autonomous rover that could investigate or intervene when something looks wrong. The hard part is doing it cheaply, ruggedly, and at low enough power to survive in the field, which meant building custom hardware rather than buying it.
Hardware: from schematic to fabricated board
I designed the collar’s electronics from scratch in KiCad: schematic capture, electrical rule checks, footprint assignment, and a double-layer PCB layout with dedicated net classes for power vs. signal traces, ground planes for EMI control, and impedance-conscious routing. Gerbers were fabricated by JLCPCB and hand-assembled.
The second-generation board was a substantial redesign: a 30.4% smaller footprint and roughly 59% less volume than version 1, achieved by integrating the IMU into the microcontroller, switching from a cylindrical to a flat Li-Po cell, and replacing an unreliable 433 MHz radio with onboard Wi-Fi/Bluetooth, all while increasing battery capacity.
Enclosure: rugged, weatherproof, animal-friendly
The electronics live in a custom clamshell enclosure I designed for field durability: a gasket-sealed, impact-resistant housing with integrated belt loops, a latch-and-hinge system, and internal ribbing tuned for 3D printing. It was printed in PLA with dissolvable PVA supports on an Ultimaker S5 Pro.
Field deployment and data collection
The collar was deployed on a steer at the Freeman Center across three multi-hour sessions, logging IMU and GNSS data at 10 Hz to onboard storage. Two time-synced cameras recorded the paddock so every sensor window could be matched against video ground truth for behavior labeling, yielding roughly 356,000 raw samples hand-labeled into four behavior classes.
Machine learning
The data is heavily imbalanced: grazing dominates at 65%, while walking is under 3%. That is the central modeling challenge, because a naive classifier scores high accuracy by ignoring the rare-but-important behaviors. Handling that imbalance honestly drove most of the ML work.
Pipeline. Raw signals are segmented into 50-sample (10-second) windows, then expanded with time-domain statistics and FFT-based frequency-domain features. To combat imbalance I used SMOTE oversampling, class-weight balancing, and RandomizedSearchCV tuned on macro-F1, with early stopping on the deep models.
Models. I benchmarked classical models (Random Forest, XGBoost) against deep sequence models (1D-CNN, BiLSTM, and a CNN-BiLSTM hybrid with weighted focal loss). The deep models with focal loss recovered more of the rare classes but traded away overall accuracy and added training complexity. The Random Forest with FFT features and SMOTE won on the accuracy/practicality trade-off at 85.4% accuracy, with the best macro-F1 among balanced configurations, so it was the one I deployed.
The deployed model handles the common behaviors (grazing, resting) reliably. The rare classes (walking, other) remain harder due to the severe class imbalance, which is the central open challenge and the motivation for the deep models’ focal-loss experiments.
Deployment: real-time dashboard
The selected model runs behind a FastAPI server that ingests the collar’s live telemetry and serves a real-time dashboard, plotting the animal’s GPS location on a map, the current predicted behavior, and the raw sensor feed side by side. This closes the loop from a bare schematic all the way to a running inference service.
What this project demonstrates
- Full-stack hardware ownership. Schematic, PCB layout, fabrication, and bring-up of a custom mixed-signal board.
- Mechanical design for the real world. Parametric CAD and additive manufacturing for a sealed, field-rugged enclosure.
- Embedded systems. Multi-sensor acquisition, SPI storage, power management, and battery-life optimization.
- Applied ML on messy, imbalanced real data. Sensor fusion, FFT feature engineering, SMOTE and focal-loss imbalance handling, and classical-vs-deep benchmarking.
- Deployment. Packaging the winning model into a live FastAPI inference service with a real-time dashboard.
- End-to-end execution. From a blank schematic to a deployed system classifying behavior on a live animal in the field.