Ugenz Academy/IoT Tutorial

Esp32 Camera And Streaming

11 min read2,191 words

Reading progress

Keep learning

ESP32-CAM and Streaming

ESP32-CAM is an ESP32-based development board that adds a camera, usually an OV2640, allowing you to build projects such as:

  • 📸 Web-based camera
  • 🎥 Live video streaming
  • 🏠 Smart security camera
  • 🚪 Door monitoring
  • 👤 Motion detection
  • 💾 Image storage on microSD
  • 🌐 Wi-Fi surveillance system
  • 🤖 Camera-based robotics

A simple architecture is:

📷 Camera ↓ ┌────────────┐ │ ESP32-CAM │ └────────────┘ ↓ Wi-Fi ┌────────────┐ │ Router │ └────────────┘ ↓ ┌─────────────────┐ │ Phone / Laptop │ │ Web Browser │ └─────────────────┘

1. What is ESP32-CAM?

ESP32-CAM is essentially:

ESP32 + Camera + Wi-Fi + Bluetooth + microSD

The ESP32 processes the camera data and can send images/video over Wi-Fi.

A very common board is the AI Thinker ESP32-CAM.


2. Main Components

Typical AI Thinker ESP32-CAM contains:

ComponentPurpose
ESP32Main microcontroller
OV2640Camera
Wi-FiWireless communication
BluetoothWireless communication
microSD slotImage/file storage
Flash LEDCamera illumination
Reset buttonRestart board
GPIO pinsExternal sensors/devices
PSRAMExtra memory for camera data

3. OV2640 Camera

The camera commonly used with ESP32-CAM is:

OV2640

It captures images that the ESP32 processes.

Conceptually:

Light ↓ OV2640 Camera ↓ Digital Image Data ↓ ESP32 ↓ JPEG ↓ Wi-Fi ↓ Browser

The camera itself does not provide Wi-Fi.

The ESP32 handles the networking.


4. ESP32-CAM Does Not Usually Have USB

This is very important.

Many AI Thinker ESP32-CAM boards don't have a USB connector.

Therefore, for programming you commonly need:

USB-to-TTL / FTDI adapter

Example:

Computer │ │ USB ↓ USB-to-TTL │ ├── TX ├── RX ├── GND └── 5V │ ↓ ESP32-CAM

Programming connections

Typical connection:

USB-TTLESP32-CAM
TXU0R / RX0
RXU0T / TX0
GNDGND
PowerBoard-appropriate power pin

Notice:

TX → RX RX → TX

Not:

TX → TX ❌ RX → RX ❌

5. GPIO0 and Programming Mode

This is one of the most important ESP32-CAM procedures.

For uploading firmware:

GPIO0 → GND

Then reset the board.

After programming:

GPIO0 → Disconnect from GND

Then reset again.

Why?

GPIO0 determines the boot mode.

GPIO0 = GND ↓ Download / Flash Mode

Whereas normal operation requires GPIO0 not to be held low during boot.

Common mistake

You successfully upload the program but the camera doesn't start.

Often:

GPIO0 still connected to GND

Remove it and press RST.


6. AI Thinker ESP32-CAM Camera Pins

For the common AI Thinker ESP32-CAM, the camera uses many GPIOs internally.

Typical mapping:

#define PWDN_GPIO_NUM 32 #define RESET_GPIO_NUM -1 #define XCLK_GPIO_NUM 0 #define SIOD_GPIO_NUM 26 #define SIOC_GPIO_NUM 27 #define Y9_GPIO_NUM 35 #define Y8_GPIO_NUM 34 #define Y7_GPIO_NUM 39 #define Y6_GPIO_NUM 36 #define Y5_GPIO_NUM 21 #define Y4_GPIO_NUM 19 #define Y3_GPIO_NUM 18 #define Y2_GPIO_NUM 5 #define VSYNC_GPIO_NUM 25 #define HREF_GPIO_NUM 23 #define PCLK_GPIO_NUM 22

⚠️ Important: GPIO assignments are board-specific. Don't use this mapping blindly on another ESP32-CAM variant.


7. Why Does the Camera Need So Many GPIOs?

A camera needs multiple signals.

For example:

Camera │ ├── Data D0 ├── Data D1 ├── Data D2 ├── Data D3 ├── Data D4 ├── Data D5 ├── Data D6 ├── Data D7 │ ├── Clock ├── VSYNC ├── HREF ├── SCCB/I2C └── XCLK

That's why ESP32-CAM has fewer freely available GPIOs than a normal ESP32 development board.


8. Initialize the Camera

A simplified camera configuration looks like:

#include "esp_camera.h" camera_config_t config; config.pixel_format = PIXFORMAT_JPEG; config.frame_size = FRAMESIZE_VGA; config.jpeg_quality = 10; config.fb_count = 2;

Then:

esp_err_t err = esp_camera_init(&config); if (err != ESP_OK) { Serial.printf("Camera init failed: 0x%x\n", err); }

If initialization succeeds:

Camera initialized ✅

9. Frame Size

ESP32-CAM can capture different resolutions.

Common examples:

Frame sizeApprox. resolution
QQVGA160 × 120
QVGA320 × 240
VGA640 × 480
SVGA800 × 600
XGA1024 × 768
SXGA1280 × 1024
UXGA1600 × 1200

Higher resolution means:

Better image + More memory + More processing + More bandwidth

So don't always select the maximum resolution.


10. What is PSRAM?

PSRAM means:

Pseudo Static RAM

Camera applications can require much more memory than a normal ESP32 application.

For example:

Normal ESP32 RAM ↓ Small camera buffers PSRAM ↓ Larger image buffers ↓ Higher resolution / multiple frame buffers

That's why many ESP32-CAM boards include PSRAM.

You can check:

if (psramFound()) { Serial.println("PSRAM found!"); } else { Serial.println("PSRAM not found!"); }

11. Snapshot vs Streaming

These are different.

📸 Snapshot

The browser requests:

/capture

ESP32-CAM:

Capture one image ↓ JPEG ↓ Send to browser

Result:

📸 One picture

🎥 Streaming

Streaming continuously sends frames:

Frame 1 ↓ Frame 2 ↓ Frame 3 ↓ Frame 4 ↓ Frame 5 ↓ ...

Conceptually:

Camera ↓ Frame ↓ JPEG ↓ Wi-Fi ↓ Browser ↓ Display ↓ Next Frame ↓ Next Frame

A common technique is MJPEG streaming.


12. ESP32-CAM Web Server

The famous Arduino example is:

File ↓ Examples ↓ ESP32 ↓ Camera ↓ CameraWebServer

The application basically does:

ESP32-CAM │ ├── Camera initialization │ ├── Wi-Fi connection │ ├── Web server │ ├── Capture endpoint │ └── Stream endpoint

After connecting to Wi-Fi, Serial Monitor might show:

WiFi connected Camera Ready! Use 'http://192.168.1.25' to connect

Then open:

http://192.168.1.25

on your phone or laptop connected to the same network.


13. Basic ESP32-CAM Initialization Example

For the common AI Thinker board:

#include "esp_camera.h" #include <WiFi.h> const char* ssid = "YOUR_WIFI"; const char* password = "YOUR_PASSWORD"; // AI Thinker ESP32-CAM #define PWDN_GPIO_NUM 32 #define RESET_GPIO_NUM -1 #define XCLK_GPIO_NUM 0 #define SIOD_GPIO_NUM 26 #define SIOC_GPIO_NUM 27 #define Y9_GPIO_NUM 35 #define Y8_GPIO_NUM 34 #define Y7_GPIO_NUM 39 #define Y6_GPIO_NUM 36 #define Y5_GPIO_NUM 21 #define Y4_GPIO_NUM 19 #define Y3_GPIO_NUM 18 #define Y2_GPIO_NUM 5 #define VSYNC_GPIO_NUM 25 #define HREF_GPIO_NUM 23 #define PCLK_GPIO_NUM 22 void setup() { Serial.begin(115200); camera_config_t config; config.ledc_channel = LEDC_CHANNEL_0; config.ledc_timer = LEDC_TIMER_0; config.pin_d0 = Y2_GPIO_NUM; config.pin_d1 = Y3_GPIO_NUM; config.pin_d2 = Y4_GPIO_NUM; config.pin_d3 = Y5_GPIO_NUM; config.pin_d4 = Y6_GPIO_NUM; config.pin_d5 = Y7_GPIO_NUM; config.pin_d6 = Y8_GPIO_NUM; config.pin_d7 = Y9_GPIO_NUM; config.pin_xclk = XCLK_GPIO_NUM; config.pin_pclk = PCLK_GPIO_NUM; config.pin_vsync = VSYNC_GPIO_NUM; config.pin_href = HREF_GPIO_NUM; config.pin_sscb_sda = SIOD_GPIO_NUM; config.pin_sscb_scl = SIOC_GPIO_NUM; config.pin_pwdn = PWDN_GPIO_NUM; config.pin_reset = RESET_GPIO_NUM; config.xclk_freq_hz = 20000000; config.pixel_format = PIXFORMAT_JPEG; if (psramFound()) { config.frame_size = FRAMESIZE_VGA; config.jpeg_quality = 10; config.fb_count = 2; } else { config.frame_size = FRAMESIZE_QVGA; config.jpeg_quality = 12; config.fb_count = 1; } esp_err_t err = esp_camera_init(&config); if (err != ESP_OK) { Serial.printf( "Camera initialization failed: 0x%x\n", err ); return; } Serial.println("Camera initialized!"); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(); Serial.println("WiFi connected!"); Serial.print("IP Address: "); Serial.println(WiFi.localIP()); } void loop() { }

⚠️ This example initializes the camera and connects Wi-Fi, but it does not itself implement the /capture and /stream web endpoints. For actual live streaming, use the Arduino ESP32 CameraWebServer example as the starting point.


14. Camera + Browser Architecture

A complete camera project looks like:

┌───────────────┐ │ OV2640 │ │ Camera │ └───────┬───────┘ ↓ ┌───────────────┐ │ ESP32-CAM │ └───────┬───────┘ │ Wi-Fi │ ↓ ┌───────────────┐ │ Router │ └───────┬───────┘ │ ┌──────────┴──────────┐ ↓ ↓ 📱 Phone 💻 Laptop │ │ └────── Browser ──────┘

15. ESP32-CAM + microSD

The ESP32-CAM can also save images to a microSD card.

For example:

PIR detects movement ↓ ESP32-CAM captures image ↓ JPEG ↓ microSD ↓ /photo001.jpg

This is perfect for a security camera.

Example folder:

/photos/ photo001.jpg photo002.jpg photo003.jpg

16. ESP32-CAM + PIR Security Camera

This is especially useful for your Smart Home project.

PIR Sensor │ ↓ Motion detected │ ↓ ESP32-CAM │ ┌────┴────┐ ↓ ↓ Capture Flash LED │ ↓ JPEG │ ┌────┴─────┐ ↓ ↓ microSD Wi-Fi │ ↓ Phone / Cloud

Example:

#define PIR_PIN 13 void setup() { pinMode(PIR_PIN, INPUT); } void loop() { if (digitalRead(PIR_PIN)) { Serial.println("Motion detected!"); // Capture image here } }

⚠️ On ESP32-CAM, GPIO availability is board-specific because many pins are already occupied by the camera/SD interface.


17. ESP32-CAM + Flash LED

Many AI Thinker ESP32-CAM boards use:

#define FLASH_LED 4

Then:

pinMode(FLASH_LED, OUTPUT); digitalWrite(FLASH_LED, HIGH);

Turn off:

digitalWrite(FLASH_LED, LOW);

Again, verify the exact board because GPIO assignments can vary.


18. Security Camera Example

Your final system could become:

🏠 SMART HOME │ ┌────────┴────────┐ │ │ PIR Sensor ESP32-CAM │ │ Movement ↓ │ Capture │ │ └────────→ Security Event │ ┌────────┴────────┐ ↓ ↓ microSD Wi-Fi │ ┌───────┴───────┐ ↓ ↓ Phone Laptop

You could then combine this with:

  • 🔔 Buzzer
  • 💡 Light
  • 🚪 Servo door lock
  • 📱 Notification
  • 💾 SD storage
  • 🌐 Web dashboard

19. ESP32-CAM + Your Smart Home Project

A powerful version of your project would be:

SMART HOME │ ┌───────────────┼────────────────┐ │ │ │ PIR RFID LDR │ │ │ └───────────────┼────────────────┘ ↓ ESP32 │ ┌──────────┴──────────┐ ↓ ↓ Relay ESP32-CAM │ │ Light / Fan Camera │ Motion Capture │ Wi-Fi / SD │ 📱

This would make your physical IoT ZONE Smart Home project much more impressive.


20. Camera + Web Dashboard

You can also create your own dashboard instead of using the default CameraWebServer interface.

For example:

┌─────────────────────────────────┐ │ 🏠 SMART HOME │ ├─────────────────────────────────┤ │ │ │ 📷 LIVE CAMERA │ │ │ │ ┌─────────────────┐ │ │ │ │ │ │ │ LIVE VIDEO │ │ │ │ │ │ │ └─────────────────┘ │ │ │ │ 💡 LIGHT 🌀 FAN │ │ [ ON ] [ ON ] │ │ │ │ 🚪 DOOR 🔒 SECURITY │ │ [OPEN] [ARMED] │ │ │ └─────────────────────────────────┘

Since you already work with React/Next.js/Tailwind, you could eventually build a much better UI and communicate with the ESP32 through HTTP/WebSocket/MQTT.


21. Important Power Issue

ESP32-CAM cameras can be sensitive to unstable power.

If you see:

Brownout detector was triggered

or:

Camera init failed

or random resets,

don't immediately assume the code is wrong.

Possible causes:

  • Weak power supply
  • Poor USB-to-TTL adapter
  • Long/thin wires
  • Incorrect voltage
  • Camera ribbon cable problem

And remember:

ESP32 GPIO is 3.3V logic.

Don't put 5V directly into ESP32 GPIO pins.

Power-pin behavior is also board-specific, so check your ESP32-CAM board's labeling/schematic before feeding 5V.


22. Common ESP32-CAM Problems

❌ Upload doesn't start

Check:

GPIO0 → GND

during flashing.


❌ Upload succeeds but camera doesn't run

Check:

GPIO0 disconnected from GND

Then press:

RST

❌ Camera initialization failed

Check:

  • Correct camera model
  • Correct GPIO mapping
  • Camera ribbon cable
  • Power
  • PSRAM settings

❌ Brownout/reset

Usually investigate:

Power supply → wiring → current capability

❌ Image is black

Check:

  • Camera ribbon connection
  • Camera orientation
  • Camera module
  • Flash/lighting
  • Camera configuration

❌ Stream is slow

Try:

Lower resolution + Higher JPEG compression + Stable Wi-Fi

For example:

config.frame_size = FRAMESIZE_QVGA;

instead of:

config.frame_size = FRAMESIZE_UXGA;

23. Snapshot vs Streaming

FeatureSnapshotStreaming
ImageOneContinuous
BandwidthLowHigher
ProcessingLowerHigher
ExampleSecurity photoLive camera
/capture✅❌
/stream❌✅

24. ESP32-CAM Project Ideas

You can build:

🏠 1. Smart Home Camera

PIR → ESP32-CAM → Photo → Phone

🚪 2. Smart Door

RFID ↓ ESP32 ↓ Servo ↓ Door

with camera:

Door ↓ ESP32-CAM ↓ Live monitoring

🚗 3. Camera Robot

Camera ↓ ESP32-CAM ↓ Wi-Fi ↓ Phone ↓ Forward / Backward / Left / Right ↓ Motor Driver ↓ Motors

📸 4. Remote Surveillance

ESP32-CAM ↓ Wi-Fi ↓ Web browser

🧠 Quick Summary

Remember these key points:

ESP32-CAM ↓ ESP32 + Camera + Wi-Fi + microSD

Camera: usually OV2640

Programming: often USB-to-TTL required

Flashing:

GPIO0 → GND

then after upload:

Remove GPIO0-GND ↓ Reset

Snapshot:

/capture

Live stream:

/stream

PSRAM: important for camera memory and higher-resolution operation.

Main application:

Camera ↓ ESP32-CAM ↓ Wi-Fi ↓ Browser / Cloud

Keep learning. Keep building. Keep growing.

© 2026 Ugenz Academy