🐱 CatSpy v1

A motion-triggered ESP32-CAM cat detection system

Status: Fully working prototype! Motion detection, photo capture, and email delivery all confirmed on breadboard/socket build. Next: permanently soldering the sensor wiring and building a proper enclosure.

The goal

Detect a cat, take a photo, and send it straight to email — automatically, over WiFi, with no manual intervention. No SD card, no screen, no cloud subscription needed.

When the PIR motion sensor detects movement (ideally the cat), the ESP32-CAM wakes up, takes a photo, and emails it over WiFi. This is now working as a full loop on the breadboard prototype.

Prototype photos

ESP32-CAM and PIR sensor wired on stripboard, held in helping-hands clamps
PIR sensor + ESP32-CAM wired on stripboard, held in helping hands for testing
Prototype powered on via USB power bank
Running from a USB power bank during testing
Close-up of the ESP32-CAM board and camera module
ESP32-CAM board close-up — OV2640 160° wide-angle camera module
First test photo captured by the ESP32-CAM
A test capture, delivered by email exactly as designed
ESP32-CAM-MB USB programmer board used for flashing code
The USB programmer board used to flash new code onto the ESP32-CAM
Underside of the hand-soldered header pin board
Underside of the header-pin test board, hand-soldered

Key design decisions

DecisionChoiceWhy
MicrocontrollerESP32-CAMBuilt-in WiFi and camera support in one small board
Motion detectionHC-SR501 PIR sensorSimple, reliable, low cost — detects body heat movement
Photo deliveryEmail via WiFi (SMTP)No SD card needed — photos go straight to the inbox
Camera sensorOV2640 wide angleWide field of view catches more of the room
Power logic3.3VESP32 runs at 3.3V — 5V on the GPIO pins would damage it
Secrets handlingSeparate secrets.h fileKeeps WiFi and email credentials out of the shared/published code

Build progress

PhaseTaskStatus
Phase 1Install Arduino IDE + ESP32 board support✅ Done
Phase 1Set up Gmail App Password✅ Done
Phase 1Build socket/header test board (soldering practice)✅ Done
Phase 2Wire PIR sensor to ESP32-CAM on breadboard✅ Done
Phase 2Upload and test WiFi connection✅ Done
Phase 3Camera capture code✅ Done
Phase 3Email send with photo attachment✅ Done
Phase 3End-to-end test: motion → photo → email✅ Done — working!
Phase 4Permanently solder PIR sensor wiring to ESP32-CAMTODO — next up
Phase 4 (future)Add SG90 pan/tilt servo mountFuture
Phase 4 (future)Proper enclosure (currently: takeaway container plan)Future
Build order: WiFi was tested on its own first, then camera capture, then email — one layer at a time, so any problem was always easy to trace back to a single change.

Wiring reference

SignalESP32-CAM PinNotes
PIR data outputGPIO13Safe input pin on the ESP32-CAM
Ground (GND)GNDConnect to PIR GND
Power (3.3V)3.3VConnect to PIR VCC — never use 5V on GPIO pins
Flash modeGPIO0 (IO0 button)Hold LOW during power-on to enter upload/programming mode

The code (core logic)

Below is the heart of the sketch — motion detection triggering a photo capture and email delivery. WiFi and email credentials are kept out of this file, in a separate secrets.h that isn't published.

secrets.h

#define WIFI_SSID "your-wifi-name"
#define WIFI_PASSWORD "your-wifi-password"
#define SENDER_EMAIL "[email protected]"
#define SENDER_PASSWORD "your-gmail-app-password"
#define RECIPIENT_EMAIL "[email protected]"

Motion detection and email send

#include "secrets.h"

#define PIR_PIN 13
#define FLASH_GPIO 4

SMTPSession smtp;

void sendPhoto() {
  digitalWrite(FLASH_GPIO, HIGH);
  delay(2000);
  camera_fb_t * fb = esp_camera_fb_get();
  digitalWrite(FLASH_GPIO, LOW);
  if (!fb) {
    Serial.println("Camera capture failed");
    return;
  }
  Serial.println("Photo taken — sending email...");

  ESP_Mail_Session session;
  session.server.host_name = "smtp.gmail.com";
  session.server.port = 465;
  session.login.email = SENDER_EMAIL;
  session.login.password = SENDER_PASSWORD;
  session.login.user_domain = "";

  SMTP_Message message;
  message.sender.name = "CatSpy";
  message.sender.email = SENDER_EMAIL;
  message.subject = "Cat detected!";
  message.addRecipient("Owner", RECIPIENT_EMAIL);
  message.text.content = "Motion detected — photo attached!";

  SMTP_Attachment attachment;
  attachment.descr.filename = "cat.jpg";
  attachment.descr.mime = "image/jpg";
  attachment.blob.data = fb->buf;
  attachment.blob.size = fb->len;
  attachment.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64;
  message.addAttachment(attachment);

  smtp.debug(1);
  if (!smtp.connect(&session)) {
    Serial.println("Email connection failed");
    esp_camera_fb_return(fb);
    return;
  }
  if (!MailClient.sendMail(&smtp, &message)) {
    Serial.println("Email send failed: " + smtp.errorReason());
  } else {
    Serial.println("Email sent successfully!");
  }
  esp_camera_fb_return(fb);
}

void loop() {
  if (digitalRead(PIR_PIN) == HIGH) {
    Serial.println("Motion detected! 🐱");
    sendPhoto();
    Serial.println("Cooling down for 30 seconds...");
    delay(30000);
  }
}