Skip to content

Guide

ESP32-CAM Pinout: Every GPIO, Free Pins, SD Card & Flash LED Explained

Which ESP32-CAM pins are actually free, which belong to the camera, PSRAM and SD card, and which can stop the board booting. Covers GPIO 16, GPIO 4 and the SD card fix.

  • 10 min read
  • Updated November 21, 2026
ESP32-CAM Pinout: Every GPIO, Free Pins, SD Card & Flash LED Explained

The AI-Thinker ESP32-CAM has a pin problem, not a chip problem. Its header carries 16 pins, but only 10 of them are GPIOs, and the camera, the PSRAM chip, the microSD slot and the flash LED each claim some of those. Once you subtract them, a project is usually left with one or two genuinely clean pins.

This guide goes through the board the way you wire it: the physical header order, power, then each pin type (GPIO, UART, I2C, SPI, ADC), the pins the camera and PSRAM keep for themselves, and the boot pins that can stop the board starting. It also covers the two mistakes behind most 'my pin doesn't work' questions: using GPIO 16, which belongs to the PSRAM, and wiring a sensor to a pin the SD card is still using.

Quick answer: use GPIO 13 first; it's free even with an SD card once the card runs in 1-bit mode. GPIO 14, 2, 12 and 15 are usable only without the SD card (and 2, 12, 15 need care at boot). GPIO 4 drives the flash LED. Never use GPIO 0 or GPIO 16: 0 is the camera clock and boot pin, 16 is the PSRAM. Power the board from 5 V with at least 2 A available.

Everything here describes the AI-Thinker board with the OV2640 camera. Other ESP32 camera boards use different pin maps, covered near the end.

ESP32-CAM (AI-Thinker) pinout diagram
5VGNDIO12IO13IO15IO14IO2IO43V3IO16IO0GNDVCCU0RU0TGND

Highlighted on the SolderHub Simulator AI-Thinker ESP32-CAM. Explore every pin on the AI-Thinker ESP32-CAM board page.

All 16 header pins on the SolderHub Simulator ESP32-CAM: almost every GPIO is shared with the SD card, the boot process or Serial, so most show amber, orange or red.
ESP32-CAM (AI-Thinker) pin layout from the SolderHub Simulator: 5V and GND on the left, 3V3 and GPIO0 on the right, camera and microSD in the middle
What's on an AI-Thinker ESP32-CAM: antenna, ESP32-S module, OV2640 camera on its ribbon, flash LED on GPIO 4, microSD slot and the header (no USB port), labelled on the SolderHub Simulator ESP32-CAM

The Short Version

Of the 16 header pins, 3 are ground, 3 carry power (5V, 3V3 and the VCC output) and 10 are GPIOs. Here is what each GPIO is worth once the camera and PSRAM are running:

GPIOVerdictWhy
13Best free pinNo camera role, no boot role. The SD card takes it only in 4-bit mode
14Free if the SD card is unusedSD clock line
2, 12, 15Usable with careBoot-sensitive pins that are also SD lines
4Usable, but it drives the flash LEDAlso SD data line D1
16Do not useChip select for the on-board PSRAM
1, 3Only if you give up SerialUART0 TX and RX
0Do not useBoot mode select and camera clock

That is where the common claim of about six free pins comes from, and it holds only if you skip the SD card and accept a few boot-time rules. With an SD card in use, one pin (GPIO 13) is genuinely clean.

Header Pin Order

The 16 pins sit in two rows of eight. The positions below run from the end of each row where the 5V and 3V3 pins are. Confirm against the silkscreen on your board, because clones sometimes print the labels differently.

Position5V row3V3 row
15V3V3
2GNDGPIO 16
3GPIO 12GPIO 0
4GPIO 13GND
5GPIO 15VCC (output)
6GPIO 14U0R (GPIO 3)
7GPIO 2U0T (GPIO 1)
8GPIO 4GND

Power Pins

PinFunctionNotes
5VPower inputThe recommended way to power the board
3V3Power input or outputWorks as an input, but many boards are unreliable powered this way. Use 5V
GND (x3)GroundThree ground pins, use whichever is closest
VCCPower outputNot an input. A solder jumper beside it selects a 3.3 V output (the usual default) or a 5 V output

Do not feed power into the VCC pin. It is an output, and on most boards it simply mirrors the 3.3 V rail.

