How to Program / Upload Code to ESP32-CAM AI-Thinker (Arduino IDE)

The ESP32-CAM AI-Thinker development board can be programmed using Arduino IDE. This guide shows how to program and upload code to the ESP32-CAM (AI-Thinker) development board using Arduino IDE.

How to program upload code to ESP32-CAM board Arduino IDE with FTDI Programmer

The ESP32-CAM AI-Thinker module is an ESP32 development board with an OV2640 camera, microSD card support, on-board flash lamp and several GPIOs to connect peripherals. However, it doesn’t have a built-in programmer. You need an FTDI programmer to connect it to your computer and upload code.

Install the ESP32 Add-on

To program the ESP32-CAM board with Arduino IDE, you need to have Arduino IDE installed as well as the ESP32 add-on. Follow the next tutorial to install the ESP32 add-on, if you haven’t already:

Program ESP32-CAM (Upload Code with Arduino IDE)

To upload code to the ESP32-CAM (AI-Thinker) using Arduino IDE, follow the next exact steps.

Connect the ESP32-CAM board to your computer using an FTDI programmer. Follow the next schematic diagram:

ESP32-CAM connected to an FTDI Programmer to upload program using Arduino IDE

Note: the order of the FTDI pins on the diagram may not match yours. Make sure you check the silkscreen label next to each pin.

Many FTDI programmers have a jumper that allows you to select 3.3V or 5V. Make sure the jumper is in the right place to select 5V.

FTDI Programmer select jumper cap to 5V

Important: GPIO 0 needs to be connected to GND so that you’re able to upload code.

ESP32-CAMFTDI Programmer
5VVCC (5V)

To upload code to the ESP32-CAM using Arduino IDE, follow the next steps:

1) Go to Tools Board and select AI-Thinker ESP32-CAM. You must have the ESP32 add-on installed. Otherwise, this board won’t show up on the Boards menu.

2) Go to Tools Port and select the COM port the ESP32-CAM is connected to.

3) For demonstration purposes, you can upload a blank sketch to your board:

void setup() {
  // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly:

4) Then, click the Upload button in your Arduino IDE.

Program ESP32-CAM with Arduino IDE

5) When you start to see some dots on the debugging window, press the ESP32-CAM on-board RST button.

Program and upload code to ESP32-CAM with Arduino IDE
ESP32-CAM Press RESET RST on-board button to restart

After a few seconds, the code should be successfully uploaded to your board.

ESP32-CAM AI Thinker Module Arduino IDE Done Uploading Success Message

6) When you see the “Done uploading” message, you need to remove GPIO 0 from GND and press the RST button to run your new code.

Common Errors and How to Fix Them

If you don’t follow the previous instructions exactly, you may get the following errors:

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

ESP32-CAM Failed to connect to ESP32: Timed out waiting for packet header

This error means that the ESP32-CAM is not in flashing mode or it is not connected properly to the FTDI programmer.

Brownout detector or Guru meditation error

When you open your Arduino IDE Serial Monitor and the error message “Brownout detector was triggered” is constantly being printed over and over again. It means that there’s some sort of hardware problem.

It’s often related to one of the following issues:

  • Poor quality USB cable;
  • USB cable is too long;
  • Board with some defect (bad solder joints);
  • Bad computer USB port;
  • Or not enough power provided by the computer USB port.


  • Try a different shorter USB cable (with data wires);
  • Use a different computer USB port or use a USB hub with an external power supply;
  • Some readers were using 3.3V and reported that when powering the ESP32-CAM with 5V, the issue was fixed.

Board at COMX is not available – COM Port not selected

ESP32-CAM COM Port Not Selected

If you get the following error or similar:

serial.serialutil.SerialException: could not open port 'COM8': WindowsError(2, 'The system cannot find the file specified.')
Failed to execute script esptool
the selected serial port Failed to execute script esptool
 does not exist or your board is not connected
Board at COM8 is not available

It means that you haven’t selected the COM port in the Tools menu. In your Arduino IDE, go to Tools Port and select the COM port the ESP32 is connected to.

It might also mean that the ESP32-CAM is not establishing a serial connection with your computer or it is not properly connected to the USB connector.

Other errors

For a more extensive list of the most common problems with the ESP32-CAM and how to fix them, read our ESP32-CAM Troubleshooting Guide.

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 this guide helps you get started programming your ESP32-CAM AI-Thinker using Arduino IDE.

Check all our projects with the ESP32-CAM:

There are different models of ESP32 camera development boards that might be more suitable for your projects. So, you might also like reading:

Thanks for reading.

Build Web Server projects with the ESP32 and ESP8266 boards to control outputs and monitor sensors remotely. Learn HTML, CSS, JavaScript and client-server communication protocols DOWNLOAD »

Build Web Server projects with the ESP32 and ESP8266 boards to control outputs and monitor sensors remotely. Learn HTML, CSS, JavaScript and client-server communication protocols DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

