Introduction

In this post we will program ESP32-Cam using Arduino Uno. But you can use Arduino Pro or Mega, or another one version of course.

We will upload the default sketch from the official espressif/arduino-esp32 github page to the ESP32-Cam.

Everything in this post is done on Ubuntu 22.04.1 LTS.

Wiring Diagram

programming-esp32-cam-using-arduino-uno-wiring-diagram

  • Red - Arduino:5V -> ESP32-Cam:5V
  • Black - Arduino:GND -> ESP32-Cam:GND
  • Green - Arduino:TX -> ESP32-Cam:UOT
  • Yellow - Arduino:RX -> ESP32-Cam:UOR
  • Purple - ESP32-Cam:GPIO0 -> ESP32-Cam:GND

This wire is used to set the ESP32-Cam to the FLASH Mode.

  • Blue - Arduino:RESET -> Arduino:GND

This is used to set the Arduino as a programmer for the ESP32-Cam.

Configure Arduino IDE

I use Arduino IDE v2. But all of these instructions would work for Arduino v1 also.

  1. Open Arduino IDE and navigate to the File > Preferences.
  2. We should add the URL for the ESP32-Cam Board Manager to the Additional boards manager URLs setting. To do this click on the button right of the input field. arduino-ide-v2-add-library-paths And paste this line
https://dl.espressif.com/dl/package_esp32_index.json

Tip. If you want to add more URLs behind this line in the future, just add new URL to a new line.

  1. Now we should install the Board Manager for the ESP32-Cam. Navigate to the Tools > Board > Boards Manager…. In the search bar type the esp32 and click on the Install button. arduino-ide-install-esp32-board-manager

Configure ESP32-Cam board in the Arduino IDE

After the previous steps (Wiring and Arduino IDE configuration) connect your Arduino Uno board to the computer.

Now we can select the ESP32-Cam board in the Arduino IDE and program it!

  1. Navigate to the Tools > Board > esp32 and select ESP32 Wrover Module.
  2. Set the Upload Speed to the 115200 in the Tools > Upload Speed.
  3. Set the Flash Frequency to the 40MHz in the Tools > Flash Frequency.
  4. Set the Flash Mode to the QIO in the Tools > Flash Mode.
  5. Set the Partition Scheme to the Huge APP (3MB No OTA/1MB SPIFFS) in the Tools > Partition Scheme.
  6. Set the Port to the /dev/ttyACM0 (or /dev/ttyS0, or similar to these) in the Tools > Port.

Programming the ESP32-Cam using Arduino Uno

Now we can select the example sketch: File > Examples > ESP32 > Camera > CameraWebServer.

Modify a few lines of code to get it working.

  1. Change SSID - your Wi-Fi Network name. Modify the line
const char* ssid = "*********";

with the following line (just use your Wi-Fi Network name)

const char* ssid = "3D2DAY-WiFi";
  1. Change Wi-Fi Password - password to connect to your Wi-Fi Network. Modify the line
const char* password = "*********";

with the line contains the password for your Wi-Fi Network

const char* password = "share_this_page_with_friends";
  1. Replace the line
#define CAMERA_MODEL_WROVER_KIT // Has PSRAM

# with the line

//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM

and replace the line

//#define CAMERA_MODEL_AI_THINKER // Has PSRAM

# with the line

#define CAMERA_MODEL_AI_THINKER // Has PSRAM

That’s it!

Click on the Upload button to upload the code to the ESP32-Cam.

If everything is OK, you will see the upload percentage in the Arduino IDE CLI. arduino-ide-upload-skecth-to-esp32-cam-without-errors

If you have any issues uploading the sketch - please read the TroubleShooting section.

Test ESP32-Cam

After sketch will be uploaded in the Arduino IDE CLI you will see the lines

Leaving...
Hard resetting via RTS pin...

Follow the steps:

  1. Insert the microSD card into ESP32-Cam. The volume of the microSD card should be 4 GB or less. With larger volume also should work, but ESP32-Cam can only use 4 GB.
  2. Disconnect the purple wire from the ESP32-Cam.
  3. In the Arduino IDE open Tools > Serial Monitor.
  4. In the Serial Monitor window set the Baud Rate to the 115200.
  5. Click RST (reset) button on the back side of ESP32-Cam.

In the Serial Monitor window you should see the ESP32-Cam trying to connect to your Wi-Fi. And when it’s finished, you will see the URL.

arduino-ide-esp32-cam-connected-to-wi-fi

This is the URL where the ESP32-Cam streams the video. Open it in the new tab of the browser and click on the Start Streaming button.

esp32-cam-streaming

If you have errors in the Serial Monitor - please read the TroubleShooting section.

Troubleshooting

1. “python”: executable file not found in $PATH

arduino-ide-python-executable-file-not-found-in-PATH

You probably have Pyhton 3 installed, which calls like python3 in the Command Line Interface. But the Arduino IDE calls it as python.

This is why you got this error.

To fix this, just open Terminal (CLI App) and execute the following:

sudo apt install python-is-python3

2. ModuleNotFoundError: No module named ‘serial’

arduino-ide-ModuleNotFoundError-No-module-named-serial

This means that Python’s serial module is not installed. To install it and fix the issue, do the following (from the CLI):

  1. Install the pip3 if you have Python 3 installed, or pip - for Python 2.
sudo apt install python3-pip
  1. Install the serial library
pip3 install pyserial

Tip. To check Python version you have installed run the command python --version in the CLI.

3. PermissionError: [Errno 13] Permission denied: ‘/dev/ttyACM0’

arduino-ide-PermissionError-Errno-13-Permission-denied-dev-ttyACM0

This issue occurs because we do not have permissions on the /dev/ttyACM0.

To set permissions please do the following:

# navigate to the rules.d directory
cd /etc/udev/rules.d

# create a file for the ne rule
sudo touch myrules.rules

# open the file
sudo vim myrules.rules

# add the line
KERNEL=="ttyACM0", MODE="0666"

Restart your computer.

4. Arduino IDE cannot connect to the ESP32-Cam during sketch upload.

If you see the line

Connecting........_____....._____....._____.....

which doesn’t stop and at the end you get the error

Could not connect

Simply click the RST (reset) button on the back side of ESP32-Cam the next time you upload the sketch.

5. “Brownout detector was triggered” error for ESP32-Cam in the Serial Monitor of Arduino IDE.

This happens when ESP32-Cam needs more power.

For example, you may get this error if you connect the Arduino with ESP32-Cam to the USB of the keyboard (if you are using a PC).

Just reconnect to another USB.

6. ESP32-Cam’s LED lights up all the time.

Most likely the issue is with the microSD card.

Try to use another one or with less volume.