Power is the most common hidden cause of pin problems on this board. Ai-Thinker lists a draw of about 180 mA with the flash off and about 310 mA with the flash at full brightness (at 5 V), and the WiFi radio adds short, sharp current bursts on top. Ai-Thinker recommends a 5 V supply of at least 2 A. A weak supply or a long, thin USB cable lets the rail sag, and that shows up as random resets, camera init failures and garbled frames, not as a clean power fault. In order of how often they help:

  • Use a proper 5 V supply with short, thick leads to the 5V and GND pins.
  • Add a 470 to 1000 uF capacitor across 5V and GND, close to the board.
  • For battery builds, use a boost converter from a single-cell LiPo that can deliver at least 1 A in bursts, not a direct connection to the 3V3 pin.
  • For deep-sleep or solar builds, size the supply for the camera and flash start-up spike, not for the average current.

A sagging rail matters most at power-on, which is exactly when the boot pins (covered below) are read.

Power pins: 5V, 3V3/VCC and GND
5VGNDIO12IO13IO15IO14IO2IO43V3IO16IO0GNDVCCU0RU0TGND

Highlighted on the SolderHub Simulator AI-Thinker ESP32-CAM. Explore every pin on the AI-Thinker ESP32-CAM board page.

GPIO Pins (Digital I/O)

This is the status of every GPIO that matters, independent of which subsystem also uses it. Cross-reference the SD card, camera, PSRAM and strapping sections for any pin marked 'shared'.

GPIOStatusShared with
0Not usableCamera XCLK, boot mode select
1, 3Only if you give up the Serial MonitorUART0 TX and RX, programming
2Usable if the SD card is unused, with careSD D0, strapping pin
4Usable if you can live with the flash LEDSD D1, flash LED
12Usable if the SD card is unused, with careSD D2 (4-bit mode only), strapping pin
13Best default choiceSD D3 (4-bit mode only)
14Usable if the SD card is unusedSD CLK
15Usable if the SD card is unused, avoid loading at bootSD CMD, weak strapping role
16Do not usePSRAM chip select
5, 18, 19, 21, 22, 23, 25, 26, 27, 32, 34, 35, 36, 39Not availableInternally wired to the camera

GPIO 13 has no strapping role and no camera role. The SD card claims it only in its default 4-bit mode, so once you switch the card to 1-bit mode (covered below) it stays free even with a card installed. For a button, a PIR sensor or a relay trigger, this is the pin to reach for first.

The six header GPIOs (all shared with the SD card)
5VGNDIO12IO13IO15IO14IO2IO43V3IO16IO0GNDVCCU0RU0TGND

Highlighted on the SolderHub Simulator AI-Thinker ESP32-CAM. Explore every pin on the AI-Thinker ESP32-CAM board page.

Wiring diagram: HC-SR501 PIR sensor on GPIO13 (OUT), 5V (VCC) and GND, exported from the SolderHub Simulator

The SD Card and the Flash LED (GPIO 4)

The microSD slot uses the ESP32's SD/MMC peripheral, and the Arduino SD_MMC library starts it in 4-bit mode by default. That claims six GPIOs at once:

SD lineGPIO4-bit mode1-bit mode
CLK14UsedUsed
CMD15UsedUsed
D02UsedUsed
D14UsedFree
D212UsedFree
D313UsedFree

GPIO 4 is also wired to the bright white flash LED, so in 4-bit mode the LED flickers on every card access. The fix is to start the card in 1-bit mode by passing true as the second argument. This is SD/MMC 1-bit mode, not SPI mode, although forums often call it that. It frees GPIO 4, 12 and 13, costs a little transfer speed that rarely matters for photos and short clips, and stops the flicker.

sketch.ino
#include "SD_MMC.h"

void setup() {
  // true = 1-bit mode: frees GPIO 4, 12 and 13
  SD_MMC.begin("/sdcard", true);

  // Optional: make sure the flash LED stays off
  pinMode(4, OUTPUT);
  digitalWrite(4, LOW);
}
The GPIO4 flash LED sits beside the camera. GPIO4 is shared with SD data line D1

If you use GPIO 4 for something else after this, that device shares the line with the flash LED and the LED will react to it.

Programming and Boot Mode (GPIO 0, U0R, U0T)

The board has no USB port of its own. You program it over UART0, using either a USB-to-serial adapter or a ready-made ESP32-CAM-MB base, which carries a USB serial chip and plugs onto the header.

With an adapter set to 5 V power and 3.3 V logic:

AdapterESP32-CAM
5V5V
GNDGND
TXU0R (GPIO 3)
RXU0T (GPIO 1)
(jumper)GPIO 0 to GND, for upload only

For an upload, connect GPIO 0 to GND, press the reset button on the board and start the upload. When it finishes, remove the jumper and press reset again so the board runs your sketch. With an MB base the boot handling is usually automatic. If the upload hangs at 'Connecting...', hold the base's IO0 button, tap reset, then release IO0 once the upload starts. The full wiring, board settings and a working sketch are in the ESP32-CAM web server tutorial.

