The Esp32-Cam is a cheap, 2-megapixel, small-size camera module developed by AI-Thinker. It integrates an Esp32, a single 2.4 GHz Wi-Fi-and-Bluetooth SoC (System On a Chip) designed by Espressif Systems, and an OV2640 camera from OmniVision.

Its dimensions and, of course, its price, make it a great choice for small IoT projects, even if getting started can appear more daunting than it is.

In this article, we’ll take a closer look at the Esp32-Cam, we’ll go over what the Arduino IDE is, and we’ll look at different ways to connect them so that you can start using an Esp32-Cam in your projects. We’ll see how it can be simple even if you’re a complete beginner, so let’s get started!

Esp32-Cam
Commissions Earned Check price at

Back to Contents

Esp32-Cam with Arduino IDE: The Basics

What Is It?

Esp32-Cam AI-Thinker pinout
Esp32-Cam AI-Thinker pinout (Source: Random Nerd Tutorials)

The standard AI-Thinker Esp32-Cam is compact (27 mm x 40.5 mm x 4.5 mm), and really cheap (around $10). Even the most expensive Esp32-Cam CH340 version will only set you back around $20.

The Esp32-Cam boasts a built-in flashlight and a microSD card slot to save images from the 2-megapixel camera. The same microSD card can be used to store files useful for your application.

Along with the integrated Wi-Fi and Bluetooth connectivity (with an onboard antenna), the board has a connector for an external antenna, which can be useful if you need to increase the range of your signal.

You can power the board with 3.3V or 5V – just choose the proper pin. Even if many GPIOs are used by the camera (15 pins), the microSD adapter (6 pins), the built-in flashlight (GPIO 4), and the built-in red LED (GPIO33), 10 GPIOs remain to be connected to external peripherals (see the light blue labels in the image above).

On the downside, because of its conveniently small size, there’s no built-in USB programmer (only the Esp32-Cam CH340 has it), and the reset switch is on the bottom, which isn’t easily accessible.

Nevertheless, having one or more Esp32-Cam boards on hand can help you start a project where you need a small camera and a cheap solution “all-in-one”. Maybe you can create a swarm of small robots to conquer the world! There are plenty of ideas for you to try.

Back to Contents

Advertisement
Advertisement
Advertisement
Esp32-Cam with Arduino IDE: The Basics

Arduino IDE

Esp32-Cam AI-Thinker
Esp32-Cam AI-Thinker (Source: Luca Dinale via All3DP)

The simplest way to start programming this little board is to use the Arduino Esp32 toolchain in the Arduino IDE (Integrated Development Environment), an application developed by Espressif that’s used to write and upload code (programs) to Arduino-compatible boards.

The Arduino IDE uses a stripped-down and simplified version of the programming language C++. Beginners can start with examples and tutorials, but more advanced programmers can create their own libraries and use a CLI (Command Line Interface) application.

With Arduino, your program is called a “sketch”, and when you compile it, it’s “magically” debugged, translated into proper C++, and sent to your board in binary form (machine language).

If you encounter errors while compiling, the Arduino IDE itself gives you suggestions to find your mistake. Quite often, especially for new users, it’s a syntax error. One of the most frequent errors is to forget to add a semicolon to the end of a line. You can learn more about Arduino IDE version 1, Arduino IDE version 2, Arduino Web Editor, and Arduino PRO CLI from the Arduino website.

There are different ways to connect your Esp32-Cam and Arduino IDE (running on your computer), both physical and remote. Next, we’ll go over five different physical ways to make the connection, then we’ll see how to work your Esp32-Cam and Arduino IDE, and finally, we’ll look at the alternative: connecting things remotely.

Back to Contents

Advertisement
Advertisement
Advertisement
1
Esp32-Cam with Arduino IDE: The Basics

FTDI Cable

Connection between an FTDI cable and an Esp32-Cam
Connection between an FTDI cable and an Esp32-Cam (Source: Luca Dinale via All3DP)

The FTDI (Future Technology Devices International) cable is a USB-to-Serial converter that provides a simple way to connect your standard Esp32-Cam to a USB port on your computer. If you have an FTDI cable on hand, you can power the board with the 3.3V or 5V pins, plus Ground (GND) pins.

Pin GPIO0 determines the Normal mode or the Flash mode of the module:

  • GPIO0 connected to Ground = Esp32-CAM in Flash Mode = You can upload the code
  • GPIO0 not connected to Ground = Esp32-CAM in Normal Mode = The board executes the program

There are two serial pins, GPIO01 and GPIO03 (marked UOT and UOR), which can be used for serial transmission and to receive data with the UART (Universal Asynchronous Receiver-Transmitter) protocol.

Other than the FTDI cable, you’ll need five jumper cables to connect the Esp32-Cam, as seen in the image above:

  • 5V red cable connects to 5V on the board (or 3.3V if you use a 3.3V FTDI cable).
  • GND to GND.
  • TXD orange cable to UOT on the board.
  • RXD yellow cable to UOR on the board.
  • A jumper connects GPIO0 and GND (before uploading the code). Always remember to reset the board after changing the state of GPIO0. Connect and reset to upload, disconnect and reset to run the program.

