ESP32-CAM complete guide
ESP32-CAM complete guide. Source: DIY Engineers (YouTube)
The ESP32-CAM in 30 Seconds
  • The ESP32-CAM is AI-Thinker’s 27 x 40.5 mm board: an ESP32 chip, an OV2640 2 MP camera, 4 MB PSRAM, 4 MB flash, a microSD slot and a flash LED.
  • It breaks out 16 pins, but with the camera running very few are truly free. Add the SD card and you are left with GPIO12 and GPIO13, and only if the card runs in 1-bit mode.
  • There is no USB port. You upload with an ESP32-CAM-MB adapter, a USB-serial adapter or an Arduino Uno, and GPIO0 must be pulled to GND at upload time.
  • Power it from 5 V. A 3.3 V supply or a thin USB cable is the number one cause of “Brownout detector was triggered”.
  • In the Arduino IDE the board is AI Thinker ESP32-CAM. In the current CameraWebServer example the camera model is picked in board_config.h, not in the .ino file.
  • Camera init failed with error 0x105 means the camera was not detected: check the ribbon cable first.

A Wi-Fi camera for about the price of a coffee. That is why the ESP32-CAM shows up in baby monitors, doorbells, bird box cams and timelapse rigs.

It also puts up a fight on day one. There is no USB port, most of the pins are taken by the camera and the SD card, and it is picky about power. This guide starts with the pinout, then covers which pins are really free, three ways to upload code, a first camera project, and the errors everyone runs into. 👇🏻


ESP32-CAM Pinout Diagram (AI-Thinker)

ESP32-CAM AI-Thinker pinout diagram, camera side up with the microSD slot at the top: left row 5V, GND, GPIO12, GPIO13, GPIO15, GPIO14, GPIO2, GPIO4; right row 3V3, GPIO16, GPIO0, GND, VCC, U0R GPIO3, U0T GPIO1 and GND, with SD card, strapping, camera and PSRAM functions
ESP32-CAM (AI-Thinker) pinout. Pin data: arduino-esp32 camera_pins.h and the AI-Thinker ESP32-CAM schematic

The diagram shows the camera side with the microSD slot at the top. The antenna and the flash LED sit at the bottom.

PinGPIOFunctionNote
5V-Power inPower the board from here
GND-GroundThere are three
IO12GPIO12SD DATA2Strapping: HIGH at boot and the board will not start
IO13GPIO13SD DATA3Free in 1-bit SD mode
IO15GPIO15SD CMD
IO14GPIO14SD CLK
IO2GPIO2SD DATA0Strapping
IO4GPIO4SD DATA1, flash LEDThe flash blinks in 4-bit SD mode
3V3-3.3 VNot recommended as a supply
IO16GPIO16PSRAMLeave it alone while using the camera
IO0GPIO0Camera XCLK, BOOTTied to GND means upload mode
VCC-Power out3.3 V by default, do not power the board here
U0RGPIO3Serial RXUploading and Serial Monitor
U0TGPIO1Serial TXUploading and Serial Monitor

Two more things live on the back: the RST button and a red LED on GPIO33. That LED is active low, so LOW turns it on. The flash LED on GPIO4 is very bright and gets warm if you leave it on.

To compare it with other ESP32 boards pin by pin, try our ESP32 pinout tool.


Advertisement

ESP32-CAM GPIO Pins: Which Ones Are Free?

This is the real catch with the ESP32-CAM. The camera uses 14 GPIOs internally (5, 18, 19, 21, 22, 23, 25, 26, 27, 32, 34, 35, 36, 39), and none of them reach the headers. Most of the header pins belong to the SD card. How many you get depends on what you are doing:

SetupPins left
Camera + SD card (4-bit)Practically none. Even GPIO4 is shared with the flash
Camera + SD card (1-bit)GPIO12, GPIO13 (plus GPIO4 for the flash)
Camera, no SD cardGPIO2, 4, 12, 13, 14, 15
If you give up Serial MonitorAdd GPIO1 and GPIO3

The ones that need care:

  • GPIO0: the camera’s clock (XCLK) comes out of this pin, so it is busy whenever the camera runs. LOW at boot puts the board in upload mode.
  • GPIO12: selects the flash chip voltage at boot. Anything that pulls it HIGH during boot (an I2C line with pull-ups, for example) stops the board from starting at all. This is the most common mistake when adding a sensor.
  • GPIO16: wired to PSRAM on most boards. The camera relies on PSRAM, so do not touch it.
  • GPIO2 and GPIO15: strapping pins, but rarely a problem in practice.