GPIO 1 and 3 can be used as ordinary pins after boot, but then the Serial output is gone, which on a board with no display is a real cost.

Programming pins: GPIO 0 (boot), U0R (GPIO 3), U0T (GPIO 1)
5VGNDIO12IO13IO15IO14IO2IO43V3IO16IO0GNDVCCU0RU0TGND

Highlighted on the SolderHub Simulator AI-Thinker ESP32-CAM. Explore every pin on the AI-Thinker ESP32-CAM board page.

ESP32-CAM upload or boot not working?
You try to upload or start the board
Q1 Is the upload stuck at 'Connecting...'?
yes → GPIO 0 must be on GND when the board resets. Jumper IO0 to GND (or hold IO0 on an MB base), tap reset, start the upload.
no
Q2 Did the upload finish but the sketch doesn't run?
yes → Remove the GPIO 0 jumper and press reset again.
no
Q3 No or garbled Serial output?
yes → Cross the lines: adapter TX → U0R (GPIO 3), RX → U0T (GPIO 1), with the adapter at 3.3 V logic.
no
Q4 Does it boot alone but not with your circuit attached?
yes → Something on GPIO 0, 2 or 12 is upsetting the boot read. Move it, to GPIO 13 first.
no
Upload and boot are fine. Check the camera and SD pin sections next.

I2C and SPI Pins

I2C is not fixed to particular pins on the ESP32. Any two free GPIOs can be SDA and SCL through Wire.begin(SDA, SCL). With no SD card, GPIO 13 (SDA) and GPIO 14 (SCL) are the clean pair.

With an SD card in use, the clean choices run out. GPIO 14 is the SD clock, GPIO 12 must stay LOW at boot (an I2C pull-up holds it HIGH), and GPIO 4 puts the pull-up on the flash LED line. In practice you choose between the SD card and an I2C sensor, or you log over WiFi to a server and drop the card. The same limit applies to SPI devices: the ESP32 can route SPI to almost any pins, but this board has too few free pins to run a second SPI bus comfortably.

ADC (Analog) Pins

The analog-capable pins on the header (GPIO 2, 4, 12, 13, 14 and 15) all belong to ADC2, and GPIO 16 has no ADC at all. The ESP32 disables ADC2 whenever WiFi is active, because the radio and ADC2 share internal hardware.

In practice you cannot reliably read an analog sensor on this board while WiFi is connected. This catches people out when a soil moisture sensor or potentiometer reads fine and then goes flat the moment the board joins a network. If a project needs analog input alongside WiFi, use an external ADC such as the ADS1115 over I2C.

Camera Interface Pins

The OV2640 connects through a ribbon cable to GPIOs wired on the PCB. They never reach the header, but they explain why the ESP32 loses so many pins on this board. This is the AI-Thinker mapping used by Espressif's CameraWebServer example:

FunctionGPIOFunctionGPIO
PWDN32Y9 (D7)35
XCLK0Y8 (D6)34
SIOD (SCCB)26Y7 (D5)39
SIOC (SCCB)27Y6 (D4)36
VSYNC25Y5 (D3)21
HREF23Y4 (D2)19
PCLK22Y3 (D1)18
Y2 (D0)5

That is 15 GPIOs consumed before you wire anything. Note that GPIO 0 appears here as XCLK, the same GPIO 0 that selects boot mode. That is why you ground it to flash the board: it is a shared, load-bearing connection, not a spare pin.

PSRAM and GPIO 16

The AI-Thinker board carries an external PSRAM chip, and the camera relies on it for frame buffers, which is what lets it run at higher resolutions without crashing. GPIO 16 is wired to that chip's chip-select line.

GPIO 16 is on the header and labelled as a normal pin, which makes it look like a free GPIO. It is not. Driving it, or loading it with a pull-down, can break PSRAM access, and the symptoms (camera init failures, crashes while capturing a frame) look nothing like a pin conflict. Treat GPIO 16 as reserved. Some libraries also default UART2 RX to GPIO 16, which is another reason to leave it alone.

GPIO 16: taken by PSRAM, never use
5VGNDIO12IO13IO15IO14IO2IO43V3IO16IO0GNDVCCU0RU0TGND

Highlighted on the SolderHub Simulator AI-Thinker ESP32-CAM. Explore every pin on the AI-Thinker ESP32-CAM board page.

Strapping Pins (Boot-Critical)