Keep in mind that, because the reset switch is on the bottom of the board, it can be difficult to reach. To reset the board, you can simply disconnect and reconnect the 5V wire or the ground wire. Remember to keep the Arduino Serial Monitor open (Arduino IDE Menu > Tools > Serial Monitor) because it can give you important information and help you to debug your sketch.

Back to Contents

Advertisement
Advertisement
Advertisement
2
Esp32-Cam with Arduino IDE: The Basics

FTDI Programmer

FTDI programmer connected to an Esp32-Cam
FTDI programmer connected to an Esp32-Cam (Source: Luca Dinale via All3DP)

An FTDI programmer has exactly the same functionality as the cable – it’s also a USB-to-Serial converter, allowing you to simply connect it to a USB port on your computer. The difference between the cable and the programmer is the different pinout of the serial connection:

  1. Connect RX on the FTDI programmer to UOT on the board.
  2. Connect TX on the FTDI programmer to UOR on the board.

Usually, FTDI programmers have a jumper to select 3.3V or 5V. Just remember to connect to Esp32-Cam accordingly. If you set the programmer to 5V, connect to 5V on the board; and if you set the programmer to 3.3V, connect to 3.3V on the board.

Back to Contents

Advertisement
Advertisement
3
Esp32-Cam with Arduino IDE: The Basics

Arduino Nano, Uno, & Others

Arduino Nano and an Esp32-Cam
Arduino Nano and an Esp32-Cam (Source: Luca Dinale via All3DP)

Maybe you don’t have an FTDI cable or an FTDI programmer at hand, but you may have an Arduino, be it a Nano, Uno, or other Arduino board.

You can send data from the Arduino board to the Esp32-Cam serially by using the UART Communication Protocol, which has the following connections:

  1. 5V to 5V on the board (or 3.3V to 3.3V).
  2. GND to GND.
  3. TXD orange cable to UOT on the board.
  4. RXD yellow cable to UOR on the board.
  5. A jumper between GPIO0 and GND (before uploading the code).

The image above shows Arduino Nano connections.

Arduino Uno + Esp32-Cam
Arduino Uno + Esp32-Cam (Source: Luca Dinale via All3DP)

To connect an Arduino Uno, you can follow the same instruction as for Arduino Nano; you can confirm the Arduino Uno connections in the image above.

If you want to use another Arduino board you already own, you just have to make sure you are using the proper pins according to the numbered schema above.

To connect the Arduino board to your computer, you only need a USB connector (a mini USB cable is needed for the Nano).

Back to Contents

Advertisement
Advertisement
4
Esp32-Cam with Arduino IDE: The Basics

Esp32-Cam MB Micro-USB Programmer

An Esp32-Cam-MB USB Programmer
An Esp32-Cam-MB USB programmer (Source: Random Nerd Tutorials)

Esp32-Cam MB Micro-USB programmer is a shield for a standard Esp32-Cam board that adds a Micro-USB port. You just need to plug your board into the shield.

Once paired, as in the photo above, you only need a USB-micro-to-USB-A cable to connect to your PC or Mac and upload the code. That’s it. Easy, right?

You can buy either the MB shield alone or the kit, which includes the Esp32-Cam and the MB shield. To connect to your computer, you’ll need a micro USB cable.

Back to Contents

Advertisement
Advertisement
5
Esp32-Cam with Arduino IDE: The Basics

Esp32-Cam CH340

The Esp32-Cam CH340
The Esp32-Cam CH340 (Source: Amazon)

The Esp32-Cam CH340 is the only Esp32-Cam version with an integrated serial port – the only con (if it even is one) is that the board is 8 mm longer, which may not be an issue for some. While the Esp32-Cam CH340 has a size of 27 mm x 48.5 mm x 4.5 mm, the standard Esp32-Cam is 27 mm x 40.5 mm x 4.5 mm.

The CH340’s chip is used to provide USB connectivity directly on the board, and perhaps the most important thing is you needn’t use a cable, a programmer, an Arduino board, or a shield!

Now that we’ve gone over different ways to connect your Esp32-Cam physically to your computer, let’s go over how to work on it with the Arduino IDE.

Back to Contents

Advertisement
Advertisement
Esp32-Cam with Arduino IDE: The Basics

Simple Steps to Start

The Arduino options
The Arduino options (Source: Luca Dinale via All3DP)

As mentioned, the Esp32-Cam from AI-Thinker comes with no built-in USB programmer, so we need to use some of its pins to give power, upload programs, and communicate with the board. This can be done in a few different ways, and we’ll look at how to use the Esp32-Cam with Arduino IDE.

