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
GNDGND
5VVCC (5V)
U0RTX
U0TRX
GPIO 0GND

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.

Solution: 

  • 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.

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.


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!

9 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 ?

    Reply
  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?

    Reply
  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.

    Reply
  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?

    Reply
    • 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)
      Regards,
      Sara

      Reply

Leave a Reply to Sara Santos 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.