Then there is I2C. Arduino’s default I2C pins are GPIO21 and GPIO22, and both belong to the camera. Call Wire.begin(), wire up a sensor, and nothing happens. If you are not using the SD card, move I2C to GPIO14 and GPIO15:

#include <Wire.h>

void setup() {
  Wire.begin(14, 15);   // SDA = GPIO14, SCL = GPIO15
}

The ESP32-CAM pins are not 5 V tolerant either. Do not connect a 5 V output straight to them.


ESP32-CAM Specs and Power Requirements

SpecValue
ChipESP32 (ESP32-D0WD), dual core, up to 240 MHz
Memory520 KB SRAM, 4 MB PSRAM, 4 MB flash
CameraOV2640, 2 MP, up to 1600 x 1200 (UXGA)
WirelessWi-Fi 802.11 b/g/n, Bluetooth 4.2 and BLE
AntennaPCB antenna, IPEX connector for an external one
StoragemicroSD slot
LEDsFlash LED (GPIO4), red LED (GPIO33)
USBNone
Power5 V recommended
Deep sleepAbout 6 mA per the vendor datasheet
Size27 x 40.5 x 4.5 mm

How should you power the ESP32-CAM? It accepts power on the 3.3 V and 5 V pins, but most people who use 3.3 V end up with random resets and instability. Current spikes hard when the camera and Wi-Fi run together. Feed the 5V pin from a supply that can deliver at least 1 A. The pin labelled VCC is an output, not an input.

6 mA in deep sleep is high for an ESP32, because the regulator and camera circuitry keep drawing current. For a project that should run on batteries for months, this is the wrong board.


How to Upload Code to the ESP32-CAM (MB, FTDI, Arduino Uno)

With no USB port and no USB-serial chip on board, you upload through an external adapter. There are three ways:

Three ways to upload code to the ESP32-CAM: plugged into an ESP32-CAM-MB with micro USB; a CP2102 USB-serial adapter wired 5V, GND, TX to U0R and RX to U0T crossed over; an Arduino Uno with RESET tied to GND and D0 to U0R, D1 to U0T wired straight; the adapter methods need GPIO0 jumpered to GND
ESP32-CAM upload wiring

1. ESP32-CAM-MB (the easy way)

A small USB board the ESP32-CAM plugs into. It carries a CH340 USB-serial chip, a micro USB port and IO0 and RST buttons. Seat the board, plug in USB, no wiring. Most of the time you just hit Upload in the Arduino IDE.

If it stalls: hold the IO0 button on the MB, press and release RST on the ESP32-CAM, then let go of IO0. If no port shows up at all, the CH340 driver is missing; Windows 11 usually installs it, otherwise get it from the chip maker, WCH.

Programming the ESP32-CAM with the ESP32-CAM-MB
Programming with the ESP32-CAM-MB. Source: Yellow Purple (YouTube)

2. USB-serial adapter (FTDI, CP2102)

Connect the adapter’s 5V to the board’s 5V and GND to GND. The data lines cross over: adapter TX to the board’s U0R, adapter RX to U0T. Finally, jumper GPIO0 to GND.

The adapter’s logic level should be 3.3 V. FTDI boards select it with a jumper; most CP2102 modules already run 3.3 V logic and offer a separate 5 V pin.

3. Uploading with an Arduino Uno

If an Uno is all you have, it can act as a USB-serial bridge. Tie the Uno’s RESET pin to GND, which takes its own processor out of the way. Then wire D0 (RX) to the board’s U0R and D1 (TX) to U0T. This time the wiring is straight, not crossed, because the Uno’s labels are written from its own processor’s point of view. 5V, GND and the GPIO0 to GND jumper stay the same.

The Uno’s data lines run at 5 V logic, while the ESP32 is officially not 5 V tolerant. Fine for an occasional upload; the long-term fix is an ESP32-CAM-MB.

With either adapter method, when the upload finishes, remove the GPIO0 jumper and press RST. Leave the jumper in and the board boots into upload mode every time, and your code never runs.


ESP32-CAM Arduino IDE Setup and Web Server Example

In short: install the esp32 package in the Arduino IDE, select AI Thinker ESP32-CAM as the board, open the CameraWebServer example, enable CAMERA_MODEL_AI_THINKER in board_config.h, enter your Wi-Fi credentials, upload, and open the IP address from the Serial Monitor in a browser. Step by step:

In the Arduino IDE, add Espressif’s package under File > Preferences > Additional boards manager URLs, then install “esp32” from the Boards Manager:

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

Pick Tools > Board > esp32 > AI Thinker ESP32-CAM. This definition has PSRAM enabled and the Huge APP partition scheme set, so there is nothing else to configure.

