Skip to content
My Account

Reference

ESP32-CAM (AI-Thinker) Pinout

The AI-Thinker ESP32-CAM pin reference: the full camera pin map, SD card pins, flashing with a USB-to-serial adapter, power, code and the traps.

  • ESP32 + OV2640
  • 4 MB flash
  • 4 MB PSRAM
  • microSD slot
No ratings yet, be the first.

The AI-Thinker ESP32-CAM is the cheapest way to put a camera on an ESP32: an ESP32 module, a 2 megapixel OV2640 camera, a microSD slot and a bright flash LED on a board of about 40 × 27 mm. It is also one of the most often miswired boards, because most of its GPIOs are already used by the camera or the SD card, and because it has no USB port: you flash it with an external USB-to-serial adapter.

This guide covers every pin with its job, the full camera pin map, the SD card pins, how to wire the adapter and enter flash mode, power, code, and the traps. The chip limits come from the Espressif ESP32 datasheet. The camera pin map is the one used in the Espressif camera driver for the AI-Thinker board and is confirmed by the common community references, not by an AI-Thinker datasheet.

System-on-chip and board

ItemValue
ModuleESP32-S module with a dual-core Xtensa LX6 ESP32, Wi-Fi 4 and Bluetooth 4.2 (BR/EDR and LE)
Memory4 MB flash, 4 MB PSRAM
CameraOV2640, 2 megapixel (1600 × 1200)
microSDSlot, 1-bit or 4-bit mode
LEDsBright white flash LED on GPIO4, small red LED on GPIO33
AntennaOn-board PCB antenna, with a spot for an external one (a resistor must be moved)
USBNone, you need a USB-to-serial adapter
Supply5 V on the 5V pin, or 3.3 V
SizeAbout 40 × 27 mm

Source: the Espressif ESP32 datasheet for the chip, and common documentation of the AI-Thinker board for the rest.

Getting started

1. What you needThe ESP32-CAM, a USB-to-serial adapter (FTDI or CP2102, 3.3 V logic), a good 5 V supply of at least 500 mA, and jumper wires.
2. Wire the adapterAdapter TX to GPIO3 (U0R), adapter RX to GPIO1 (U0T), GND to GND, 5 V to the 5V pin. Connect GPIO0 to GND to enter flash mode.
3. Upload and runChoose AI Thinker ESP32-CAM in the Arduino IDE, upload the CameraWebServer example, remove the GPIO0 to GND wire, and reset the board.

Specifications

Board

Supply5 V on the 5V pin (recommended) or 3.3 V
CurrentSpikes of several hundred mA with Wi-Fi and the flash LED, so use a supply that gives at least 500 mA
Free GPIOs2 to 6, depending on whether you use the SD card and the flash LED
Flash and PSRAM4 MB each
Camera supplyOn the board, with a power-down pin on GPIO32

Chip limits (ESP32 datasheet)

Supply3.0 to 3.6 V on the chip pins, absolute maximum 3.6 V
Cumulative output current1200 mA
Storage temperature−40 to 150 °C
Strapping pinsGPIO0, GPIO2, GPIO5, GPIO12 (MTDI) and GPIO15 (MTDO)

Source: the Espressif ESP32 datasheet (v5.3) for the chip limits. Board values are from common documentation.

Dimensions

The board is about 40 × 27 mm, and with the camera module about 12 mm high. AI-Thinker does not publish a drawing in the text I could check, so measure your board before you design a case. The camera is on a flexible connector on one side of the board and the microSD slot is on the back. Leave a free view for the lens and for the antenna.

Source: typical size of the AI-Thinker board, not from a datasheet read for this guide.

Pin reference

Camera pins (not free)

Camera signalGPIO
XCLKGPIO0
PWDNGPIO32
RESETnot connected (−1)
SIOD (camera I2C data)GPIO26
SIOC (camera I2C clock)GPIO27
Y2 to Y9 (data)GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35
VSYNCGPIO25
HREFGPIO23
PCLKGPIO22

All other pins

GPIOFunctionNotes
GPIO0XCLK, boot strappingConnect to GND to flash. Pulled up
GPIO1, GPIO3UART TX and RXTo the USB-to-serial adapter
GPIO2, GPIO12, GPIO13, GPIO14, GPIO15SD card (1-bit uses GPIO2, GPIO14, GPIO15)Free for other use only if the SD card is not used or runs in 1-bit mode
GPIO4Flash LED, SD DATA1Bright LED. Shared with the SD card in 4-bit mode
GPIO16PSRAM chip selectDo not use. A common cause of crashes
GPIO33Red LEDActive low

With the camera enabled and the SD card off or in 1-bit mode, the realistic free pins are GPIO2, GPIO12, GPIO13, GPIO14, GPIO15, and GPIO4 if you give up the flash LED. GPIO12 and GPIO15 are strapping pins, so they must not be pulled the wrong way at boot.

Source: Espressif camera driver pin map for the AI-Thinker board and community references. The strapping pins are from the ESP32 datasheet.

Advertisement

