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.

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:

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.

Important: GPIO 0 needs to be connected to GND so that you’re able to upload code.
ESP32-CAM | FTDI Programmer |
GND | GND |
5V | VCC (5V) |
U0R | TX |
U0T | RX |
GPIO 0 | GND |
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.

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


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

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

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

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:
- Video Streaming, Face Detection and Face Recognition
- ESP32 IP CAM – Video Streaming (Home Assistant and Node-RED)
- Take Photo and Save to MicroSD Card
- PIR Motion Detector with Photo Capture
- Take Photo, Save to SPIFFS and Display in Web Server
- Build ESP32-CAM Projects (eBook)
- Read all our ESP32-CAM Projects, Tutorials and Guides
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.
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 ?
Hello Dave,
Have you tried using an external antenna with your camera? For my testing, it’s been improving tremendously the signal strength.
Regards,
Rui
Hi Rui,
I have not tried an external antenna tbh as the AP was pretty close to the camera.
Will give it a try though.
Thanks Dave
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:
WIFI_Connect();
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.disconnect();
WiFi.mode(WIFI_STA);
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”);
Serial.println(WiFi.macAddress());
}
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?
Hi Gustavo.
You can read our article about I2C with the ES32, it will help: https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/
Regards,
Sara
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.
Hi.
In your code, do you have the AI-Thinker board uncommented to use the right pinout?
Regards,
Sara
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)
Regards,
Sara
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?
just remove your usb, put it back and try again.
i have the same error like 50% of the times i try to upload the code.
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.
Regards,
Sara
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
Rocco
Hi.
How are you powering your ESP32-CAM?
We used a 5V power adapter as shown in this image and it worked fine: randomnerdtutorials.com/wp-content/uploads/2019/03/5V-power-supply-ESP32-CAM.jpg?w=750&ssl=1
Regards,
Sara
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.
Thanks.
Hi.
I have no idea. It works fine for me, whether it is connected to a PC or a power bank.
Regards,
Sara
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- rb.gy/fr7q66) 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.
Regards,
Sara
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.
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.
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.
As a follow up, my hookup worked first time and I can power ESP32-Cam from FTDI during testing
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:-)
Hi.
Yes, that should work too, I think.
Regards,
Sara
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.
Regards,
Sara
Hello Sara,
You do great job,
I want to give RST signal by programming, how can i do that?
Regards.
Hi.
You can use
ESP.reset()
in your code.
Regards,
Sara
Hi! Where in the ESP code would you put this rest commend? Also, does it need an ; after the () ? Thanks
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 (https://github.com/SeeedDocument/forum_doc/raw/master/reg/ESP32_CAM_V1.6.pdf) 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.
Regards,
Sara
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.
Another 5 star ***** tutorial Rui & Sara.
Thank you
D