Connected
Mini camera
A small camera you watch live from a phone or computer on the same Wi-Fi. The camera is already on the board: there is nothing to wire.
- Medium
- about 35 min
- ESP32-S3 CAM
- 2 parts
- 105 lines of code
- Uses Wi-Fi
ESP32 packs are built on real parts: the simulator runs Arduino Uno circuits only.
Idea
The board takes a photo, squeezes it into a JPEG and hands it to the browser, several times a second. Nothing leaves your home network.
Before you start
Only point the camera at your own home, and never film people without asking them first. It has no password: do not put it on a public network.
What you learn
Starting a camera, serving images from a web server, and why a board needs extra memory for pictures.
How it works
input
OV2640 camera (on the board)
decides
ESP32-S3 CAM · Wi-Fi
output
A browser on your phone
Powered with 5 V through the board's USB-C port.
It joins your home Wi-Fi. You type the network name and password into the sketch before uploading; they stay on the board.
A reference design. The sketch is compiled with the real ESP32 toolchain, and its pins are checked against the wiring table automatically. It has not yet been built and tested on real parts by us, so wire it on the bench and run the checks before you build it into a case. Real modules vary: follow the labels printed on yours, not their position in the picture.
Parts
0 of 2 ready
No prices here: they change by shop and by week. Buy each part by its name and the note beside it.
You also need
A computer with Arduino IDE 2 installed (free)
3D wiring
Nothing to wire: everything this build needs is already on the board. Plug in the USB cable and go to the sketch.
mini-cam.ino
// Mini camera
// Watch the camera live from a phone or computer on the same Wi-Fi.
// Only point it at your own home, and never film people without asking.
//
// Camera pins below are the ESP32-S3-EYE layout, which the Freenove
// ESP32-S3-WROOM CAM also uses. If your board is different, copy its pins
// from the maker's page.
#include <WiFi.h>
#include <WebServer.h>
#include "esp_camera.h"
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
const int CAM_XCLK = 15;
const int CAM_SIOD = 4;
const int CAM_SIOC = 5;
const int CAM_Y9 = 16;
const int CAM_Y8 = 17;
const int CAM_Y7 = 18;
const int CAM_Y6 = 12;
const int CAM_Y5 = 10;
const int CAM_Y4 = 8;
const int CAM_Y3 = 9;
const int CAM_Y2 = 11;
const int CAM_VSYNC = 6;
const int CAM_HREF = 7;
const int CAM_PCLK = 13;
WebServer server(80);
const char PAGE[] PROGMEM = R"HTML(<!doctype html><meta name=viewport content="width=device-width,initial-scale=1">
<title>Mini camera</title><body style="margin:0;background:#111;color:#eee;font-family:sans-serif;text-align:center">
<h1 style="font-size:1.2rem;padding:.6rem">Mini camera</h1>
<img id=view style="max-width:100%;height:auto" alt="Live camera view">
<script>
// One frame after another: simple, and it works on every browser.
const view = document.getElementById('view');
function next() { view.src = '/frame.jpg?t=' + Date.now(); }
view.onload = () => setTimeout(next, 80);
view.onerror = () => setTimeout(next, 1000);
next();
</script></body>)HTML";
bool startCamera() {
camera_config_t config = {};
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = CAM_Y2;
config.pin_d1 = CAM_Y3;
config.pin_d2 = CAM_Y4;
config.pin_d3 = CAM_Y5;
config.pin_d4 = CAM_Y6;
config.pin_d5 = CAM_Y7;
config.pin_d6 = CAM_Y8;
config.pin_d7 = CAM_Y9;
config.pin_xclk = CAM_XCLK;
config.pin_pclk = CAM_PCLK;
config.pin_vsync = CAM_VSYNC;
config.pin_href = CAM_HREF;
config.pin_sccb_sda = CAM_SIOD;
config.pin_sccb_scl = CAM_SIOC;
config.pin_pwdn = -1;
config.pin_reset = -1;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
config.frame_size = FRAMESIZE_VGA;
config.jpeg_quality = 12;
config.fb_count = psramFound() ? 2 : 1;
config.fb_location = psramFound() ? CAMERA_FB_IN_PSRAM : CAMERA_FB_IN_DRAM;
config.grab_mode = CAMERA_GRAB_LATEST;
return esp_camera_init(&config) == ESP_OK;
}
void sendFrame() {
camera_fb_t* frame = esp_camera_fb_get();
if (!frame) {
server.send(503, "text/plain", "No frame");
return;
}
server.sendHeader("Cache-Control", "no-store");
server.send_P(200, "image/jpeg", (const char*)frame->buf, frame->len);
esp_camera_fb_return(frame);
}
void setup() {
Serial.begin(115200);
if (!startCamera()) {
Serial.println("Camera failed to start: check the camera pins for your board.");
while (true) delay(1000);
}
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) delay(250);
Serial.print("Open this address in a browser: http://");
Serial.println(WiFi.localIP());
server.on("/", []() { server.send_P(200, "text/html", PAGE); });
server.on("/frame.jpg", sendFrame);
server.begin();
}
void loop() {
server.handleClient();
}
Libraries
None. It uses only what the Arduino IDE has built in.
Uploading
First time with an ESP32: in Arduino IDE open Boards Manager, search “esp32” and install “esp32 by Espressif Systems”.
- Before uploading, type your Wi-Fi name and password into WIFI_SSID and WIFI_PASS at the top of the sketch.
- Open the sketch in Arduino IDE.
- Plug the board in with the USB-C cable.
- Tools > Board > ESP32S3 Dev Module (PSRAM: OPI PSRAM, Partition Scheme: Huge APP), then Tools > Port and choose the board's port.
- Press Upload (the arrow). Wait for “Done uploading”.