Strapping pins are GPIOs the ESP32 reads at the instant it powers on to choose its boot mode and flash voltage. If an external circuit holds one in the wrong state at that moment, the board can fail to boot, and because it only happens at start-up it is a confusing bug to chase.

GPIOStrapping rolePractical guidance
0Boot mode select (also camera XCLK)HIGH or floating to boot normally. Grounding it forces flash mode. Never tie it permanently low
2Boot mode select (also SD D0)Leave floating or LOW at boot. Do not pull it HIGH externally at power-on
12Flash voltage select (also SD D2)Must be LOW at boot. HIGH selects the wrong flash voltage and the board will not start. Beware I2C pull-ups here
15Boot log output (also SD CMD)Generally safe, but best left unloaded at power-on

If you use GPIO 2, 12 or 15 for a switch or sensor, make sure the connected circuit cannot pull the line the wrong way during power-up. A pull-up resistor on GPIO 12 is a classic cause of 'works sometimes, won't boot other times'.

Strapping pins on the header: 0, 2, 12 and 15
5VGNDIO12IO13IO15IO14IO2IO43V3IO16IO0GNDVCCU0RU0TGND

Highlighted on the SolderHub Simulator AI-Thinker ESP32-CAM. Explore every pin on the AI-Thinker ESP32-CAM board page.

Onboard LEDs

The white flash LED (GPIO 4) sits next to the lens. It shares its pin with SD data line D1, which is why the flash flickers during card access in 4-bit mode. Anything else you connect to GPIO 4 flickers with it.

The small red status LED (GPIO 33) is active-low: it lights when GPIO 33 is driven LOW. It is wired on the board but GPIO 33 is not broken out to the header on the AI-Thinker design, so it is not a pin you can use for your own wiring without soldering to the board. Treat it as a status light, not an extra GPIO.

Planning Your Pin Budget

Five minutes of planning avoids discovering a conflict halfway through a build:

  1. List every peripheral and how many digital, analog and communication pins each needs.
  2. Decide whether you need the SD card. If you can log over WiFi, dropping it frees GPIO 2, 4, 12, 13, 14 and 15 at once, the single biggest lever on this board.
  3. Assign pins in order of risk: GPIO 13 first, then GPIO 14 (if no SD card), then 2 and 12 (fine once past boot, mind the strapping rules), then 15, then 4 (accepting the flash LED), and only then GPIO 1 and 3 (giving up Serial). Never GPIO 0 or 16.
  4. If the list still does not fit, you have hit a hardware limit. The fix is an I2C GPIO expander (on GPIO 13 and 14, with no SD card), or a different camera board with more free I/O.
Header GPIOs left for your own parts
SD card, 4-bit mode
0 pins

Every free GPIO is an SD line

SD card, 1-bit mode
3 pins

GPIO 4 (flash LED), 12, 13

No SD card
6 pins

GPIO 2, 4, 12, 13, 14, 15

No SD, no Serial
8 pins

Adds GPIO 1 and 3, but you lose Serial output

SD_MMC 4-bit uses GPIO 2, 4, 12, 13, 14, 15; 1-bit mode uses only 2, 14 and 15. GPIO 0 (boot) and 16 (PSRAM) are never free.

Quick Reference: Every Pin, One Table

GPIOCameraSD cardStrappingOther roleFree to use?
0Yes (XCLK)NoYes (boot mode)Flash modeNo
1NoNoNoUART0 TXOnly if not using Serial
2NoYes (D0)YesIf SD unused, with care
3NoNoNoUART0 RXOnly if not using Serial
4NoYes (D1)NoFlash LEDIf you accept the LED
5Yes (Y2)NoNoNo
12NoYes (D2, 4-bit)Yes (flash voltage)If SD unused, with care
13NoYes (D3, 4-bit)NoBest default choice
14NoYes (CLK)NoIf SD unused
15NoYes (CMD)WeakIf SD unused, with care
16NoNoNoPSRAM chip selectNo
18, 19, 21, 22, 23, 25, 26, 27, 32, 34, 35, 36, 39YesNoNoNo, internal camera use

Bookmark this rather than memorize it. Checking takes seconds and saves a long debugging detour.

Common Pin Problems and Their Actual Cause

The camera works until you add a component, then stops initializing. The new component is probably on one of the camera GPIOs, on GPIO 0, or on GPIO 16 (PSRAM). Cross-reference the camera and PSRAM sections.

SD card writes fail once you add a sensor on GPIO 2, 4, 12, 13, 14 or 15. The sensor and the card are fighting over the same line. Move the sensor to GPIO 13 and switch the card to 1-bit mode.

