ESP32-CAM AI-Thinker Pinout Guide: GPIOs Usage Explained

The ESP32-CAM is a development board with an ESP32-S chip, an OV2640 camera, microSD card slot and several GPIOs to connect peripherals. In this guide, we’ll take a look at the ESP32-CAM GPIOs and how to use them.

Pinout Diagram

The following image shows the pinout diagram for the ESP32-CAM AI-Thinker.

ESP32-CAM AI Thinker module board Pinout diagram GPIOs name

Schematic Diagram

The following figure shows the schematic diagram for the ESP32-CAM.

Image Source

You can download a PDF file with better resolution on this GitHub repository.

Power Pins

The ESP32-CAM comes with three GND pins (colored in black color) and two power pins (colored with red color): 3.3V and 5V.

You can power the ESP32-CAM through the 3.3V or 5V pins. However, many people reported errors when powering the ESP32-CAM with 3.3V, so we always advise to power the ESP32-CAM through the 5V pin.

Power output pin

There’s also the pin labeled on the silkscreen as VCC (colored with a yellow rectangle). You should not use that pin to power the ESP32-CAM. That is an output power pin. It can either output 5V or 3.3V.

In our case, the ESP32-CAM outputs 3.3V whether it is powered with 5V or 3.3V. Next to the VCC pin, there are two pads. One labeled as 3.3V and other as 5V.

ESP32-CAM Camera AI Think Module VCC Power Pins

If you look closely, you should have a jumper on the 3.3V pads. If you want to have an output of 5V on the VCC pin, you need to unsolder that connection and solder the 5V pads.

Serial Pins

GPIO 1 and GPIO 3 are the serial pins (TX and RX, respectively). Because the ESP32-CAM doesn’t have a built-in programmer, you need to use these pins to communicate with the board and upload code.

The best way to upload code to the ESP32-CAM is using an FTDI programmer.

Learn how to upload code to the ESP32-CAM AI-Thinker.

You can use GPIO 1 and GPIO 3 to connect other peripherals like outputs or sensors after uploading the code. However, you won’t be able to open the Serial Monitor and see if everything is going well with your setup.

GPIO 0

GPIO 0 determines whether the ESP32 is in flashing mode or not. This GPIO is internally connected to a pull-up 10k Ohm resistor.

When GPIO 0 is connected to GND, the ESP32 goes into flashing mode and you can upload code to the board.

  • GPIO 0 connected to GND » ESP32-CAM in flashing mode

To make the ESP32 run “normally”, you just need to disconnect GPIO 0 from GND.

MicroSD Card Connections

The following pins are used to interface with the microSD card when it is on operation.

MicroSD cardESP32
CLKGPIO 14
CMDGPIO 15
DATA0GPIO 2
DATA1 / flashlightGPIO 4
DATA2GPIO 12
DATA3GPIO 13

If you’re not using the microSD card, you can use these pins as regular inputs/outputs. You can take a look at the ESP32 pinout guide to see the features of these pins.

All these GPIOs are RTC and support ADC: GPIOs 2, 4, 12, 13, 14, and 15.

Flashlight (GPIO 4)

The ESP32-CAM has a very bright built-in LED that can work as a flash when taking
photos. That LED is internally connected to GPIO 4.

That GPIO is also connected to the microSD card slot, so you may have troubles when trying to use both at the same time – the flashlight will light up when using the microSD card.

Note: one of our readers shared that if you initialize the microSD card as follows, you won’t have this problem because the microSD card won’t use that data line.*

SD_MMC.begin("/sdcard", true)

* we found that this works and that the LED will not make that flash effect. However, the LED remains on with low brightness – we’re not sure if we are missing something.

GPIO 33 – Built-in Red LED

Next to the RST button, there’s an on-board red LED. That LED is internally connected to GPIO 33. You can use this LED to indicate that something is happening. For example, if the Wi-Fi is connected, the LED is red or vice-versa.

That LED works with inverted logic, so you send a LOW signal to turn it on and a HIGH signal to turn it off.

You can experiment uploading the following snippet and see if you get that LED glowing.

void setup() {
  pinMode(33, OUTPUT);
}

void loop() {
  digitalWrite(33, LOW);
}

Camera Connections

The connections between the camera and the ESP32-CAM AI-Thinker are shown in the following table.

OV2640 CAMERAESP32Variable name in code
D0GPIO 5Y2_GPIO_NUM
D1GPIO 18Y3_GPIO_NUM
D2GPIO 19Y4_GPIO_NUM
D3GPIO 21Y5_GPIO_NUM
D4GPIO 36Y6_GPIO_NUM
D5GPIO 39Y7_GPIO_NUM
D6GPIO 34Y8_GPIO_NUM
D7GPIO 35Y9_GPIO_NUM
XCLKGPIO 0XCLK_GPIO_NUM
PCLKGPIO 22PCLK_GPIO_NUM
VSYNCGPIO 25VSYNC_GPIO_NUM
HREFGPIO 23HREF_GPIO_NUM
SDAGPIO 26SIOD_GPIO_NUM
SCLGPIO 27SIOC_GPIO_NUM
POWER PINGPIO 32PWDN_GPIO_NUM