43 thoughts on “How to Program / Upload Code to ESP32-CAM AI-Thinker (Arduino IDE)”

  1. Hi Rui,
    Thanks for very precise tutorials on ESP8266 and ESP32 projects 🙂
    I purchased 2 pcs ESP32 cameras from different Ebay vendors and are experiencing the same issue with both of them.
    After some hours of the camera functioning perfectly it disconnects from wifi (does not reply to ping even) but will reconnect again after power cycling camera.
    I have fitted an electrolytic across power header pins to stabilise power supply (5v) to camera.
    Also tested connecting to 2 different brand wifi access points (close to camera so signal strength is strong) also used 5volt 2 Amp regulated power supply for camera with no improvements.
    Have you had this problem before with the ESP32 camera boards ?

    • All the ESP32 seem to drop of the WiFi eventually. You can fix it with adding a few lines to your code by checking is the WiFi is still online and if not to reconnect to the WiFi. I have added these lines to all my code and it works.

      In setup add:


      And in loop:

      if (WiFi.status() != WL_CONNECTED) WIFI_Connect(); //Make sure wifi is still connected

      And add this to be save before setup() to avoid compiler warnings.

      void WIFI_Connect()
      WiFi.begin(SSID, PASSWORD); //Use #define SSID “YourWiFi” etc the top etc
      for (int i = 0; i < 60; i++) {
      if ( WiFi.status() != WL_CONNECTED ) vTaskDelay(500); //Need this to feed the watchdog!
      if (debug) Serial.println(“Connected to wifi”);

  2. Hi! Thanks for the tutorial!
    I’m trying to connect a gpio extender (PCF8574), and it uses an i2c protocol. Do you know how can I set up a new i2c bus for the extender?

  3. Rui, I can seem to get past the camera setup on my esp32-cam boards. I have tried several different boards and cables, different board configs and progammer settings. I can get the program to load but when the esp32-cam is reset always ends in detected camera not supported
    Camera probe failed with error 0x20004.

  4. Hi, Thanks for the tutorial.
    i am unable to upload cam web server program to my board. It shows sketch is large and timed out waiting.
    In tools, there is no partition scheme shown to change to Large app OTA.
    May i know how to add that partition scheme ??
    or any other fixes?

    • Hi.
      If you’re having that issue, select the board “ESP32 Wrover Module”
      Then, you can select the partition scheme to Huge APP(3MB No OTA)

      • I tried as Wrover Module and AI Thinker. In both the cases, after compiling the sketch, it shows connecting_____……….____……… and goes on ! to show the error A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header
        Checked CP2102 programmer, tried uploading with Arduino via Tx/Rx and nothing worked. previously a month ago, i was able to do the same.
        what may be the bug ? any fixes?

  5. Hi,

    I have recently buy an ESP32 CAM and I have a doubt: I hav the same FTDI programmer that you used in the document.

    Must I switch jumper to 3.3 V or to 5V ? I thought that must be in 3.3V taking in account that the ESP32 is 3.3 V compatible in its inputs and outputs but a I read in your document and saw in the picture that jumper is in 5 V.

    Thank you very much

    • Hi Eduardo.
      Yes, put the jumper in 5V.
      In our case, it worked in both configurations. However, many of our readers had problems with the 3.3V configuration – that’s why we recommend 5V.

    • Eduardo you are correct, the jumper should be set to 3.3V. The [ESP32 chip] only runs at 3.3V and so you should never drive its input pins higher than that. If you do, current will flow through the built-in protection diodes into the 3.3V bus, and this can damage the ESP32. The FTDI jumper must be set to 3.3V.

      BUT with this 3.3V jumper set correctly, the VCC output voltage is too low to power up the [ESP32 board]. The problem is that the [ESP32 board] needs 5V but the [ESP32 chip] can only handle 3.3V. The [ESP32 board] takes the 5V input and regulates it down to 3.3V for the [ESP32 chip]. That regulator won’t work if you only give the board 3.3V to start with. So the red wire in the hook-up diagram is incorrect.

      The correct solution is to give the [ESP32 board] the +5V it requires from the terminal pad labeled “5V” on the FTDI board. On my FTDI board this pad is located 4 holes up from the end on the long edge of the board. I had to solder a wire to it, there isn’t a pin header on this edge.

      When you power the [ESP32 board] from “5V” and set the jumper to 3.3V then the configuration is good and you won’t damage anything.

      Jim Luschen

  6. Hey, thank you for the great tutorial,
    it runs perfectly with the programmer hooked on it, but can it be run without the FTDI once it was programmed? I am not getting it to work the moment I run it without the interface. As it is not hooked up, I can’ debug it.
    Any suggetions?

    Thank you

    • Hi.
      How are you powering your ESP32-CAM?
      We used a 5V power adapter as shown in this image and it worked fine:

    • Were you able to figure this out? I have the same problem.

      I can even disconnect the TX/RX lines from the FTDI (so only 5V and GND are connected to the ESP32-CAM), plug that into my computer, and it works.

      I take that same setup and plug the USB cable into a 5V USB power bank — nothing. Or I use my lab power supply and connect it to 5V and GND on the ESP32-CAM…again nothing.

      What’s the magic about plugging the USB cable into a computer USB port? Not making any sense to me.


        • Dear Sara Santos,

          Please re-read NickB’s comment. He is correct on all accounts.
          Remember there are designers trying to work with the
          ESP32-CAM. We are designing after market products using
          this board. We need to run it WITHOUT the FTDI as the power
          source. We want to run it with a VCC and a GND.

          I am confident in saying that there is an error in this board.
          I will look at the circuit diagram but I am not going expend much
          time doing so.

          If you have direct contact with the design/manufacture of this board, tell
          them it has a power source design error and for them to fix it.

          Please let me know when a new version of the board is released.

          Sara, thank you for all of your valuable comments thus far.

          Anxiously awaiting new version,
          Rex Rooples

  7. Hi Rui/Sara,

    I am trying to upload the code to ESP32-S cam board(It not branded as AI thinker but with espressif logo, link- using FTDI programmer . I am struggling with error “A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header” from past two days. Connections to FTDI programmer from ESP32 cam are perfect. TX /RS are not swapped. IO0 is connected to GND and I am supplying 5v using Jumper cap on FTDI, also tried the workaround of holding RST button for long time but still getting the error. Can I assume that board is faulty ? If possible could you please let me if there is any way to test at least if board is working.

    • Hi.
      That board, looking at the photo seems OK.
      In this article we already discuss the main issues and possible ways to solve them.
      Maybe you can check your FTDI programmer? Are you sure it works OK?
      What FTDI programmer are you using?
      We’re using the one as shown in the photo in this tutorial.

      • Hi Sara,

        I just did a loop back test with FTDI programmer using putty, I am able to see the echo. So I can say FTDI programmer is working fine.

  8. Hi Rui & Sara,

    I successfully flashed the Sketch in my ESP32-CAM. Mine is a Chinese brand so I was not expecting it will work properly. Before doing the flashing, I did several research on different sites so I learned that the FTDI programmer must be in 5V config and ESP32-CAM works better in 5V supply. FTDI programmer is my preferred programmer for ESP-01 by the way.
    I encountered the expected errors and bugs so to speak.

    The only thing that bothers me is my ESP32-CAM will only work when the Tx-Rx are still connected? Is this expected?

    I was thinking 5v and GND are sufficient.

  9. WARNING: This hookup is wrong and can damage your ESP32. On FTDI1232 when the jumper is placed in the 5v position it also drives the serial I/O pins at the 5v rail (on FT232RL VCCIO is then connected to 5v instead of the onboard 3.3v 50ma regulator and since the ESP32 input pins are not 5v tolerant, it can be damaged). Moreover, in that configuration you simply cannot then connect the FTDI VCC output pin to the 3.3v pin on the ESP32-Cam because of the low current output on the FT232RL. Instead LEAVE the jumper in the 3.3v position and connect the ESP32-Cam 5v pin to the 5v jumper pin. In that way logic levels will be at 3.3v and power to the ESP32-Cam will be supply through its onboard regulator. I have seen other hookups leaving the jumper at the 3.3v position and supplying the ESP32-Cam directly from the FTDI1232 and of course that is equally wrong. Either hookup may work but not reliably and the 5v jumper position could very well damage your ESP32-Cam.

  10. Can I use a USBASP instead of the FTDI? Isn’t it just serial TX/RX data?

    I don’t have a FTDI but a couple USBASPs.

    I want to program my ESPCAM:-)

  11. Hello Folks:

    I am so grateful for this forum. Only after I switched to 5 V mode from 3.3V did the camera start working properly–otherwise I was bogged down with “brownout” issues for nearly a whole day! I do have a problem however–there are a lot of fine horizontal lines in the picture–is there any way to prevent this? Or am I expecting too much from a $10 diy camera? OR is this part of the normal diy experience???

    • Hi.
      The horizontal lines are not normal.
      It may be a weak wi-fi signal or the camera might be not connected properly.
      You can disconnect the camera and connect it again to make sure that everything is good.

  12. The FTDI board produces regulated 3.3V why can’t I just attach directly to the 3.3V rail on the ESP32? If I were making a custom circuit using an ESP32 I would just be powering everything off of 3.3V anyway, going through 5V seems like an unneeded step.

    Also looking at the schematic for the ESP32-CAM board ( I don’t see anything on the board that needs 5V aside from the regulator

    • Hi.
      You are right.
      Our projects worked well with 3.3V.
      However, many of our readers reported that they were able to upload code only after powering 5V.
      That also works for us. That’s why we recommend 5V. It works for everyone.

      • Hi. I contacted Rui about the ESP32 CAM. After hours and hours of trying to upload the program for the Camera Web Server, I finally got it to load. However, after removing the grounding wire and resetting the camera all I see on the serial monitor is the recognition of the Cam but then as it tries to connect to the internet I get screen after screen of :
        Can you tell me what this means or what the program is trying to do? This is the part of my original question that Rui did not address. Looking forward to hearing from you.

  13. esp32 cam
    I press reset to get IP address, and in Arduino serial monitor i get

    Jun 8 2016 00:22:57

    rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    mode:DIO, clock div:1
    ho 0 tail 12 room 4
    entry 0x400806b4

    . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

    The row of dots just continues indefinitely with no more information printed
    Any ideas about what is happening?.


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.