This project builds a low-power GPS and health monitoring collar for cats using an ESP32 microcontroller paired with an LTE-M/NB-IoT modem for global connectivity. The collar tracks location via GNSS, monitors heart rate with an optical sensor, and can trigger alerts through a piezo buzzer—all powered by a compact 500 mAh lithium battery designed for extended outdoor use.
The guide provides a complete wiring diagram, parts list, and step-by-step assembly instructions starting with a safe bench prototype. Firmware is included with simulation mode for testing without cellular service, plus support for real LTE-M connectivity and MQTT publishing when configured. Builders will learn how to integrate multiple sensors, manage power consumption through sleep modes, and send location and vital data to a remote server.
Wiring diagram

Gather all the parts
Assemble it in 6 steps
1. Power the bench prototype safely
Power the ESP32 through its USB socket. For real modem testing only, connect battery positive to modem VBAT and capacitor positive; connect battery negative, modem GND and capacitor striped negative to ESP32 GND. The battery does not power the ESP32.
- ESP32 DevKit has no battery charger. Never connect the LiPo to VIN or 3V3. Use a separate suitable charger with the battery disconnected.
2. Connect the modem for hardware testing
Use the same battery-input breakout with 3.3 V translated UART and active-low PWRKEY. GPIO17 goes to modem RXD (catalog host TX); GPIO16 goes to modem TXD (catalog host RX). Connect PWRKEY to GPIO25. Insert the SIM and connect antennas. These peripherals are not simulated.
- Do not connect a bare module with 1.8 V UART directly to the ESP32.
3. Connect the button and indicator
Connect the button between GPIO33 and GND. Connect GPIO26 to the 1 kΩ resistor, then to the LED anode (long leg). Connect the LED cathode to GND.
4. Keep this as a bench prototype
Simulation uses mock location data and console messages, not a cellular network. Keep the battery disconnected during simulation. This USB-powered development board is not an ultra-low-power finished collar.
- Do not put a breadboard or exposed battery on an animal.
5. Add the heartbeat breakout
Use a MAX30102 breakout with onboard regulation and I2C pull-ups to 3.3 V. Connect VCC to ESP32 3V3, GND to GND, SDA to GPIO21 (data), and SCL to GPIO22 (clock). Leave INT disconnected. Simulation prints clearly labeled synthetic BPM once per second, including during tracking cycles. The MAX30102 itself is not simulated and this firmware does not read it in hardware mode.
- BPM values are a software demonstration, not animal health measurements. Fur and movement prevent reliable optical readings on a collar. Do not use for medical or emergency decisions.
- Use a regulated 3.3 V breakout, not the bare 1.8 V IC. Do not attach this breadboard prototype to an animal.
6. Add the alert piezo
Connect GPIO19 to a 1 kΩ series resistor, then to the passive piezo SIG (positive) lead. Connect its GND lead to ESP32 GND. The resistor limits GPIO current to about 3.3 mA maximum. The firmware plays a short beep on an emergency trigger and two beeps when a transmission begins.
- Use a passive piezo, not a magnetic buzzer or a high-current active buzzer. Keep this audible bench demonstration off animals.
Review all connections
1. Connections between "battery" and "ESP32"
2. Connections between "modem" and "ESP32"
3. Connections between "button" and "ESP32"
4. Connections between "led_r" and "ESP32"
5. Connections between "status" and "ESP32"
6. Connections between "bulk" and "ESP32"
7. Connections between "heartbeat" and "ESP32"
8. Connections between "buzzer_r" and "ESP32"
9. Connections between "buzzer" and "ESP32"
Deploy the firmware
#include <Arduino.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>
#include <esp_sleep.h>
#include <driver/rtc_io.h>
// Virtual router credentials; use your actual network credentials on hardware.
const char WIFI_SSID[]="YOUR_WIFI_SSID";
const char WIFI_PASSWORD[]="";
const char WEBHOOK_URL[]="https://catcollar-demo.free.beeceptor.com";
// Default: interactive simulator demonstration with synthetic GPS/BPM.
// Simulator HTTP is mocked locally; hardware attempts real HTTP with mock fallback.
constexpr bool SIMULATION_MODE=true;
// ESP32 UART2: GPIO17 TX, GPIO16 RX; breakout must translate to 3.3 V.
constexpr uint8_t BUTTON=33, LED=26, KEY=25, BUZZER=19;
constexpr uint32_t INTERVAL_MS=15UL*60*1000, FIX_MS=120000;
// Set these three values to enable cellular MQTT. No public location broker default.
const char APN[]="";
const char BROKER[]="";
const char TOPIC[]="cat/test";
const char CLIENT_ID[]="cat-collar-change-me";
bool ledState=false;
uint32_t lastBlink=0;
uint32_t nextCycle=0;
bool previousButton=false;
// MAX30102 is wired on SDA=21, SCL=22. It has no simulator model.
// Demonstration values below are synthetic, NEVER measured cat vital signs.
// Real optical sensing through fur is unreliable and requires separate validation.
uint32_t lastBpmPrint=0;
int simulatedBpm=150;
void serviceHeartbeat() {
if (!SIMULATION_MODE || millis()-lastBpmPrint<1000) return;
lastBpmPrint=millis();
// Slow, deterministic variation to make the live demonstration visible.
const int demoBpm[]={150,152,154,152,150,148,146,148};
simulatedBpm=demoBpm[(millis()/1000)%8];
Serial.print("SIMULATED cat BPM: "); Serial.print(simulatedBpm);
Serial.println(" (demo only; not a sensor measurement)");
}
void blink() {
serviceHeartbeat();
if (millis()-lastBlink>=200) {
lastBlink=millis(); ledState=!ledState; digitalWrite(LED,ledState);
}
}
// Short tones keep the heartbeat console output serviced while sounding.
void beep(uint8_t count) {
for(uint8_t i=0;i<count;i++) {
tone(BUZZER,4000);
uint32_t start=millis();
while(millis()-start<120){serviceHeartbeat();delay(5);}
noTone(BUZZER);digitalWrite(BUZZER,LOW);
if(i+1<count) {
start=millis();
while(millis()-start<100){serviceHeartbeat();delay(5);}
}
}
}
// Local demo success is explicitly marked mock: it is NOT webhook delivery.
bool mockHttpResponse(const String &payload, const char *reason) {
beep(2);
Serial.print("MOCK HTTP POST telemetry: ");Serial.println(payload);
Serial.print("MOCK reason: ");Serial.println(reason);
Serial.println("MOCK HTTP response status: 200 OK");
Serial.println("MOCK success: telemetry accepted locally; NOT delivered to webhook.");
return true; // Demo success only, not proof of network delivery.
}
// Send once per hardware cycle, with a clearly labeled local fallback.
bool postTelemetry(const String &payload) {
if(SIMULATION_MODE) return mockHttpResponse(payload,"simulator mode");
if (WIFI_SSID[0]=='\0') {
Serial.println("HTTP skipped: WIFI_SSID is empty.");
return mockHttpResponse(payload,"empty Wi-Fi SSID");
}
if (WiFi.status()!=WL_CONNECTED) {
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID,WIFI_PASSWORD);
Serial.println("Connecting to Wi-Fi...");
uint32_t start=millis();
while(WiFi.status()!=WL_CONNECTED && millis()-start<15000) {
blink();delay(20);
}
}
if(WiFi.status()!=WL_CONNECTED) {
Serial.println("HTTP failed: Wi-Fi connection timed out.");
return mockHttpResponse(payload,"Wi-Fi connection failed");
}
WiFiClientSecure client;
// DEMO ONLY: encrypted HTTPS, but server certificate is NOT verified.
// For production, replace setInsecure() with setCACert(trustedRootCA).
// Never send private location/health data with this demo configuration.
client.setInsecure();
client.setHandshakeTimeout(10);
HTTPClient http;
http.setConnectTimeout(5000);
http.setTimeout(10000);
if(!http.begin(client,WEBHOOK_URL)) {
Serial.println("HTTP failed: could not initialize request.");
return mockHttpResponse(payload,"request initialization failed");
}
http.addHeader("Content-Type","application/json");
beep(2); // An attempt, not confirmation of successful delivery.
Serial.print("HTTP POST telemetry: ");Serial.println(payload);
int status=http.POST(payload);
if(status>0) {
Serial.print("HTTP response status: ");Serial.println(status);
} else {
Serial.print("HTTP transport error: ");Serial.println(HTTPClient::errorToString(status));
}
bool sent=status>=200 && status<300;
http.end();
Serial.println(sent?"Webhook accepted telemetry.":"Webhook delivery failed (not retried).");
if(!sent) return mockHttpResponse(payload,"real HTTP POST failed; see actual error above");
return true;
}
// Bounded response buffer and deadlines prevent endless network retries.
String receive(uint32_t timeout, const char *end="\r\nOK\r\n") {
String s; s.reserve(768);
uint32_t start=millis();
while(millis()-start<timeout) {
while(Serial2.available()) {
char c=Serial2.read();
if(s.length()<1500) s+=c;
if(s.indexOf(end)>=0 || s.indexOf("ERROR")>=0) return s;
}
blink(); delay(10);
}
return s;
}
String command(const String &cmd,uint32_t timeout=2000) {
while(Serial2.available()) Serial2.read();
Serial2.println(cmd); return receive(timeout);
}
bool ok(const String &cmd,uint32_t timeout=2000) {
return command(cmd,timeout).indexOf("\r\nOK\r\n")>=0;
}
// Open-drain key: never drive the key's internal pullup to 3.3 V.
void releaseKey() { pinMode(KEY,INPUT); }
bool startModem() {
Serial2.begin(115200,SERIAL_8N1,16,17);
if(ok("AT")) return true; // Avoid toggling an already-running modem off.
digitalWrite(KEY,LOW); pinMode(KEY,OUTPUT); delay(1100);
releaseKey(); delay(3000);
for(int i=0;i<5;i++) if(ok("AT")) {ok("ATE0"); return true;}
return false;
}
String field(const String &s,int n) {
int begin=0;
for(int i=0;i<n;i++) {begin=s.indexOf(',',begin); if(begin<0)return ""; begin++;}
int end=s.indexOf(',',begin); if(end<0)end=s.length();
String v=s.substring(begin,end);v.trim();return v;
}
bool gps(String &lat,String &lon) {
if(!ok("AT+CGNSPWR=1")) return false;
uint32_t start=millis();
while(millis()-start<FIX_MS) {
String r=command("AT+CGNSINF");
int p=r.indexOf("+CGNSINF:");
if(p>=0) {
String info=r.substring(p+9); info.trim();
if(field(info,1)=="1") {
lat=field(info,3);lon=field(info,4);
if(lat.length() && lon.length()) return true;
}
}
for(int i=0;i<100;i++){blink();delay(20);}
}
return false;
}
bool sendCellular(const String &payload) {
if(!APN[0] || !BROKER[0]) return false;
if(!ok("AT+CPIN?"))return false;
ok("AT+CNMP=38"); ok("AT+CMNB=3"); // LTE-M or NB-IoT, as available.
uint32_t start=millis();bool registered=false;
while(millis()-start<90000) {
String r=command("AT+CEREG?");
if(r.indexOf(",1")>=0 || r.indexOf(",5")>=0){registered=true;break;}
delay(1000);
}
if(!registered)return false;
if(!ok(String("AT+CNCFG=0,1,\"")+APN+"\""))return false;
if(!ok("AT+CNACT=0,1",15000))return false;
delay(3000);
if(!ok(String("AT+SMCONF=\"URL\",\"")+BROKER+"\",1883"))return false;
ok(String("AT+SMCONF=\"CLIENTID\",\"")+CLIENT_ID+"\"");
ok("AT+SMCONF=\"KEEPTIME\",60");ok("AT+SMCONF=\"CLEANSS\",1");
if(!ok("AT+SMCONN",20000))return false;
while(Serial2.available())Serial2.read();
Serial2.println(String("AT+SMPUB=\"")+TOPIC+"\","+payload.length()+",1,0");
if(receive(5000,">").indexOf('>')<0)return false;
beep(2); // Payload transmission is starting, not proof of delivery.
Serial2.print(payload); // Exact length, no extra newline.
bool sent=receive(15000).indexOf("\r\nOK\r\n")>=0;
ok("AT+SMDISC");return sent;
}
// Simulator uses short, non-blocking idle intervals instead of deep sleep,
// so the interactive button remains usable even without sleep emulation.
void setup() {
Serial.begin(115200);
pinMode(BUZZER,OUTPUT);digitalWrite(BUZZER,LOW);
pinMode(LED,OUTPUT);digitalWrite(LED,LOW);releaseKey();
pinMode(BUTTON,INPUT_PULLUP);
if(SIMULATION_MODE) {
Serial.println("SIMULATION: synthetic GPS/BPM; local MOCK HTTP 200, no network request. Timer every 30 seconds.");
Serial.println("MAX30102 has no simulator model: BPM values are synthetic.");
nextCycle=millis()+30000;
}
}
void runCycle(bool emergency) {
if(emergency) beep(1);
ledState=true;digitalWrite(LED,HIGH);
String lat,lon;bool ready=false,fixed=false;
if(SIMULATION_MODE) {
Serial.println("SIMULATION: acquiring mock GPS fix...");
uint32_t start=millis();
while(millis()-start<2000){blink();delay(10);}
lat="51.500700";lon="-0.124600";fixed=true;
} else {ready=startModem();fixed=ready && gps(lat,lon);}
String payload=String("{\"simulated\":")+(SIMULATION_MODE?"true":"false")+
",\"alert\":"+(emergency?"true":"false")+
",\"bpm\":"+(SIMULATION_MODE?String(simulatedBpm):String("null"))+
",\"fix\":"+(fixed?"true":"false")+",\"lat\":"+
(fixed?lat:"null")+",\"lon\":"+(fixed?lon:"null")+"}";
postTelemetry(payload);
if(SIMULATION_MODE) {
Serial.print("SIMULATED SENSOR TELEMETRY: ");Serial.println(payload);
uint32_t start=millis();while(millis()-start<2000){blink();delay(10);}
} else {
if(ready)ok("AT+CGNSPWR=0");
bool sent=ready && sendCellular(payload);
Serial.println(payload);Serial.println(sent?"MQTT accepted":"MQTT not sent");
if(ready)command("AT+CPOWD=1",5000);
Serial2.end();pinMode(16,INPUT);pinMode(17,INPUT);releaseKey();
}
digitalWrite(LED,LOW);ledState=false;
}
void loop() {
serviceHeartbeat();
if(SIMULATION_MODE) {
bool pressed=digitalRead(BUTTON)==LOW;
bool emergency=pressed && !previousButton;
previousButton=pressed;
if(emergency || (int32_t)(millis()-nextCycle)>=0) {
delay(30);
runCycle(emergency);
previousButton=digitalRead(BUTTON)==LOW;
nextCycle=millis()+30000;
Serial.println("SIMULATION: idle, waiting for button or timer.");
}
delay(10);return;
}
// Real hardware: wake every 15 minutes or when GPIO33 is pulled low.
esp_sleep_wakeup_cause_t cause=esp_sleep_get_wakeup_cause();
runCycle(cause==ESP_SLEEP_WAKEUP_EXT0);
while(digitalRead(BUTTON)==LOW)delay(50); // Avoid immediate held-button wake.
rtc_gpio_pullup_en(GPIO_NUM_33);rtc_gpio_pulldown_dis(GPIO_NUM_33);
esp_sleep_enable_ext0_wakeup(GPIO_NUM_33,0);
esp_sleep_enable_timer_wakeup((uint64_t)INTERVAL_MS*1000ULL);
Serial.println("Entering deep sleep.");Serial.flush();
esp_deep_sleep_start();
}Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