So, the pin definition for the ESP32-CAM AI-Thinker on the Arduino IDE should be as follows:

#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

Learn how to program and build 17 projects with the ESP32-CAM using Arduino IDE DOWNLOAD »

Learn how to program and build 17 projects with the ESP32-CAM using Arduino IDE DOWNLOAD »

Wrapping Up

We hope you’ve found this guide for the ESP32-CAM GPIOs useful. If you have any tips or more info about the ESP32-CAM GPIOs, write a comment below.

We have several projects with the ESP32-CAM that you may like:

Thanks for reading.



Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »


Enjoyed this project? Stay updated by subscribing our weekly newsletter!

30 thoughts on “ESP32-CAM AI-Thinker Pinout Guide: GPIOs Usage Explained”

  1. im really happy that you have started including more and more esp32-cam stuff.. its documentation is really difficult to understand, and you must spend many hours for the simplest things..

    Reply
  2. 1. Other useful pin would be number 33: it’s internally attached to a little red led placed at the backside of the module. Define it as output [pinMode(33, OUTPUT)] and set it to low to light it up [digitalWrite(33, LOW)]. While it’s not an externally accesible pin, it is very useful to indicate, for instance, that wifi connection is alive, or that ESP is trying to establish it, etc.

    2. In order to free pin12 and pin13 (provided you wouldn’t need them for a very demanding SD card usage) you can modify ESP32-CAM fuses like this:
    (from Terminal window) $ espefuse.py –baud 115200 –port **your_USB_port_name** set_flash_voltage 3.3V
    and then include in your Arduino code:
    SD_MMC.begin(“/sd”, true);
    When you set the second initializer attribute to ‘true’ you’re saying that SD card will run in ‘1-line’ mode. This apparently suggests that SD card would continue to be accessible in a slower or less versatile mode, but I have not tested it.
    Anyway, after that code line, you can use pins 12 and 13 like any other I/O pin. I’ve done it, and it works.

    Reply
    • Hi Norberto.
      Thank you so much for sharing that.
      I’ll add that information to this article.
      Thanks again.
      Regards,
      Sara

      Reply
  3. I cannot figure out how to use RTC pins to wake from deep sleep by applying logic level voltage . I’ve tried all of them and I’ve tried changing the gpio level from low to high without success. Using a simple switch to take an rtc pin to ground will work but if I try that with a PIR or transistor arrangement I get a cycle of wakeup take, photo and sleep about every 10 seconds. The g
    RTC gpio pins seem to float high at logic level (3.3v). I feel like I should be able to pull the pins down in software but cannot figure out how without affecting the SD card or camera.
    I’m using an AI thinker model (or clone) just like in this article. Following your many guides trying to save an image to SD and send it over wifi to email, triggered by a basic Pir. I can get everything to work individually and combine sleep, capture, SD and email fine but can’t get the wake by rtc with logic level to work.

    Any help is greatly appreciated. I’m new to arduino and microcontrollers and I find your blog to be extremely helpful so thank you both for all the time and effort you put in.

    Best!

    Reply
    • Hi Dennis.
      If you’re using the microSD card, the only pin that lefts is GPIO 16 and that GPIO is not an RTC pin, which means it can’t be used to wake up the ESP32.
      Do you really need to save your photos to the microSD card?
      If you don’t use the microSD card, you can use the other pins. For example, GPIO 13.

      We have a project that takes a picture when motion is detected and sends it via email. The photo is temporarily saved in SPIFFS. Then, the ESP32-CAM goes to sleep. It is awakened by the PIR motion sensor that is attached to GPIO 13.(the project is not published, it is part of our new eBook: https://randomnerdtutorials.com/esp32-cam-projects-ebook/

      We also have other project that uses external wake-up with the PIR, that uses deep sleep and sd card: https://randomnerdtutorials.com/esp32-cam-pir-motion-detector-photo-capture/
      I hope this helps.
      Regards,
      Sara

      Reply
  4. Sarah,

    Thank you for the helpful reply and again for the wonderful resource y’all provide. You have been an asset to me as a beginner in arduino/esp devices and coding.

    I’ve solved the problem, rookie mistake on my part. I had checked my wiring several times and thought it was solid but after rebuilding it on a breadboard i got it working without issue. Seems i had a bad transistor that was not switching to allow the current to bring GPIO13 to ground. Fixed that and its working great.

    I have no issue using your code for the PIR motion capture to SD and combining it with your code for sending email (also helped by BnBe’s similar post at hackster.io) Combining all together I can use a PIR on GPIO13 (of an AI Thinker clone ESP32-Cam, which looks identical to the one in the photo at the top of this article, bought on amazon from KeeYees). I am using a different PIR from the one you use in your other article. Mine looks identical to the HC_SR501. I have everything wired exactly as your other post using a 2N222 transistor. The ESP32 and PIR are wired to a regulated 5 volts and everything works great. I did find that I got better performance with the PIRs jumper set to L rather than H.

    I have had no issue waking form deep sleep using GPIO 13 and I have tried pin 12 as well with success. I don’t know if those are RTC for sure (I cannot seem to find much documentation on that) but I thought only RTC pins would allow wake up.

    Your code is very fast and works great compared to a few others that I have tried. So great job and thanks!! I love that I can have this setup as a motion capture that saves to SD no matter what but also will email me if its connected to my WiFi. I will be using these as a wildlife trail camera and the first one is working great just testing around my house. I’ve removed the IR filter from the camera lenses and plan to setup a small IR LED array that will come on when the camera wakes and go off at sleep. Obviously that requires more bits but a quick test with a couple LEDS in my home is promising if I can power them efficiently.

    Sorry this is a little more geared toward a few of your other posts but I appreciate the guidance and encouragement. I also apologize for the long post. I’m still curious of a definitive answer regarding the RTC pins on these modules while using the SD also. This article mentions 16 as UART and not RTC while 2,4,12,13,14,15 are RTC. Regardless, i know 12 and 13 will allow wake from deep sleep.

    Last, if I may make a suggestion here for future tutorials… as a beginner with these modules and their coding I would love to see info regarding the timing of when certain parts of code should be in the setup and loop sections. For example, if I were to have a pin on the ESP trigger a light before the camera captures the image, how would I time that to happen? No need to answer here, just a general idea of what I mean by timing. As a newbie I can often figure out what sections of code are doing (thanks largely to your great tutorials) but they don’t always seem to have a logical order compared to when things happen.

    Thanks again and best!

    Reply
    • Hi Dennis.
      I’m gad everything is working now.
      To learn more about RTC GPIOs, you can read our ESP32 Pinout guide that also applies to the ESP32-CAM: https://randomnerdtutorials.com/esp32-pinout-reference-gpios/
      When using the microSD card, you don’t have much options left.
      Thank you for your suggestions. We’ll definitely create more tutorials with the ESP32-CAM.
      Thanks for following our tutorials.
      Regards,
      Sara

      Reply
  5. I have one doubt about the GPIO4 (flash pin).

    In my last experiments using the ESP32_CAM, I tryed to turn the flash off, but no matter the configuration I used in setup(), everytime that the ESP32-CAM took a picture it lit the flash.

    In my setup() function, I tryed using ‘pinMode(4, INPUT)’ and ‘pinMode(4, OUTPUT)’, but the result was the same.

    How I disable the Flash?

    Reply
    • Hi.
      You should initialize your microSD card as follows (if it is used):
      SD_MMC.begin(“/sdcard”, true)

      instead of
      SD_MMC.begin()

      Regards,
      Sara

      Reply
  6. Hello.
    Regarding the flashlight GPIO4, the issue there is that you have a voltage divider that drops voltage over the flash LED’s transistor base. Look at R11, R13 and R12. The voltage divider creates an output voltage of ~0.6V, enough to drive some current through the transistor. If you don’t need the SD card, you can remove the R11 resistor to stop this flow.
    I tried this in order to obtain a low power WiFi camera over battery, that wakes from time to time and takes a photo and then it sends it over email. Until now, I didn’t manage to obtain a sub-milli ampere consumption, I get about 2-4 mA, but I suspect that the boards design is not optimal for low power. I also replaced the AMS1117 with ADP3338AKCZ-3.3RL7 which is better for quiescent current, but with no great success. Any ideas on getting the best low power current consumption with this board?
    Thank you for the tutorials.

    BR,
    Mihai

    Reply
  7. Hello, Thanks for the awesome article. I need to know about the project PIR+ESP32 CAM + email pic and SD card storage. If I just need that ESP32 CAM takes a pic after motion detection. Means not using deep sleep, just doing by an interrupt. I am asking this because I have to subscribe the ESP32 CAM module by MQTT. And as per my knowledge, if ESP32 CAM goes to sleep mode then it is very much hard to subscribe it by MQTT. SO what changes I have to make in the program?

    Thanks

    Reply
    • Hi.
      With the ESP32-CAM, if you don’t use the microSD card, I would suggest that you try the following GPIOs: 2, 14, 15, 13, 12 and 16.
      I haven’t tried that sensor with the ESP32-CAM. So, I’m not sure if it will work well on those pins.
      Regards,
      Sara

      Reply
  8. Hi
    Thank you so much for all the info and tutorials, they really helped me out a lot. I’m still new to all this and thus am having trouble with setting the shutter speed. I need a lower shutter speed than the one used by default but I’m unable to find the settings in any codes. Is it even possible? based on OV2640 datasheet, it seemed possible but I couldn’t find the pins anywhere. Can you help me with this issue if possible?
    Regardless, I’m still thankful for all those instructions 🙂

    Reply
  9. Hi there, I tried using GPIO16 for a button and found it almost always crashed my ESP32-CAM board. After a lot of head scratching I looked at the circuit diagram and it’s shown connected to PSRAM.

    I would not continue to recommend using it as an extra input.

    Reply
    • Hi Nick.
      I don’t think GPIO 16 is connected to PSRAM.
      In the diagram, GPIO 16 is connected to U2RXD. GPIO17 is connected to PSRAM, which is right above the GPIO16.
      I’ve used GPIO 16 with a pushbutton in a project that takes photos when the button is pressed.
      The button worked when I connected it with a 10kOhm pull up resistor.
      This means that when the button is not pressed the GPIO state is HIGH and when you press it, it is LOW.
      I hope this helps.
      Regards,
      Sara

      Reply
      • In the diagram, GPIO16 is a CS# of PSRAM. See the schematic above. If it is used as input, you can easily enter a boot loop.

        It is forced to the output mode and high. I was trying to connect PIR module there, and I badly failed.

        Actually, there are no really free pins. Even worse, GPIO4 is shared between SD slot and LED flash, so if you use SD, LED ocasionally flashes.

        If you are not using serial port, you can repurpose serial pins.

        If you are not using SD slot, you can repurpose SD pins.

        If you are not using camera, you can repurpose camera pins.

        Reply
        • Hi.
          You’re right about the PSRAM. Thanks for your comment.
          However, as I’ve wrote in the previous comment, it worked well to take a photo when pressed a button. But I haven’t tried with an interrupt.
          Regards,
          Sara

          Reply
  10. Your work is amazing, thanks a lot.
    I have a trouble using builtin_led until i changed “pinMode” to “digitalWrite”.

    void loop() {
    digitalWrite(33, LOW);
    delay(1000);
    digitalWrite(33, HIGH);
    delay(1000);
    }

    Reply
  11. Hi Sara,

    You say in the tutorial that you can use the MicroSD card pins for GPIO when you’re not using the card. That is incorrect — if you plan to use the CAMERA in anything OTHER than the lowest resolution, you won’t have enough memory (or you’ll cause a guru panic/core dump). There is a small ESP PSRAM64H (or IPUS6406L) 64Mbit (8mb) SPI CMOS ram chip attached to the SPI bus.

    The arduino camera drivers automatically enable it and basically require it — the board itself only has 320k ram and that’s insufficient with Arduino + webserver + anything to move to higher resolution images.

    I literally spent about two weeks of my life discovering this.

    If you look on the esp32-cam, on the pin header (chip side) adjacent to the LMS1117 3.3v regulator, on the other side of the RST button you’ll see an SOT8 IC which is attached to the SPI bus/pins.

    Reply
    • The microSD card is not the same as PSRam chip. You don’t need an microSD card to use the camera at full resolution. Indeed if you don’t need to use the microSD slot (for example to store image files on a card), you can use two more pins for IO, and the camera will still work at full resolution.

      Reply
  12. Hi Sara,
    I should have read all the comments before spending two days wondering why the call to frame2bmp() crashed my IA thinker module ! I did connect GPIO 16 to a RS485 serial module and I eventually found that this pin was used by frame2bmp(), probably accessing the PSRAM. I could clearly see the I/O on the serial analyzer.
    I now use GPIO 13, GPIO 14 & GPIO 15, and it works much better, even if I can no longer use the SD Card… As started by Stanislas, could you please warn the user about GPIO 16 & PSRAM ?
    Thanks again for this nice set of articles !

    Reply
  13. Further to the freeing up of io pins when using an sd card using 1 bit mode.
    i.e. “SD_MMC.begin(“/sdcard”, true)”

    I have found that to use pins 4, 12 and 13 you need to define them as input or output after you have enabled the sd card, otherwise it removes any previous assignment and stops them working.
    e.g. I am successfully using all 3 pins of these pins as well as an sd card in this sketch: https://github.com/alanesq/ESP32Cam-range

    btw – It may be possible to use extra io pins by soldering direct to the esp32-s module (possibilities 16, 17, 9, 10, 11, 6, 7, 8)

    Reply

Leave a Reply to Brian H. Cancel reply

Download our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.