Now the first project, the web server example that live streams video to your browser:

  1. Open File > Examples > ESP32 > Camera > CameraWebServer.
  2. Switch to the board_config.h tab. Comment out #define CAMERA_MODEL_ESP_EYE with // and remove the // in front of //#define CAMERA_MODEL_AI_THINKER.
  3. In the main tab, enter your Wi-Fi credentials:
const char *ssid = "YourNetwork";
const char *password = "YourPassword";
  1. Upload, remove the GPIO0 jumper if you used one, and press RST.
  2. Open the Serial Monitor at 115200 baud. You should see something like:
WiFi connected
Camera Ready! Use 'http://192.168.1.42' to connect
  1. Open that address in a browser on the same network and click Start Stream.

The page lets you change resolution, brightness, mirroring and the flash. To pull the video into something else (Home Assistant, VLC, your own page), the stream lives at http://IP:81/stream and a single still at http://IP/capture.

Two things differ from older tutorials. In the 2.x releases of Arduino-ESP32 you picked the camera model right in the .ino file; in the current 3.x releases that choice moved to board_config.h. The same transition removed face detection and face recognition from the example. Most “ESP32-CAM facial recognition” videos on YouTube use the 2.0.x package, so to get that page back you need to install version 2.0.17 from the Boards Manager.

If the stream stutters, drop the resolution to VGA (640 x 480) or below. The ESP32-CAM’s Wi-Fi cannot keep up with smooth video at high resolutions.


ESP32-CAM: Save Images to the SD Card

Plenty of projects do not need a live stream at all. They need this: take a photo every so often, write it to the card, sleep. The code below saves a photo every minute and deep sleeps in between, which makes it a simple timelapse camera:

#include "esp_camera.h"
#include "FS.h"
#include "SD_MMC.h"
#include "driver/rtc_io.h"

RTC_DATA_ATTR int counter = 0;   // survives deep sleep

void goToSleep() {
  pinMode(4, OUTPUT);
  digitalWrite(4, LOW);          // keep the flash LED off
  rtc_gpio_hold_en(GPIO_NUM_4);
  esp_sleep_enable_timer_wakeup(60ULL * 1000000);   // 60 seconds
  esp_deep_sleep_start();
}

void setup() {
  Serial.begin(115200);

  camera_config_t c = {};
  c.pin_pwdn = 32;  c.pin_reset = -1;  c.pin_xclk = 0;
  c.pin_sccb_sda = 26;  c.pin_sccb_scl = 27;
  c.pin_d7 = 35;  c.pin_d6 = 34;  c.pin_d5 = 39;  c.pin_d4 = 36;
  c.pin_d3 = 21;  c.pin_d2 = 19;  c.pin_d1 = 18;  c.pin_d0 = 5;
  c.pin_vsync = 25;  c.pin_href = 23;  c.pin_pclk = 22;
  c.xclk_freq_hz = 20000000;
  c.ledc_timer = LEDC_TIMER_0;
  c.ledc_channel = LEDC_CHANNEL_0;
  c.pixel_format = PIXFORMAT_JPEG;
  c.frame_size = FRAMESIZE_UXGA;   // 1600x1200
  c.jpeg_quality = 10;
  c.fb_count = 1;
  c.fb_location = CAMERA_FB_IN_PSRAM;
  c.grab_mode = CAMERA_GRAB_LATEST;

  if (esp_camera_init(&c) != ESP_OK) { Serial.println("Camera init failed"); goToSleep(); }

  // the first frames are dark while auto exposure settles
  for (int i = 0; i < 3; i++) {
    camera_fb_t *skip = esp_camera_fb_get();
    if (skip) esp_camera_fb_return(skip);
  }

  if (!SD_MMC.begin("/sdcard", true)) { Serial.println("No SD card"); goToSleep(); }   // true = 1-bit mode

  camera_fb_t *fb = esp_camera_fb_get();
  if (fb) {
    char path[24];
    snprintf(path, sizeof(path), "/photo%05d.jpg", counter++);
    File f = SD_MMC.open(path, FILE_WRITE);
    if (f) {
      f.write(fb->buf, fb->len);
      f.close();
      Serial.printf("Saved %s (%u bytes)\n", path, fb->len);
    }
    esp_camera_fb_return(fb);
  }
  goToSleep();
}

void loop() {}

Two details matter here. The true in SD_MMC.begin("/sdcard", true) starts the card in 1-bit mode. In that mode the SD card leaves GPIO4 alone, so the flash LED stops blinking on every write, and GPIO12 and GPIO13 become free. Second, the file counter survives deep sleep thanks to RTC_DATA_ATTR, but resets when power is lost, so after a power cut the board overwrites older photos. For long runs, read the counter from a file on the card instead.