While there’s a new version of Arduino IDE (Arduino IDE 2), it’s still a release candidate version. You can choose to go safe with the Arduino IDE 1 or try the new Arduino IDE 2 and, if you’re the adventurous kind, you can even choose to download a preview of the upcoming release with the most recent features and bugfixes.

Installing the Esp32 Library

  1. Download and install the version of your choice:
  2. Once it’s running, go to “Menu Arduino IDE > Preferences > Settings > Additional board manager URLs”. Add “https://dl.espressif.com/dl/package_esp32_index.json” and click OK.
  3. Restart Arduino IDE and connect your board to a USB port.
  4. Install the Esp32 library by going to “Tools > Board > Boards Manager > Search for Esp32 > Install Esp32 from Espressif Systems”.
  5. Select the right board: “Tools > Board > ESP32 Arduino > AI Thinker ESP32-CAM”.
  6. Select the right port by going to “Tools > Port” and then selecting your serial port (it depends on your operating system).

Now you’re ready to write your first sketch and upload it to the Esp32-Cam!

You can find the differences between Version 1 and Version 2 of Arduino IDE on Arduino.cc documentation: “The new Remote Sketchbook integration, released in July 2021, is a ground-breaking feature that allows you to synchronize your Arduino Cloud Sketchbook to your local computer”.

Syncing Arduino IDE 2 & the Web Editor

  1. Go to Arduino Cloud.
  2. Choose “Get Started for Free” and create your account or sign in with Google, Facebook, or Apple.
  3. Click on Create and choose to start the Web Editor.
  4. Download and install Arduino Create Agent.
  5. Start the Web Editor, choose the board and port (as mentioned in 5.1 and 5.2), and you’re ready to go.

If you create a sketch in the web editor and then go back to Arduino IDE 2.0 on your computer, in the Menu choice Arduino IDE/Advanced, activate Show/Hide Remote Sketchbook and small cloud icons will appear to Push or Pull your sketch. This means that you can choose your preferred version from IDE and “push” it to the Arduino Cloud, or choose the Cloud version and “pull” it to Arduino IDE.

Finally, let’s look at how to set up your Esp32-Cam with OTA in case none of the previous options work for you.

Back to Contents

Advertisement
Advertisement
Esp32-Cam with Arduino IDE: The Basics

Over the Air

Image of: Over the Air
No physical connection? No problem (Source: IoT Design Pro)

Perhaps a physical connection won’t cut it and you need a remote setup. Maybe you have a lot of devices running the same software or it might be difficult to make a physical connection to your board. Over-the-air (OTA) or Firmware-over-the-air (FOTA) updates come to the rescue.

There are many ways to implement OTA on generic Esp32s, but as the scope of this article is to give you the basics, we’ll concentrate on basic-over-the-air.

As of this writing, Basic OTA only works with Arduino IDE 1; an issue has been opened in the Arduino IDE GitHub repository about Arduino IDE 2 not working properly.

So, to implement Basic OTA, start Arduino IDE 1 and follow these steps:

  1. Check if the Esp32 board’s library is installed (see points 2 and 3 of “Install Esp32 Library in “5 + 5 Simple Steps to Start”).
  2. Choose your board as follows: “Tools > Board > ESP32 Arduino > ESP32 Wrover Module” (not ESP32-Cam).
  3. Set the following parameters under “Tools”:
    • Upload Speed: 115200
    • Flash Frequency: 80 MHz
    • Flash Mode: QIO
    • Partition Scheme: Minimal SPIFFS
    • Core Debug Level: Debug (it can be helpful)
    • Port: Choose the proper serial port
  4. Under the Examples folder, there’s the Basic OTA example file: “Examples > ESP32 Wrover Module > Examples for Arduino OTA > BasicOTA”
  5. Add your Wi-Fi SSID and password, and save the sketch.
  6. Upload the sketch to your Esp32-Cam, then open “Tools > Serial Monitor”. The last message should read something along the lines of: “begin(): OTA server at: esp32-4417937c9080.local:3232”, where 4417937c9080 is the MAC address of your Esp32-Cam board.
  7. After that, you can choose the network ports that will appear in the “Tools > Port” menu.

To use OTA in your sketch, you need to keep the basicOTA structure and just add your code in the 4 basic sections of an Arduino sketch:

  • The comment section
  • The variables section
  • The setup section
  • The loop section

Happy OTA upload!

Back to Contents

Advertisement
Advertisement

License: The text of "How to Use the Esp32-Cam with Arduino IDE" by All3DP is licensed under a Creative Commons Attribution 4.0 International License.

CERTAIN CONTENT THAT APPEARS ON THIS SITE COMES FROM AMAZON. THIS CONTENT IS PROVIDED ‘AS IS’ AND IS SUBJECT TO CHANGE OR REMOVAL AT ANY TIME.

Stay informed with notifications from All3DP.

You get a notification when a new article is published.

You can’t subscribe to updates from All3DP. Learn more… Subscribe to updates

You can’t subscribe to updates from All3DP. Learn more…

Topics
Advertisement