Build it step by step
0 of 7 doneTest the sensor
Print movement while shaking.
Separate active and rest
Choose a threshold.
Add deep sleep
Wake every 5 seconds.
Keep the counters
Use RTC memory.
Add the Wi-Fi sync
Upload every 15 minutes at home.
Make the case
Waterproof and small, fix to the collar.
Test on a walk
Check the active time makes sense.
How do you build a pet activity collar?
A collar tag counts your dog's activity and rest and syncs when it comes back in Wi-Fi range. You need Seeed XIAO ESP32C3, LIS3DH accelerometer, Li-Po battery 3.7 V 500 mAh and TP4056 Charging Module. It takes 7 steps and about 180 minutes.
- Level
- Intermediate
- Time
- About 180 min
- Parts
- 4
Parts list
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| LIS3DH VCC and GND | XIAO 3V3 and GND | Power |
| LIS3DH SDA and SCL | XIAO D4 and D5 | I2C |
| LiPo | TP4056 B+ and B−, then XIAO BAT pads | Charging and power (the XIAO also charges the cell over USB-C) |
| Case | Waterproof box with the board and cell | Enclosure |
Code
The collar wakes about every 5 seconds, measures half a second of movement, adds 5 seconds to either the active or the rest counter and goes back to deep sleep, so the cell lasts days. Every 15 minutes it looks for the home Wi-Fi for a few seconds; if the dog is at home it uploads the totals to a small server on your own network and clears them, otherwise it keeps counting and tries again later. The server address and Wi-Fi details are placeholders for you to fill in, and the collector is yours: a tiny page that stores the numbers. For a dog's comfort and safety, the case should be small and light for the dog's size and secured to the collar, not hang loose, and the collar must be a breakaway or properly fitted type. Use a protected LiPo in a sealed, waterproof case, away from heat and chewing, and check the dog's skin regularly for rubbing. Never leave a dog wearing it while it charges, and do not use it on a very small pet. This is a curiosity tool and not a veterinary device; speak to a vet if you are worried about your pet's health. Arduino IDE with the ESP32 boards package 2.0.x, board "XIAO_ESP32C3".
Runs on a virtual Seeed XIAO ESP32-C3 in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Pet activity collar: count active minutes, sync when home. Libraries: Adafruit LIS3DH. Board: XIAO ESP32C3.
#include <Wire.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <Adafruit_LIS3DH.h>
const char* WIFI_SSID = "YOUR_HOME_WIFI";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
const char* SERVER = "http://192.168.1.50:5000/pet"; // your own collector on the home network (placeholder)
Adafruit_LIS3DH lis;
RTC_DATA_ATTR int activeSeconds = 0, restSeconds = 0, wakeCount = 0; // survive deep sleep
void setup() {
Wire.begin(); lis.begin(0x18); lis.setRange(LIS3DH_RANGE_4_G);
// measure movement for half a second
float sum = 0, prev = 9.8;
for (int i = 0; i < 10; i++) { sensors_event_t e; lis.getEvent(&e);
float m = sqrt(e.acceleration.x * e.acceleration.x + e.acceleration.y * e.acceleration.y + e.acceleration.z * e.acceleration.z);
sum += fabs(m - prev); prev = m; delay(50); }
if (sum / 10 > 0.4) activeSeconds += 5; else restSeconds += 5; // this wake stands for about 5 seconds
wakeCount++;
if (wakeCount >= 180) { // about every 15 minutes try to sync
wakeCount = 0;
WiFi.begin(WIFI_SSID, WIFI_PASS);
unsigned long t0 = millis();
while (WiFi.status() != WL_CONNECTED && millis() - t0 < 6000) delay(100);
if (WiFi.status() == WL_CONNECTED) { // at home: upload and clear the counters
HTTPClient http;
http.begin(String(SERVER) + "?active=" + activeSeconds + "&rest=" + restSeconds);
if (http.GET() == 200) { activeSeconds = 0; restSeconds = 0; }
http.end();
}
WiFi.disconnect(true);
}
esp_sleep_enable_timer_wakeup(4500000ULL); // sleep about 4.5 s
esp_deep_sleep_start();
}
void loop() {}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Seeed XIAO ESP32-C3 with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
[deep sleep for 4.5 s] ets Jul 29 2019 12:21:46 rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) [deep sleep for 4.5 s]
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Shake the board | Active seconds rise |
| Leave it on a table | Rest seconds rise |
| At home | Counters upload and clear |
| Out of range | Counters keep adding until home |
If it does not work
Never uploads
Check the Wi-Fi name, password and server address.
Always active
Raise the movement threshold.
Battery drains fast
Sync less often.
Case leaks
Use a gasket and check seals.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the pet activity collar?
Seeed XIAO ESP32C3, LIS3DH accelerometer, Li-Po battery 3.7 V 500 mAh and TP4056 Charging Module.
How long does the pet activity collar take to build?
About 180 minutes for a intermediate maker, in 7 steps.
How do I know the pet activity collar works?
Shake the board: Active seconds rise. Leave it on a table: Rest seconds rise. At home: Counters upload and clear.
Never uploads: what should I check?
Check the Wi-Fi name, password and server address.
Always active: what should I check?
Raise the movement threshold.
Battery drains fast: what should I check?
Sync less often.
Case leaks: what should I check?
Use a gasket and check seals.