The microSD card must be FAT32. Cards larger than 32 GB usually ship as exFAT, so reformat them first.


ESP32-CAM Not Working? Common Errors and Fixes

“Failed to connect to ESP32: Timed out waiting for packet header”

The board is not in upload mode. With an adapter, make sure GPIO0 is tied to GND and press RST right before uploading. On the ESP32-CAM-MB, hold IO0 and press RST. Swapped TX and RX give the same error.

“Brownout detector was triggered”

The board is not getting enough current and resets itself. The cause is almost always power: a thin, long USB cable, a weak USB port, or a 3.3 V supply. A short, thick cable, 5 V and at least 1 A fixes it. The “disable the brownout detector” snippet that circulates online hides the symptom without fixing the cause.

“Camera init failed with error 0x105” or “0x20001”

Both mean the same thing: the camera was not detected. Check in this order:

  1. Ribbon cable. Lift the black latch on the connector, push the cable all the way in and close the latch. It often comes loose in shipping.
  2. Camera model. Is CAMERA_MODEL_AI_THINKER the one selected in board_config.h?
  3. Power. A weak supply can stop the camera from initializing.

PSRAM errors

“psram id read error” or half-loaded images mean PSRAM is disabled. If you picked ESP32 Dev Module as the board, set Tools > PSRAM: Enabled, or just select AI Thinker ESP32-CAM. Some very cheap clones ship without a PSRAM chip at all.

Weak or dropping Wi-Fi

The PCB antenna is weak. The board has an IPEX connector for an external antenna, but it is not active by default: a tiny 0 ohm resistor next to it routes the signal to the PCB antenna. Move that resistor to the IPEX pad, attach an external antenna, and range improves noticeably. If you would rather not solder, move the board closer to the router or lower the resolution.

SymptomCause and fix
Timed out waiting for packet headerGPIO0 not tied to GND, or TX/RX swapped
Brownout detector was triggered (keeps rebooting)Weak power. 5 V, short cable, 1 A
Camera init failed 0x105 / 0x20001Loose ribbon cable or wrong camera model
Upload succeeded but nothing runsRemove the GPIO0 jumper, press RST
Board will not boot at allSomething pulls GPIO12 HIGH at boot
Sensor does not respondDefault I2C (21/22) is the camera’s, move to 14/15
Flash blinks when using SD1-bit mode with SD_MMC.begin("/sdcard", true)
No port shows up (MB)CH340 driver, or a charge-only cable

ESP32-CAM vs ESP32-S3 CAM: Which to Buy?

BoardWhen to use it
ESP32-CAMThe cheapest Wi-Fi camera. Live streaming, timelapse, motion-triggered photos
ESP32-S3 (N16R8 CAM boards)Native USB, 8 MB PSRAM, more free pins, and room for on-device vision experiments

If you run out of pins or want to process images on the board, step up to an S3. If you only need to push video onto the network, the ESP32-CAM is still the cheapest option.


Frequently Asked Questions

What is the ESP32-CAM? An AI-Thinker development board with an ESP32 chip, an OV2640 camera, 4 MB PSRAM and a microSD slot. It can stream live video over Wi-Fi and save photos to the card. It has no USB port.

What voltage does the ESP32-CAM need? 5 V on the 5V pin is recommended. It also runs from the 3V3 pin, but with the camera and Wi-Fi active that often leads to instability and brownout resets. Use a supply that can deliver at least 1 A.

How do you upload code to the ESP32-CAM? Since there is no USB, you use an ESP32-CAM-MB adapter, a USB-serial adapter (FTDI, CP2102), or an Arduino Uno with its RESET pin tied to GND. GPIO0 must be pulled to GND at upload time, and afterwards you remove the jumper and press RST.

What is the ESP32-CAM-MB? A programming board the ESP32-CAM plugs into, with a CH340 USB-serial chip and a micro USB port. It handles uploading and Serial Monitor without any wiring, and powers the board from 5 V.

Which board should I select in the Arduino IDE? AI Thinker ESP32-CAM under Tools > Board. It comes with PSRAM enabled and the Huge APP partition scheme.

Why does the ESP32-CAM show “Camera init failed with error 0x105”? The camera was not detected. The usual cause is a loose ribbon cable, followed by the wrong camera model in board_config.h and a weak power supply.

Does the ESP32-CAM support facial recognition? Face detection and recognition were removed from the CameraWebServer example in the current 3.x releases of Arduino-ESP32. To use them, install one of the 2.0.x versions from the Boards Manager.