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 build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

139 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
    • Hello Norberto, thank you very much for your useful notice.
      Do you think that then Pin 12 and 13 could be used as SDA and SCL to implement a I2C communication?
      I am thinking on using the SD card for recording sensors data, not only pictures.
      Thank you veery much.
      David

      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
          • Short-circuiting the GPIO 16 to the ground would enforce it to be set to low, however driving it with the output of the PIR doesn’t work.

        • That goes pretty well with my observations. I believe Stanislav’s comment should be added directly into the guide.

          Reply
          • I agree — it would be very good to have some ink on GPIO16 in the guide! The guide sent me down the rabbit hole of attempting to use GPIO16 for PIR detection. In another tutorial at RNT, the effect of the PIR was inverted using a transistor so that when the PIR output is high, it drives the pin LOW (to ground). Given Sara’s observation, this might work for GPIO16. Also the other guide should be explicit with regard to why the transistor was used. Other guide: https://randomnerdtutorials.com/esp32-cam-pir-motion-detector-photo-capture/

  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
    • All but one of your “possible pins” are used for other things already (eg. the CAM module, PSRAM, etc). The only pin that is not used anywhere else in the circuit diagram is pin8 (GPIO32) – labelled as “CAM PWR”. They probably planed to allow the ESP32 to turn off the camera to save power using that pin, then changed their mind later (it’s hard-wired to 3.3v).

      Assuming that’s correct – it would allow that pin8 to be reliably used as the I2C clock pin, letting you connect device data pins safely to any other GPIOs.

      (I need to run 4 identical I2C devices all synchronised, so I’m hoping I can wire all their SCL pins to pin8, and each of their SDA pins to 17, 18, 20, and 21 … and use I2C bitbang to trigger them to sample all at once, and read all their data back in parallel too).

      Reply
      • Update – no – pin8 cannot be used either (GPIO32) – trying to use it causes the camera to stop working – looks like this pin is used for camera reset functionality, even though the schematic doesn’t show how/where it is connected to.

        So the only possible pin left over that’s available to use for an I2C clock line is GPIO3 (the Serial RX pin)… as long as you’re not trying to send serial data to your ESP32 during operation, this pin can safely be used for output (without affecting the ability to still view serial output from your sketch)

        Reply
        • The schematic shows (bottom left) that CAM_PWR drives a MOSFET that controls the power from the 3.3V regulator U2 to the two other voltage regulators U1 and U3 that power the camera.

          Depending on your application you might like to explore using SPI instead of I2C as the SD card uses SPI when running in ‘1-bit mode’ so all you need is GPIO12 to drive the CS of your additional device.

          Reply
  14. Hi, can I expand more GPIO for TX and RX ? like Ublox GPS module, in the article that you can use the MicroSD card pins for GPIO when you’re not using the card. can you give example or i must remove the SD Card slot?

    thanks

    Reply
  15. Thanks for this cuide, Sara.
    I’m testing cheaps esp32 cam (chineses) and for now runs ok. I can active flash, webserver, wifi,led… All works.
    But, im triying to use a device with SPI. Does anyone use SPI with this device? I spend soné days with no luck.
    Thanks again.

    Reply
    • Hi.
      I have not tested SPI with the ESP32-CAM.
      If you’re using the microSD card, you won’t have pins left to use SPI.
      Nonetheless, I’m not sure because I haven’t tried it.
      Regards,
      Sara

      Reply
  16. Hey Sara,

    I have used the WiFIManager previously for the ESP8266 which provides the ability to set the SSID and PASS through APConnect. Do you know if there are any libraries out there that provide the same functionality for the ESP32-CAM?

    Reply
  17. Hi Sara,
    how high is the max current which can be drawn from the VCC pin? Can I use the 3,3V pin instead of the VCC pin to output power? Can I draw more power from the 3,3V pin than from the VCC pin? Bests Andre

    Reply
  18. I would like to use 8 Input pins to connect a keypad. Can I use a I2C IO expander like the PCF8574 and still use all the hardware of the ESP CAM board?

    Reply
  19. I have been consistently using GPIO33 to analogRead an LDR voltage divider after removing LED1 and soldering a wire from the GPIO33 pin.

    Reply
  20. Hi,

    did anyone tried using, for example MPU6050, with ESP32 CAM connecting it to SCL and SDA of the camera (GPIO27 and GPIO26)? Does ESP32 communicate with camera only during configuration or also when recording?

    Thanks!

    Reply
    • Hello Gabrijel,

      we have used two FPC connectors, cf: github.com/Barrois/Detecteur-ESP32-Cam-Blob-Detector/tree/main/documentation/FPC_24P_0.5mm_I2C_Derivation
      to make a derivation of sda/scl and it seems to work 🙂

      Reply
  21. Hi I thought I’ve already posted my comment.

    Quick question, can you extend the ports as you can with other dev boards?
    Also, can you add 2 way audio to it?

    Thanks

    Reply
    • Hi.
      Yes, I think you can expand the ports using a GPIO expander.
      I haven’t experimented with audio. But, I think you would need the DAC pins (GPIO25 and GPIO 26) that are not available on the ESP32-CAM.
      Regards,
      Sara

      Reply
  22. Thank you for the reply Sara. Do you know if other pins can be used for DAC?? Alternatively, if a full esp32 board has the dac pins, do you know if a camera can be added? Or would it be best to have a full esp32 dev board and esp32 cam board working together?

    Thanks a lot!

    Reply
    • Hi.
      I don’t think other pins can be used for DAC, but I’m not certain.
      I think you can connect a camera to a “normal” ESP32 board, but I haven’t tried it.
      To make things simpler, it would be better to use a normal board and an ESP32-CAM.
      Regards,
      Sara

      Reply
  23. Hii….
    Which pins are SDA and SCL?
    Where i can find in ESP32 Cam board?
    I need to connect OLED display and MLX90614 temperature sensor.
    According to the data sheet GPIO 26,GPIO 27 are the I2C pins.
    But, where i can find those pins?
    Your help is appreciated!

    Reply
  24. Hi… thanks for all of the great articles!
    Just wanted to let you know someone stealing your content and passing if off as their own.
    Here is the URL: (…)

    Reply
    • Hi.
      Thanks for letting us know.
      We already tried to contact the owner of that website before.
      Unfortunately, there is nothing more that we can do.
      If you find our content in any other place, let us know.
      Thanks
      Regards,
      Sara

      Reply
  25. I’m trying to connect a RWLC-1506 so that the ESP32-CAM (AI Thinker) can take a picture when it detects motion. I’ve connected the RWLC to different pins, including 13 and 16, but the ESP32-CAM always crashes in the esp_camera_init function:

    Guru Meditation Error: Core 1 panic’ed (IllegalInstruction). Exception was unhandled.
    Memory dump at 0x400d1664: ffffffef ffffffff ffffffff
    Core 1 register dump:
    PC : 0x400d1668 PS : 0x00060130 A0 : 0x800d202e A1 : 0x3ffb1f80
    A2 : 0x3ffc09a4 A3 : 0x3ffc0962 A4 : 0x00000020 A5 : 0x80000020
    A6 : 0x00000003 A7 : 0x00060823 A8 : 0x800d1464 A9 : 0x3ffb1f60
    A10 : 0x00000006 A11 : 0x40081158 A12 : 0x00000001 A13 : 0x3ffc0b54
    A14 : 0x3ffb1f1c A15 : 0x3ffb1f1c SAR : 0x0000001a EXCCAUSE: 0x00000000
    EXCVADDR: 0x00000000 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff

    Backtrace: 0x400d1668:0x3ffb1f80 0x400d202b:0x3ffb1fb0 0x4008ce1d:0x3ffb1fd0

    Any suggestions appreciated!
    Thanks

    Reply
    • You can’t 🙂

      I got the same issue and found the explanation here (with the solution) =>
      https://github.com/espressif/esp-who/issues/90

      Basically, you’ll need to play with:
      esp_err_t err = gpio_isr_handler_add(PIN_MOTIONSENSOR, &detectsMovement, (void*)PIN_MOTIONSENSOR);
      if (err != ESP_OK) {
      Serial.printf(“handler add failed with error 0x%x \r\n”, err);
      }
      err = gpio_set_intr_type(PIN_MOTIONSENSOR, GPIO_INTR_POSEDGE);
      if (err != ESP_OK) {
      Serial.printf(“set intr type failed with error 0x%x \r\n”, err);
      }

      Reply
  26. Hi! First thank you for creating such an amazing ESP32-Cam product!

    I’ve a question about how you have tied the 3V3 and 5V lines together in parallel to produce your output voltage on header pin 4 (P_OUT). (See the 2 resisters under Header 8 P1 on your schematic)

    Wouldn’t this connection be pulling the lower 3V3 volts up to 5V? How does the 0R resistors prevent this? I am trying to learn and better understand this? Wouldn’t you want a diode to prevent this back-flow?

    Thank you in advance!

    Reply
    • Hi Randy.
      The ESP32-CAM was not developed by us.
      We’re just trying to compile information so that people can better understand how it works.
      Regards,
      Sara

      Reply
  27. Hi…
    Is there any way to add more pins?
    I tried with PCO8574 but it is not good for the servo.
    I need a more general one.
    Basically I would also like it in esp32-cam with more pins.
    Thanks
    …thanks for all lessons!!!

    @}-,-‘——-
    Gianfranco

    Reply
  28. How do I connect a pca9685 board to Esp32-cam? To be specific, I want to know which pins to use and how to write the code. PCA9685 works on I2C bus.

    Reply
  29. Hii,
    I need to read analog values from esp32 cam, that is analog pH sensor values from it, can u share me a snippet or code.
    Thank you in advance.

    Reply
  30. Hello! I am new in PCB Design

    I want to ask something, why sd card supplied with 3.3 volt on the data pins? Furthermore when you have in the schematic an input from esp32s to sd card for example HS2 data3 to pin 2 of sd card I should connect it after the resistor?

    Reply
  31. Hello,
    About this : * 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.
    I think that things will be ok if you un-solder R11 (47k). This pull-up is unused if SD card is put in SPI mode, but it creates a small current in the base of Q1, which is responsible of the low brightness of FLASH LED.

    Reply
  32. Hi everyone,
    I want to ask everyone is there anybody who uses gpio interrupt and camera_init() at the same time? I get this error when I write attachInterrupt() and camera_init() respectively at the setup():
    [E][camera.c:1327] camera_init(): gpio_install_isr_service failed (105)
    [E][camera.c:1406] esp_camera_init(): Camera init failed with error 0x105

    As I write these vice versa:
    WiFi connected
    Starting web server on port: ’80’
    Starting stream server on port: ’81’
    Camera Ready! Use ‘http://192.168.0.25’ to connect
    Guru Meditation Error: Core 1 panic’ed (LoadProhibited). Exception was unhandled.
    Core 1 register dump:
    PC : 0x401606b3 PS : 0x00060530 A0 : 0x800d2e86 A1 : 0x3ffb1ea0
    A2 : 0x00000000 A3 : 0x00000000 A4 : 0x4008137c A5 : 0x00000000
    A6 : 0x3ffc2e68 A7 : 0x3ffb0060 A8 : 0x8013db9a A9 : 0x3ffb1e50
    A10 : 0x00000105 A11 : 0x0000040e A12 : 0x00000000 A13 : 0x00000000
    A14 : 0x4008137c A15 : 0x00000000 SAR : 0x00000014 EXCCAUSE: 0x0000001c
    EXCVADDR: 0x00000000 LBEG : 0x4008d6fd LEND : 0x4008d70d LCOUNT : 0xffffffff

    ELF file SHA256: 0000000000000000

    Backtrace: 0x401606b3:0x3ffb1ea0 0x400d2e83:0x3ffb1ec0 0x400d2ee1:0x3ffb1ef0 0x400d114d:0x3ffb1f10 0x400d394e:0x3ffb1fb0 0x4008ff8e:0x3ffb1fd0

    Rebooting…

    and then rebooting and rebooting again…

    OR

    who knows stopping camera_init() or usage of camera_deinit()??

    Thanks in advance,

    GS.

    Reply
  33. Hi there,

    Thank you so much for all the amazing tutorials. I’ve learned so much thanks to your hard work.
    As mentioned before on this topic, Pin 16 is indeed connected to #CS of the PSRAM.
    As long as you don’t take a picture this pin can be used for a button pulled to GND.
    After a picture is taken, this pin will more or less random switch from low to high after that.

    I don’t expect anyone to solve this, but it might be interesting for future users.

    Please keep up the great work,
    you really did a spectacular job sofar!

    Kind regards,
    Michiel

    Reply
  34. I want to use it as a flash when taking pictures using pin 4, but I can’t find the relevant source.
    I’m new to Arduino and I’m referencing the sources of many experts.
    please help

    Reply
  35. Hi
    I have a problem when I’m using esp32 cam. I upload the sketch but when I open the browser to see the image, the image is corrupted even when I reduce the quality. how can I fix it. I use a power supply that can produce at least 2 amper.

    Reply
  36. Just to answer my own question – I have the ESP-Prog device, and I can now debug with JTAG, interact across Serial, and upload new FW. So it support debugging via JTAG.

    Reply
  37. I will use this camera in a place where I can’t reach it easy.
    So, I added some watchdogs:
    * Check if WiFi is still active
    * Check if ping is lower than 400ms
    * Check if ping is higher than 0.1ms
    When they fails I restart : ESP.restart();

    But very often the camera was not found after the restart.
    My first idea was to trigger a reset of the camera, but the ping CAM_RST is just connected to an power on reset circuit.
    But the camera had a second internal power on reset check. The external PWDN (power down) will check if the power supply (CSI_2.8V and CSI1.2V) are high enough.
    This pin is also not reachable from GIOP. But this can be triggered when the power supply (CSI_xx) went down.
    The GIOP32 drives Q2 which powers the CSI voltage regulators.
    To switch off the CSI voltage, just set the GOIP32 to High: digitalWrite(32,HIGH);
    After doing this the ESP.restart(); will done.
    Since using this, the camera module always come back.

    Comments are welcome.
    See below the code.

    #include

    float last_time_ms=0;
    float avg_time_ms=0;
    int WifiCount=0;
    bool ret;

    void setup() {
    pinMode(33, OUTPUT); //Rote LED
    pinMode(4, OUTPUT); //Blitzlicht
    pinMode(32, OUTPUT); //Camera Power
    //..

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

    if (WiFi.status()!= WL_CONNECTED){
    Serial.println(“Reboot because of lost WiFi”);
    digitalWrite(32,HIGH);
    ESP.restart();
    }

    ret = Ping.ping(gateway);
    avg_time_ms = Ping.averageTime();
    if ((avg_time_ms+last_time_ms)>400) {
    Serial.println(“Reboot because of high Ping”);
    Serial.println(avg_time_ms);
    digitalWrite(32,HIGH);
    ESP.restart();
    }

    if (avg_time_ms>last_time_ms) {
    last_time_ms = avg_time_ms;
    Serial.println(avg_time_ms);
    }

    if (avg_time_ms <=0.10) {
    Serial.println(“Reboot because of low Ping”);
    digitalWrite(32,HIGH);
    ESP.restart();
    }
    }

    Reply
  38. I have been having issues recently with all 3 of my esp32cams in that after a period of time they freeze. I am in timelapse mode taking a pic every 30 secs then uploading to my host server. Between pics deep sleep mode is enabled. The freezing occurs randomly anywhere between 10 minutes and 12 hours. After a board reboot it will start working again. The SD card is not enabled neither is the flash.

    Reply
  39. Hello Sara,

    I am totally stuck. I have been through all the troubleshooting and I have installed and re-installed Arduino twice. In addition to the esp8266 and ESP32 board definitions. I cannot get my board to accept a sketch upload. I have simplified the code down to the pin33 led blink and nothing. I purchased two cameras with the esp32-cam-mb usb programmer to make it as simple as possible. Or so I thought. The product name is ‘Aideepen ESP32-CAM WiFi Bluetooth Board ESP32-CAM-MB Micro USB to Serial Port CH340G with OV2640 2MP Camera Module Dual Mode’. It looks exactly like the AI Thinker but without the AI Yhinker under the DM ESP32-S.

    Any help or insight is greatly appreciated.

    Thank you very much for your time.

    Reply
      • Thank you so much for the quick response.

        I get the following error:

        c:/users/tplummer/appdata/local/arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/1.22.0-97-gc752ad5-5.2.0/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: cannot find crt1-sim.o: No such file or directory
        c:/users/tplummer/appdata/local/arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/1.22.0-97-gc752ad5-5.2.0/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: cannot find _vectors.o: No such file or directory
        collect2.exe: error: ld returned 1 exit status
        exit status 1
        Error compiling for board AI Thinker ESP32-CAM.

        Reply
        • Hi.
          That’s a weird error.
          Try to uninstall arduino ide and delete all installation related files and then install again.
          Regards,
          Sara

          Reply
        • This is a problem with your Arduino packages. Uninstall Arduino, and also all the libraries you have installed with it

          Delete this folder

          c:/users/tplummer/appdata/local/arduino15

          Then install Arduino IDE again, and add the espressif ESP32 using the board manager. You have the right version of the esp32 installation – its just that your paths are messed up. Did you move the arduino IDE project – or install the package manually before somewhere else ?

          When you do a build for a esp32 example – check the following folder

          c:/users/tplummer/appdata/local/arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/1.22.0-97-gc752ad5-5.2.0/bin

          make sure you have a load of executables in there.

          Reply
  40. If you want to use the SD card but also need its GPIOs you can do so provided you wrap your SD card access in SD_MMC.begin() and SD_MMC.end(). If you don’t include SD_MMC.end() it appears to leave the SD card API in a corrupted state which is not repaired by SD_MMC.begin(). I am using GPIO 15 as an input for an IR receiver (open collector output), which is never going to be active when I’m reading from the SD card.

    Reply
  41. Unfortunately there are no more pins free for I2C. Unless I do without the SD card. The SD card could also be operated with 2 instead of 4 data lines a bit slower.
    On the circuit board there are pins for TWI SDA and TWI SCL but the ends in the camera connector.

    Reply
  42. Hello,
    I’ve discovered that my ESP32Cam version have some differences:

    1) Third “GND” pin (near the Flash LED) is not the ground pin really. The module does not boot up if it is connected to the ground. It has logical “1” level when the module operates normally

    2) The flash LED switch is not S8050 BJT, but LPM2302 (A2sHB) N-MOSFET, what makes it worth to try using HSDATA1 (GPIO4) as ADC2 input either. To control battery, for example.

    Reply
    • I was just about to comment the same thing. I appear to have a ESP32 Cam clone fitted with an ESP32-S OEM (“ZY”) and 8MB PSRAM. The ‘GND’ pin is actually tied to the EN/reset pin which is handy as the reset button on the board is not easily accessible.

      Next issue I have is that the PSRAM is 3.3V, GPIO12 is floating to 3.3V meaning the ESP will supply 1.8V to the SPI flash and PSRAM. I am going to use efuse to burn 3.3V option and avoid complications with the bootstrapping.

      Reply
      • Hmm. I don’t think the 3.3V efuse burn is required as now the device boots with default firmware, however I am unable to write anything to the device. I haven’t had these issues with the other ESP32 modules or my custom embedded devices.

        Reply
  43. Your pinout diagram is a little misleading as it suggests that all the GPIOs on the left are reserved for the SD card. However, as has been suggested by others, it depends how you drive the SD card. If you initialise with SD_MMC.begin(“/sdcard”, true) it operates in SPI mode. In this mode GPIO12 and GPIO4 are not used. GPIOs 14, 2, 15, 13 are used for SPI CLK, MISO, MOSI, CS. So you get GPIO12 and GPIO4 (driving the flash) to play with. Furthermore, in SPI mode you can attach a SPI expander such as MCP23S18 to the SPI pins and use GPIO12 for its CS to give you 16 further GPIOs.
    I think it would be good to update the pinout diagram to show the SPI mode pin usage as, arguably, it is more useful to most people than the SD mode pin usage. See https://components101.com/misc/microsd-card-pinout-datasheet for the detail.

    Reply
    • Hi yorrrick,

      I have just ordered the ESP32 CAM I want to use for my next project. Hence, I have no experience with SPI so far, but I would like to use it to send single photos taken with the ESP32 CAM to a Raspberry PI or an other SPI capable SBC to use them later on.

      Do understand correctly that you can address with GPIO 12 HIGH the MCP23S18 and GPIO 04 with HIGH the SD card? Then using the GPIO 14, 2, 15 for the actual communication with the ESP32 as master.

      If I would like to address the ESP32 from another master, then I would use GPIO13 in HIGH as the Client Select line to communicate with it as client? Then I would not need to use a MCP23S18, isn’t it?

      Reply
      • If you don’t want to expand your GPIOs then you won’t need the MCP23S18. If you are not going to use the SD card you have GPIO 14, 2, 15, 13 & 12 all free to use as you see fit. You have five uncommitted GPIOs and need any four of them for SPI. I would ignore GPIO 4 as it drives the flash light and may not work properly as an input. You could either use the ESP32 CAM as SPI master or as SPI slave. It might be easier to have the ESP32 CAM operate in SPI master mode and send each image to your second device when it is available to avoid running out of memory on the ESP32 CAM but I’m sure it could be done the other way round too.

        Reply
        • Hi yorrrick!
          Thanks for chiming in. It’s really appreciated!
          Good to know they can be used freely then.
          I hope I will not forget, but I will report back here how it goes.

          Reply
    • Just to clarify: I don’t need the SD card on the ESP32 CAM if I understand correctly, as I want to get the images pulled from the ESP32 as SDI client anyway.

      Reply
  44. Re: ESP32-CAM Serial communication

    Once my sketch is running, “Serial.begin(115200);” allows Serial.print() to send to the Arduino Serial Monitor. Works fine.

    The Serial Monitor has a bar at the top with a “Send” button. Is there a “Serial.receive” or “Serial.read” type statement that allows my script to receive characters or text typed into the bar at the top of the Serial Monitor?

    That is, once a script is uploaded to the ESP32-Cam, is the serial input available for scripts to receive data?

    I assume Arduino.h is managing serial 0 for uploading and “Serial.begin” activity, and trying “HardwareSerial mySerial(0);” and “byteFromSerial= mySerial0.read();” hasn’t yielded any joy.

    Thanks!

    Reply
  45. I was over-complicating things. Serial.read() works fine.

    // serial input on ESP32-CAM

    #include “Arduino.h”

    void setup() { // put your setup code here, to run once:
    Serial.begin(115200);
    Serial.println();
    Serial.println();
    Serial.println(“ESP32-CAM Spins waiting for incoming serial bytes…\n”);
    Serial.println(“(Enter keystrokes at the top of the Arduino Serial Monitor.)”);
    Serial.println();
    }

    char incomingByte = 00;
    void loop() { // put your main code here, to run repeatedly:
    while(Serial.available()) {
    incomingByte = Serial.read();
    Serial.print(“Serial Byte: “);
    Serial.print(incomingByte);
    Serial.print(” (0x”);
    Serial.print(incomingByte,HEX);
    Serial.println(“)”);
    }
    delay(100);
    }

    Reply
  46. Hi, anybody knows the model/maker of flash-led on esp32-cam?
    I tried
    3v 3535
    3528
    Both doesn’t seem feet from voltage point of view

    Reply
  47. The pin at the end labelled “GND” is not a ground pin (it does note share continuity with the other 2 GND pins). On my board, it is labelled “GND/R” and connects directly to a resistor on the PCB.

    Many other people in forums are being tripped up by that wrong label.

    Reply
  48. Great tutorial! I was able to get my camera working with little difficulty. The streaming server example worked fine for a quick and dirty crawlspace exploring camera on a stick. Looking forward to mounting the cam board inside a 3d-printed eyeball for Halloween!

    Reply
  49. Hi Sara, I need to know if a level shifter is mandatory to connect U0T and U0R from the esp32cam to tx2 rx2 on an Arduino mega 2560. I believe you need it on a plain esp32, but not on an esp32cam that is powered at 5 volts. Obrigado.

    Reply
    • There is no PIR motion detector on the ESP32-CAM if that was behind your question. Any motion detection would be done in software by comparing successive images. You might then choose to set a GPIO to indicate motion had been detected but there is no dedicated GPIO for motion detection.

      Reply
  50. hello mi esp 32 cam gpio pin are always high i dont know this happening,even if i put them on low they still are on high the give out voltage,could you pls explain why?

    Reply
  51. Hi
    I have a problem when I’m using esp32 cam. I upload the sketch but when I compile I get the error :
    Arduino: 1.8.16 (Windows 8.1), Board:”AI Thinker ESP32-CAM, 240MHz (WiFi/BT), QIO, 80MHz”
    In file included from sketch\ESP32-CAM_blink.ino.cpp:1:0:

    C:\Users\Looitje\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5\cores\esp32/Arduino.h:184:12: error: ‘std::round’ has not been declared
    using std::round;
    exit status 1

    How can I solve this problem? Is there a setting wrong somewhere? I selected board “AI Thinker ESP32-CAM”.

    Reply
  52. If I use the board not as camera and do nout use an SD-card, can I use the 6 ports GPIO2,3 and GPIO12-GPIO15 as PWM output ports?
    Thank you , Ya

    Reply
  53. Goodnight! Is it possible to use a higher voltage on the 5V input of the esp32cam? For example if you use 2 18650 batteries in series we will have a voltage of approximately 7.4V. The regulator that drops from 5 to 3.3V is the AMS1117. I consulted the datasheet of the regulator and there it says that it supports up to 15V maximum at the input of the regulator. Therefore, it seems possible to use a voltage of 7.4V on this pin. Can anyone confirm this?

    Reply
    • The issue will be heat dissipation. At 5v the regulator has to drop 1.7v and pass 250mA-750mA which means it has to shed 0.4W-1.2W. At 7.4v the regulator would need to drop 4.1v so it would need to shed 1W-3W. I’d be surprised if it could do this without either shutting down or burning out. I’d advise using a 7805 on a basic heatsink to drop your battery voltage to 5v before passing to the ESP32-CAM.

      Reply
  54. Hello,
    Apologies for the potentially very simple question. I’d like to set a GPIO pin as a pullup input – I expect this input to therefore be HIGH and remain high.

    I define it within the camerawebserver example in the setup section as
    pinMode(13,INPUT_PULLUP)

    Then in the main loop I have
    delay(50)
    if (digitalRead(13) == HIGH){
    Serial.println(“1”);
    } else {
    Serial.println(“1”);
    }

    Weirdly the serial monitor shows an output that toggled between 1 and 0. This is with the CAM MB-USB programmer connected. I’ve tried using different GPIO pins (12, 15, 16) since it sounds like some are not safe to use. I must be missing something simple, would really appreciate any insight you all may have

    Reply
  55. I have finally found time to get an I/O expander interfaced to an ESP32-Cam.

    tldr: Use an MCP23S08 or MCP23S17 to share the SPI bus with the SD-card reader running in SPI mode. You get 8 or 16 free GPIOs, a fully working SD-card reader, and no flashlight flickering.

    For full details and an example sketch see https://github.com/jksemple/ESP32CamSPI

    Reply
  56. From reading the comments, it seems like there is a need to see a complete example of using I2C on a ESP32-CAM board, with code, pin-outs, extra hardware, and, optionally, integrated with the SD disk in SPI and SD access modes… Many people asked for details, and if you were to figure it out, it would be a valuable add to your e-book, I think.

    IOW, do what people tell you is lacking from your posts.

    Reply
    • Due to the lack of uncommitted GPIOs, running I2C and the SD card on an ESP32Cam is difficult. In SD_MMC 4-bit mode the SD card uses GPIOs 12, 13, 15, 14, 2 and 4 so there are no spare pins for I2C. In SD SPI mode the SD card uses GPIOs GPIOs 13, 15, 14 and 2 leaving GPIO12 and GPIO4 but as GPIO4 is also runs the flash it doesn’t work too well for I2C. In SD_MMC 1-bit mode the SD card leaves GPIO 12 and 13 free and those might indeed be used for I2C but I haven’t tried it. I chose to use the SD card in SPI mode and add an SPI I/O expander as explained in my earlier post to give lots of spare GPIOs. Lots of I2C peripherals are also available as SPI peripherals so this may be an option for some people instead of sweating the I2C problem.

      Reply
  57. can any gpio pins be used simply to send a signal back to an stm32 board it is connected to?
    for example i want to use the esp32 for object detection and send a simple digital high or digital low output to the stm32 can it be done? if so which pin?

    Reply

Leave a Comment

Download Our Free eBooks and Resources

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