This tutorial covers how to use ESP32-CAM with PlatformIO. This guide describes step by step how to compile and run ESP32-CAM sketch with PlatformIO. In more detail, we will cover how to compile and run CameraWebServer sketch so that you can enable:
- video streaming
- face recognition
and start implementing rich IoT applications. As you may already know, ESP32-CAM is an ESP32 with camera support (OV2640) with other interesting features.
Preparing PlatformIO
Before starting with ESP32-CAM, it is necessary to install and configure the PlatformIO. In this ESP32-CAM tutorial, we will use the Visual Studio Code with PlatformIO plugin. Download it and add the PlatformIO extension using the button as shown in the picture below:

Once you have clicked on the button you have to look for PlatformIO extension and install it.
Importing CameraWebServer into PlatformIO
Let’s clone the Github repository containing the source code for CameraWebServer. Go to Github and download the repository. If you prefer you can clone it using this command:
git clone https://github.com/espressif/arduino-esp32.git
Open the PlatformIO extension and select Import Arduino Project:

When importing the project into PlatformIO select AI Thinker ESP32-CAM
in the board box. Then move to arduino-esp32/libraries/ESP32/examples/Camera/CameraWebServer
and import the project.
Please be sure that in the file named platformio.ini
contains the following lines:
[env:esp32cam]
platform = espressif32
board = esp32cam
framework = arduino
Compile the code.
Uploading the code into ESP32-CAM from PlatformIO
To connect the ESP32-CAM to your PC USB port you need an adapter because ESP32-CAM doesn’t have an USB port. Therefore, you have to use FTDI232 that’s a USB serial converter. Connect the ESP32-CAM to the FTDI232 using the following schema:

If your FTDI232 has a jumper to set 3.3V or 5V set 5V.
Before uploading the code you have to connect the GPIO 0 to the GND.
Customizing the CameraWebServer code
Before using the code into the ESP32-CAM, you have to apply some customization to the CameraWebServer code. Open CameraWebServer.ino
using PlatformIO and modify the code as shown below:
- Uncomment this line
#define CAMERA_MODEL_AI_THINKER // Has PSRAM
Code language: PHP (php)
Next:
onst char* ssid = "your_wifi_ssid";
const char* password = "your_wifi_password";
Code language: JavaScript (javascript)
Now you are ready to compile and upload the code into your ESP32. Then you can stream your video from ESP32-CAM.

Once the uploading is complete, you have disconnect the GPIO 0 from the GND e restart the device.
Streaming Video from ESP32-CAM
Run the code and open the serial monitor in your PlatformIO. Notice to press the Reset button to start the application

Now you can start streaming video from the ESP32-CAM. Open your browswer and copy the URL shown in the previous image:

Here you can change some settings according to your need. Using Resolution settings you can change the image and video resolution. As you can see, using the browser it is possible to stream the video using the ESP32-CAM
Face detection and face recognition
To enable face recognition you have to ckeck two buttons at the end of the settings:

If you enable the option Face detection as soon as the ESP32 detects a face, it creates a square around it. Moreover, you can press on Enroll Face to enroll a new face. Consider that it may be necessary several attempts before the device can enroll a new face. If you want to use ESP32-CAM with machine learning you can read how to use Machine Learning with ESP32-CAM.
Recommended:
How to connect ESP32 to the smartphone through Node-RED
ESP32 MQTT client: Publish and Subscribe. HiveMQ and BME280 example
Getting started with ESP32: Build a weather station (BMP280 + SSD1306)
Wrapping up
At the end of this post, you have learning how to use ESP32-CAM with PlatformIO. Moreover, you have discovered how to stream video from ESP32-CAM and how to detect faces. ESP32-CAM is a powerful device that adds to the ESP32 the video capabilities. You can start creating interesting projects once you know how to develop a sketch for ESP32-CAM.
Hi, I was following this tutorial and it’s giving me this error Failed to connect to ESP32: Timed out waiting for packet header
When do you get this error? Do you get it while uploading the code to the ESP32 or when you connect using your browser?
Hit the reset button on your esp32cam when you get the “connecting….” dialogue from your IDE, make sure your IO0 is tied to ground before you start flashing. The two tips I mentioned above should solve the problem if you hadn’t tried them yet. Make sure you untie IO0 from ground and press reset again after the flashing process is completed and you are ready to run the code you uploaded. Hope this helps!
Hello Thank you very much for the great instructions.
Unfortunately, I always get the following error message after starting the stram:
E (10869) httpd_txrx: httpd_resp_send_err: error calling setsockopt : 22
[ 14207][E][app_httpd.cpp:755] stream_handler(): Send frame failed
Hello! When I try to download the project, I have to put it in Google like: arduino-esp32/libraries/ESP32/examples/Camera/CameraWebServer or how? It appears like the project does not exist any more.