Analog readings are fine until WiFi connects, then go flat or noisy. That is the ADC2 and WiFi conflict, not a wiring fault. Use an external ADC.

The board boots standalone but fails when a circuit is attached. Check whether that circuit touches GPIO 0, 2 or 12. Even a pull-up or pull-down resistor on the wrong pin can corrupt the boot read, especially on a marginal supply.

The flash LED flickers whenever the SD card is used. The card is in 4-bit mode and sharing GPIO 4. Start it with SD_MMC.begin("/sdcard", true).

Putting It Together: A Motion-Triggered Camera

A minimal PIR camera trap that respects every rule above: the PIR on GPIO 13, the SD card in 1-bit mode and nothing near the strapping pins.

sketch.ino
#include "esp_camera.h"
#include "SD_MMC.h"

#define PIR_PIN 13

void setup() {
  Serial.begin(115200);
  pinMode(PIR_PIN, INPUT);

  // Camera init omitted: use the AI-Thinker pin map from the CameraWebServer example

  // Mount the SD card in 1-bit mode, then keep the flash LED off
  if (!SD_MMC.begin("/sdcard", true)) {
    Serial.println("SD mount failed");
    return;
  }
  pinMode(4, OUTPUT);
  digitalWrite(4, LOW);
}

void loop() {
  if (digitalRead(PIR_PIN) == HIGH) {
    camera_fb_t *fb = esp_camera_fb_get();
    if (fb) {
      String path = "/photo_" + String(millis()) + ".jpg";
      File file = SD_MMC.open(path.c_str(), FILE_WRITE);
      if (file) {
        file.write(fb->buf, fb->len);
        file.close();
      }
      esp_camera_fb_return(fb);
    }
    delay(2000);  // simple debounce against repeated triggers
  }
}

Every pin choice here traces back to a rule in the sections above.

How This Compares to Other ESP32 Camera Boards

The pin scarcity in this guide belongs to the AI-Thinker design, not to every ESP32 camera board.

BoardPin situationWhat to check
AI-Thinker ESP32-CAM10 exposed GPIOs, few truly freeCheapest option, no USB without an MB base
Freenove ESP32-WROVER CAMDifferent camera pin mapUses the CAMERA_MODEL_WROVER_KIT definition
M5Stack camera boardsDifferent camera pin mapUse the matching CAMERA_MODEL_M5STACK_* definition
ESP32-S3 camera boardsUsually more usable I/O and native USBEach vendor wires the camera differently, so use that board's own pin map

If a project needs more than two or three free GPIOs alongside a working camera, an ESP32-S3 camera board is worth the extra cost. Do not assume this guide's pin numbers apply to it.

Quick Answers to Common ESP32-CAM Pin Questions

How many GPIOs does the ESP32-CAM have? Ten are exposed on the header (GPIO 0, 1, 2, 3, 4, 12, 13, 14, 15 and 16). Of those, only GPIO 13 is clean once the camera and SD card are in use.

Can I use GPIO 16? No. It is the chip select for the PSRAM the camera depends on. It is on the header, which is why people try it.

Why does my flash LED flash when I use the SD card? The SD card in its default 4-bit mode uses GPIO 4, the same pin as the LED. Initialize it in 1-bit mode with SD_MMC.begin("/sdcard", true).

Which pins can I use for I2C? With no SD card, GPIO 13 and GPIO 14. With an SD card, the options are poor, so consider logging over WiFi instead.

Can I add more GPIOs with an I/O expander? Yes. An I2C expander such as the PCF8574 or MCP23017 needs only two pins and gives you 8 to 16 more, provided you can spare GPIO 13 and 14 by dropping the SD card.

Why does my clone have a different layout? This guide describes the AI-Thinker reference design. Other makers use different camera pin maps, so match your board to its CAMERA_MODEL_ definition before trusting any pin table.

Can I debug with Serial if I use GPIO 1 and 3? Not at the same time. They are the UART0 lines. A common workaround is to use them during development with Serial disabled, then repurpose them in the final build.

Where to Go From Here

Once GPIO 13 is your default answer for 'which pin is free' and the GPIO 4 flash LED stops being a surprise, the next step is a working camera. The ESP32-CAM web server tutorial streams live video from this board. For the standard ESP32 pin rules that the camera board inherits, see the ESP32 pinout guide, and the ESP32 deep sleep guide covers running the camera on a battery.

Projects that use these pins:

Continue learning

Related articles

All articles

Signal In

Built from what makers search for

The lookups piling up in SolderHub's search bar every day shape what we publish next — new component pages, board guides, and firmware notes, sent out as they go live.

By subscribing you agree to our Privacy Policy. Unsubscribe anytime.