This project demonstrates how to build a security camera system leveraging Cloudflare Workers, Workers AI, and R2 for real-time object detection and storage. By using an ESP32-CAM to capture images and Cloudflare’s edge infrastructure for AI processing, this solution is scalable, cost-effective, and highly performant.
This project was made for a IRL meetup at the Cloudflare Lisbon Office.
- ESP32-CAM Integration: Captures images every 5 seconds and sends them to a Cloudflare Worker.
- Object Detection: Workers AI analyzes the images to detect objects, providing labels, bounding boxes, and confidence scores.
- Cloudflare R2 Storage: Stores images in Base64 format and object detection results as JSON files.
- Real-Time Web UI: Visualizes the results with red bounding boxes and labels for detected objects.
graph TD
A[ESP32-CAM] -->|Captures Image| B[Cloudflare Worker]
B -->|Sends to AI Model| C[Workers AI]
C -->|Detects Objects| D[Cloudflare R2]
D -->|Stores Images & Metadata| E[Real-Time Web UI]
E -->|Fetches Data| D
- ESP32-CAM module
- Cloudflare account with access to:
- Workers
- Workers AI
- R2 storage
All of the esp32-cam code is from https://RandomNerdTutorials.com/esp32-cam-http-post-php-arduino/ I've just added a simple blink feature when the esp is taking a picture.
Full code is available in the esp32-uploader.ino
- Update the code to point into your own worker and your WIFI ssid and password
- Flash your ESP32-CAM using the instruction in the RandomNerdTutorials linked above
Install dependencies and login with Cloudflare
npm install
npx wrangler loginCreate a R2 Bucket
npx wrangler r2 bucket create esp32-cam-with-workers-aiDeploy the worker
npx wrangler deploy- Power on the ESP32-CAM to start capturing images.
- Monitor the Web UI for real-time results.
- View stored images and detection metadata in R2.
This project is licensed under the MIT License.