Power

  • Use a real 5 V supply. The 5V pin has a regulator on the board. The board behaves badly on a weak or noisy supply, and a USB-to-serial adapter often cannot deliver the current.
  • 3.3 V works but not always. The 3.3 V pin feeds the chip directly. A supply that sags causes brownout resets.
  • The flash LED is hungry. The white LED on GPIO4 takes a lot of current. Keep it off when you do not need it, and use PWM to dim it.
  • A bulk capacitor helps. A 100 µF to 470 µF capacitor across 5 V and GND at the board reduces resets.
  • Brownout. The message “Brownout detector was triggered” means the supply sagged.

Flashing and settings

ItemSetting
WiringAdapter TX to GPIO3, RX to GPIO1, GND to GND, 5 V to 5V
Flash modeGPIO0 to GND before power or reset, then remove it and reset to run
BoardAI Thinker ESP32-CAM
Partition schemeHuge APP (3MB No OTA) for the camera example
PSRAMEnabled
Upload speedIf it fails, lower it to 115200

Example code

This is the camera configuration for the AI-Thinker board with the esp32-camera driver:

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

The easiest start is the CameraWebServer example, with CAMERA_MODEL_AI_THINKER selected. I did not run this sketch on a board.

Tips

  • Use JPEG in PSRAM, and a frame size of SVGA or smaller for streaming.
  • Use two frame buffers with CAMERA_GRAB_LATEST for a live stream.
  • Turn the flash LED off with PWM or a transistor when it is not needed.
  • Add a heat sink or air: the board gets hot while streaming.
  • Put the SD card in 1-bit mode to free GPIO4, GPIO12 and GPIO13.
  • Use a separate USB-to-serial adapter that gives 3.3 V logic.
  • Flip the picture with set_vflip and set_hmirror if it is upside down.

Real gotchas

  • There is no USB. You need a USB-to-serial adapter, and you must connect GPIO0 to GND to flash.
  • GPIO0 must be free to run. If GPIO0 stays at GND, the board starts in flash mode and your program does not run.
  • Do not use GPIO16. It is the PSRAM chip select.
  • The SD card kills pins. In 4-bit mode it uses GPIO2, GPIO4, GPIO12, GPIO13, GPIO14 and GPIO15. Use 1-bit mode to free some.
  • GPIO12 is a strapping pin. The datasheet strapping table puts MTDI at pull-down. A wrong level on GPIO12 at boot can stop the chip from booting. Do not pull it high with external parts.
  • The red LED is active low. GPIO33 LOW turns it on.
  • Power is the number one problem. Random reboots, a failed camera init and brownout messages are almost always the supply.
  • Boards differ. Clones can have another camera module or another pin map, so compare with yours.
  • Pins are not 5 V tolerant. The ESP32 GPIOs are 3.3 V only.
  • Not all pins are inputs. GPIO34 to GPIO39 are input only, which is why the camera uses them as data lines.
Advertisement

Compared with other camera boards

BoardChipMemoryUSBCameraNotes
ESP32-CAMESP32, dual core4 MB flash, 4 MB PSRAMNoOV2640Cheapest, adapter needed
XIAO ESP32S3 SenseESP32-S3, dual core8 MB flash, 8 MB PSRAMYesOV5640 or OV3660Small, USB, battery
Waveshare ESP32-S3-CAM-OVxxxxESP32-S3R816 MB flash, 8 MB PSRAMYesSeveralMicrophones, speaker, display connector

The numbers for the other boards come from their own guides and are not checked again here.

What to build with it

  • A cheap Wi-Fi camera or doorbell camera.
  • A time-lapse camera that saves to the SD card.
  • A face detection or QR code scanner project.
  • A HomeKit camera, see ESP32 HomeKit development.
  • A pet or bird feeder camera with a motion sensor, such as a PIR sensor.

Safety notes

Before you wire anything up

  • Keep every GPIO at 3.3 V. The chip supply limit is 3.6 V and the pins are not 5 V tolerant.
  • Use a regulated 5 V supply that can give enough current. Do not feed the 5V pin from a source above 5.5 V.
  • A camera records people. Respect privacy laws, and tell people when a camera is on.
  • The board gets warm. Do not enclose it without air.
  • Never connect the board to mains voltage. Keep it on a low-voltage supply.
  • Disconnect the power before you change the wiring.

Conclusion

The ESP32-CAM is genuinely the cheapest way to add a camera to an ESP32 project, but budget your wiring around 2–6 free GPIOs, not the ESP32’s full pin count, and remember the external FTDI adapter, it isn’t optional. For a camera-equipped ESP32-S3 board with a display instead, see the T-Display-S3 (display, not camera) or Seeed’s XIAO ESP32S3 Sense (camera connector, no display).

The chip limits are from the Espressif ESP32 datasheet. The camera pin map is the one in the Espressif camera driver and the community references.

Advertisement
All guides

More guides

Keep building.

From ESP32 HomeKit accessories to Arduino and ATtiny reference guides, there’s more where this came from.

All guides