Projects / Pet activity collar

Pet activity collar

Intermediate3 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32

    Test the sensor

    Print movement while shaking.

  2. ESP32

    Separate active and rest

    Choose a threshold.

  3. ESP32

    Add deep sleep

    Wake every 5 seconds.

  4. ESP32

    Keep the counters

    Use RTC memory.

  5. ESP32

    Add the Wi-Fi sync

    Upload every 15 minutes at home.

  6. ESP32

    Make the case

    Waterproof and small, fix to the collar.

  7. ESP32

    Test on a walk

    Check the active time makes sense.

In short

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

FromToWhy
LIS3DH VCC and GNDXIAO 3V3 and GNDPower
LIS3DH SDA and SCLXIAO D4 and D5I2C
LiPoTP4056 B+ and B−, then XIAO BAT padsCharging and power (the XIAO also charges the cell over USB-C)
CaseWaterproof box with the board and cellEnclosure

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.

CheckExpected
Shake the boardActive seconds rise
Leave it on a tableRest seconds rise
At homeCounters upload and clear
Out of rangeCounters 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 →

Ask Lark AI

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.