Skip to content
Buy 10+ on select items — save 10% auto-applied
Free US shipping on orders $35+
Order by 3pm ET — ships same-day from the US
Skip to main content

ESP32-CAM HC-SR501 PIR: Motion Photo Alerts via Wi-Fi | ShillehTek

May 20, 2026 28 views

ESP32-CAM HC-SR501 PIR: Motion Photo Alerts via Wi-Fi | ShillehTek
Project

Build an ESP32-CAM doorbell with an HC-SR501 PIR sensor that snaps a photo on motion, saves to microSD, and sends Wi-Fi alerts using ShillehTek parts.

1.5 hr Intermediate6 parts

Project Overview

ESP32-CAM + HC-SR501 PIR doorbell: An HC-SR501 PIR sensor watches the doorway and, when motion is detected, the ESP32-CAM snaps a photo, saves it to a microSD card, and sends it over Wi-Fi (email, or Telegram if you prefer). The build can be battery-powered, hidden in a small enclosure, and optimized for long runtime with deep-sleep.

  • Time: ~1.5 hours
  • Skill level: Intermediate
  • What you will build: A standalone doorbell camera that emails a photo every time someone approaches.
ESP32-CAM doorbell project with HC-SR501 PIR sensor triggering photo capture and Wi-Fi alerts
ESP32-CAM + PIR + microSD + Wi-Fi = motion-triggered photo alerts.

Parts List

From ShillehTek

External

  • microSD card (≤32 GB) - storage for photos.
  • 18650 LiPo cell - battery power source.
  • Gmail account (or Telegram bot) - delivery endpoint for alerts.

Note: The ESP32-CAM has no built-in USB. Flash via the CP2102 USB-to-TTL adapter, then power the deployed unit from the TP4056 + 18650.

Step-by-Step Guide

Step 1 - Gather the components

Goal: Confirm you have the ESP32-CAM, PIR sensor, and microSD storage ready before wiring.

What to do: Collect the ESP32-CAM module, HC-SR501 PIR sensor, and microSD hardware (card and adapter/slot). Verify your power plan (TP4056 + 18650) and your programming method (CP2102 USB-to-TTL).

ESP32-CAM board shown with HC-SR501 PIR motion sensor and microSD adapter for motion-triggered photo alerts
ESP32-CAM + HC-SR501 PIR + microSD adapter.

Expected result: All parts are on hand and you know how the device will be powered and programmed.

Step 2 - Wire the PIR and power

Goal: Connect the HC-SR501 output to the ESP32-CAM so motion can trigger a capture, and provide stable power.

What to do: Wire the PIR sensor to the ESP32-CAM and connect power as listed below.

Wiring diagram showing ESP32-CAM connected to HC-SR501 PIR sensor with PIR OUT going to GPIO 13 and power routed from TP4056
PIR OUT to GPIO 13. microSD uses the ESP32-CAM built-in SD pins.
  • HC-SR501 VCC to 5V, GND to GND, OUT to GPIO 13
  • ESP32-CAM has a built-in SD slot - no extra wiring needed
  • Power: TP4056 + 18650 to ESP32-CAM 5V pin

Expected result: The PIR sensor is connected to GPIO 13 and the ESP32-CAM can be powered reliably for testing and deployment.

Step 3 - Upload the email sketch and test

Goal: Connect to Wi-Fi, capture a photo with the ESP32-CAM, and send it via email when motion is detected.

What to do: Install ESP Mail Client by Mobizt via the Arduino Library Manager. Create an app-password on your Gmail account for SMTP. Update Wi-Fi credentials and email settings in the sketch, then flash it to the ESP32-CAM using your USB-to-TTL adapter.

Flow diagram for ESP32-CAM motion alert sequence: sleep, wake on PIR, initialize camera, snap photo, email, then return to sleep
Sleep to wake on PIR to snap photo to email to back to sleep.

Code:

#include <WiFi.h>
#include <esp_camera.h>
#include <ESP_Mail_Client.h>
#define PIR_PIN 13
const char* SSID = "WIFI";
const char* PASS = "PWD";
const char* FROM = "you@gmail.com";
const char* APP_PASS = "GMAIL_APP_PASSWORD";
const char* TO = "you@gmail.com";
SMTPSession smtp;

void setup() {
  Serial.begin(115200);
  pinMode(PIR_PIN, INPUT);
  WiFi.begin(SSID, PASS);
  while (WiFi.status() != WL_CONNECTED) delay(500);
  // camera_config + esp_camera_init(&config) goes here
}

void snapAndEmail() {
  camera_fb_t *fb = esp_camera_fb_get();
  // attach fb->buf as JPEG to the SMTP message, send via smtp.connect + MailClient.sendMail
  esp_camera_fb_return(fb);
}

void loop() {
  if (digitalRead(PIR_PIN) == HIGH) {
    snapAndEmail();
    delay(60000);   // 1 min cooldown
  }
  delay(200);
}

Expected result: When the PIR detects motion, the ESP32-CAM captures an image and sends it through your configured delivery method (email in this sketch).

Step 4 - Extend the project (optional)

Goal: Plan upgrades without changing the core motion-to-photo workflow.

What to do: Choose one of the enhancements below to match your use case.

  • Add deep-sleep with EXT0 wake-on-PIR for much longer battery life
  • Post photos to a Telegram bot instead of email for faster phone alerts
  • Upload to AWS S3 with timestamps for a cloud-stored event log
  • Add a relay-controlled chime + LED for a full smart doorbell

Expected result: You have a clear next step to improve battery life or notifications while keeping the same trigger and capture logic.

Conclusion

This build uses an ESP32-CAM and an HC-SR501 PIR sensor to detect motion, capture a photo, save it to microSD, and send an alert over Wi-Fi. It is a practical way to turn a low-cost camera module into a simple doorbell-style security notifier.

Want the exact parts used in this build? Grab them from ShillehTek.com. If you want help customizing this project or building something for your product, check out our IoT consulting services.