ESP32-CAM - Getting Started & Solving Common Problems (2024)

Table of Contents

  • 1 Introduction
  • 2 Examining the ESP32-CAM
    • 2.1 ESP32-CAM Specifications
    • 2.2 Camera Specifications
  • 3 Working with the ESP32-Cam
    • 3.1 Hooking up the FTDI Adapter
    • 3.2 Programming with the Arduino IDE
    • 3.3 Loading the Sample Sketch
    • 3.4 Testing the ESP32-CAM
  • 4 Resolving ESP32-CAM Power Issues
    • 4.1 Using an Active USB Hub
    • 4.2 Using a 5-volt Power Supply
  • 5 Using an External Antenna
    • 5.1 Selecting an External Antenna
    • 5.2 Modifying the ESP32-CAM for External Antenna
    • 5.3 Antenna Test Sketch
  • 6 Conclusion
    • 6.1 Parts List
    • 6.2 Resources

ESP32-CAM - Getting Started & Solving Common Problems (1) ESP32-CAM - Getting Started & Solving Common Problems (3)

We have worked with the ESP32 module already, it’s a powerful yet inexpensive microcontroller from Espressif and A-Thinker with advanced features like Bluetooth, WiFi, and multipurpose GPIO ports.

Today we’ll look at another member of the ESP32 module family, the ESP32-CAM board.

This amazing little module packs a lot of power and features into a small package. Read on and see how you can put it to use.

Introduction

The ESP32-CAM is a full-featured microcontroller that also has an integrated video camera and microSD card socket. It’s inexpensive and easy to use, and is perfect for IoT devices requiring a camera with advanced functions like image tracking and recognition.

ESP32-CAM - Getting Started & Solving Common Problems (5)

The sample software distributed by Espressif includes a sketch that allows you to build a web-based camera with a sophisticated control panel. After you get the hang of programming the device you’ll find that it is very easy to use.

Not bad for a board that costs about ten dollars, including the camera!

Examining the ESP32-CAM

The ESP32-CAM module has fewer I/O pins than the previous ESP-32 module we looked at. Many of the GPIO pins are used internally for the camera and the microSD card port.

Another thing missing from the ESP32-CAM module is a USB port. In order to program this device you’ll need to make use of an FTDI adapter. This will be described further on in this article.

Here is the pinout of the ESP32-CAM Module:

ESP32-CAM - Getting Started & Solving Common Problems (6)

One thing to note about this module is that it has components on both sides of the printed circuit board. The “top” of the board has the connector for the camera module, as well as the microSD (sometimes called “TF”) card socket.

ESP32-CAM - Getting Started & Solving Common Problems (7)

You’ll also note a square white LED on the top of the module, this can act as a “flash” for illuminating the subject you are trying to view with the camera.

The underside of the circuit board has the ESP32-S module. It also has a connector for an external antenna, as well as an internal antenna that is etched onto the circuit board. I’ll explain how to use the external antenna shortly.

ESP32-CAM - Getting Started & Solving Common Problems (8)

Another key component located underneath the board is the reset switch.

Because there are so many components on the bottom of the module you may find it easier not to use a solderless breadboard when experimenting with the ESP32-CAM module. The use of jumpers with female Dupont connectors is recommended.

ESP32-CAM Specifications

The ESP32-CAM is based upon the ESP32-S module, so it shares the same specifications. It has the following features:

  • 802.11b/g/n Wi-Fi
  • Bluetooth 4.2 with BLE
  • UART, SPI, I2C and PWM interfaces
  • Clock speed up to 160 MHz
  • Computing power up to 600 DMIPS
  • 520 KB SRAM plus 4 MB PSRAM
  • Supports WiFi Image Upload
  • Multiple Sleep modes
  • Firmware Over the Air (FOTA) upgrades possible
  • 9 GPIO ports
  • Built-in Flash LED

Camera Specifications

The ESP32-CAM includes an OV2640 camera module. The device also supports OV7670 cameras. The OV2640 has the following specifications:

  • 2 Megapixel sensor
  • Array size UXGA 1622×1200
  • Output formats include YUV422, YUV420, RGB565, RGB555 and 8-bit compressed data
  • Image transfer rate of 15 to 60 fps

Working with the ESP32-Cam

Using the ESP32-CAM is similar to using the ESP32 modules we looked at previously, with one major difference. The ESP32-CAM board has no USB port, so you can’t just connect it up to your computer and start loading programs.

Instead you will need to add an external FTDI adapter. This is the same adapter you would use programming an Arduino Pro Mini, so if you’ve worked with the Pro Mini then you probably already have one of these.

Hooking up the FTDI Adapter

Here is the hookup diagram for connecting the FTDI adapter to the ESP32-CAM module:

ESP32-CAM - Getting Started & Solving Common Problems (9)

It is important to note that the FTDI adapter must be set for a 3.3-volt VCC output, not 5-volts, as we are powering the ESP32-CAM using the 3.3-volt power pin. You could also keep the FTDI adapter at 5-volts and use the 5-volt power pin instead.

I have found the 3.3-volt set up to be more reliable, which is why I am recommending it.

You’ll also need to note that there is a connection between the GPIO 0 pin and Ground. This connection is only required while you are programming the ESP32-CAM. Once you have finished programming the module you can power it down and remove this connection.

ESP32-CAM - Getting Started & Solving Common Problems (10)

As you’ll require access to the Reset push button you may want to use female-to-female Dupont jumpers, instead of a solderless breadboard, when working with the ESP32-CAM.

Programming with the Arduino IDE

In order to use the ESP32-CAM, or any ESP32, with the Arduino IDE you will need to use the Board Manager to add the ESP32 boards. This is accomplished by adding a JSON file link to your Arduino IDE Preferences “Additional Boards URL” text box.

ESP32-CAM - Getting Started & Solving Common Problems (11)

Complete details for doing this can be found in the Getting Started with ESP32 article.

Once you have done this you will find a list of ESP32 boards in your Arduino IDE Boards Manager. Select the A-Thinker ESP32-CAM board from this list.

Loading the Sample Sketch

After you select the A-Thinker ESP32-CAM board you will have a number of example sketches loaded into your Arduino IDE.

The sample sketch we will be using is the CameraWebServer sketch. You can load it as follows:

  • Open the Arduino IDE
  • Click on the File menu item on the top menu bar.
  • Scroll down and click on Examples. A sub-menu will open.
  • Scroll down the sub-menu and look for Examples for A-Thinker ESP32-CAM.
  • Below this you’ll see an entry for ESP32. Click on it and another sub-menu will open.
  • Select Camera from this sub-menu.
  • Select CameraWebServer

The CameraWebServer sketch is very complicated and consists of four files, so I won’t go over the details here.

The sketch turns the ESPO32-CAM into a full-featured online camera, complete with face detection capabilities and a wealth of controls. It’s a very impressive demonstration of the ESP32-CAMs capabilities!

Before you can use the sketch you will need to modify it for your network, and to select the correct ESP32 module.

  • Under the lines saying Select Camera Model you need to select the correct entry for your board. The one I used (and the most popular one) is CAMERA_MODEL_AI_THINKER
  • Below that you will see a line for your SSID. Enter your networks SSID here.
  • On the line below the SSID enter your network access password.

Note that the ESP32-CAM only works with 2.4 GHz WiFi networks.

Save the sketch after you modify it.

Testing the ESP32-CAM

Load the sketch into your IDE and press the Upload button to compile and load it to the ESP32-CAM, via the FTDI connector. Be sure you have the jumper connected between GPIO 0 and Ground.

The sketch may take a while to compile, this is normal. When it is finished you can disconnect the USB cable, remove the jumper wire, and then reconnect the USB cable to power the board back up again.

Open your Serial Monitor, making sure it is set to a baud rate of 115,200 bps. Then press the Reset switch on the ESP32-CAM module.

You should see some initialization information, followed by a statement saying that the board has connected to the network and has obtained an IP address. The IP address will be in the form of a URL, such as http://192.168.1.67 (this is just an example URL, yours will be different)

Copy this address and then paste it into the address bar of a web browser. The web browser needs to be on the same network as the ESP32-CAM is connected to.

ESP32-CAM - Getting Started & Solving Common Problems (12)

You should now see the webpage for the camera, complete with a number of controls.

Click on the Start Stream button to stream video. You can change the size and frame rate of the video using the drop-down at the top of the screen.

Experiment with the many features of the Camera Web Server, and try to remember that this is all coming from a 10-dollar module!

Resolving ESP32-CAM Power Issues

If you have problems getting the ESP32-CAM to work the first thing you’ll want to investigate is the power supply. This is also true with other ESP32 modules.

Although the ESP32 can operate at a very low standby current it also consumes large bursts of current when operating its radio, and this can affect both WiFi and Bluetooth performance.

One way to determine if you have a power issue is to observe the Serial Monitor when starting your ESP32-CAM. If you see a message saying a “Brownout Condition” has been detected then it’s likely that the ESP32-CAM is trying to draw more current than you’re able to supply for it.

There are a few ways to get around this issue.

Using an Active USB Hub

The FTDI module that supplies power and communications for the ESP32-CAM gets its power from the USB cable connected to it. The power source here is your computer.

Most USB2 computer ports do have enough current capability to satisfy the requirements of the ESP32-CAM, but some do not.

Another factor can be the length and quality of the USB cable. These cables use very thin wire, and sometimes the voltage drop is pretty significant. Often you can resolve the brownout issue by simply replacing the cable.

Another way, and one that worked for me in the workshop, is to use a powered USB hub. This allows you to place the hub close to the ESP32-CAM and use a shorter USB cable to drive the FTDI adapter.

ESP32-CAM - Getting Started & Solving Common Problems (13)

A USB2 hub is sufficient, it doesn’t need to be USB3. The hub allows the communications signals to pass through to the FTDI adapter while powering it from its own power supply.

It is important to use a POWERED hub here, as using a passive USB hub just defeats the purpose and would probably make things worse!

Using a 5-volt Power Supply

Another way to resolve the brownout condition is to power the ESP32-CAM with the 5-volt power pin, instead of the 3.3-volt pin.

If you are using the FTDI adapter and are having issues running the ESP32-CAM try switching the power to 5-volts and using the 5-volt power pin.

Oddly enough I found that the ESP32-CAM seems to RUN better with 5-volts, but it is easier to PROGRAM using 3.3-volts! This might be unique to my setup, however, so I urge you to experiment.

ESP32-CAM - Getting Started & Solving Common Problems (14)

The above image shows an ESP32-CAM on a solderless breadboard with a 5-volt breadboard power supply. The ESP32-CAM was already programmed using female-to-female jumper cables and 3.3-volts.

The breadboard power supply is powered by a standard 9-volt battery, allowing for a portable setup.

One issue with mounting the module on a breadboard is it prevents easy access to the reset switch, however, you can access the switch from the front using a toothpick or other insulated object.

Using an External Antenna

Another problem you might encounter using the ESP32-CAM is WiFi Signal strength.

The ESP32-CAM has an antenna etched on its printed circuit board. The specification sheet from A-Thinker claims a gain of 2.1dBi for the onboard antenna.

If you are in close proximity to your router or WiFi access point this should be sufficient, however as you move the module further from the signal source you can experience dropouts or loss of signal.

The solution for this is to add an external antenna.

Selecting an External Antenna

There are many different external antennas that would be suitable for use with the ESP32-CAM. The requirements for the external antenna are as follows:

  • It needs to work in the 2.4GHz band.
  • It needs to have a U.FL or IPEX MHF or MHF1 connector.

Otherwise you can use either a flexible “stick-on” or a dipole antenna.

ESP32-CAM - Getting Started & Solving Common Problems (15)

Using the antenna is not just simply a matter of plugging it into the socket however. You will need to make a modification to the ESP32-CAM board, and this will require a bit of soldering. So heat up your soldering iron and follow these instructions.

Modifying the ESP32-CAM for External Antenna

The ESP32 board has a small antenna connection on the bottom of the module, very close to the built-in antenna.

Next to the antenna connector, and between the built-in antenna and the metal case of the ESP32S module, are a trio of solder pads. There is a 0-ohm (yes, you read that correctly) resistor across two of the pads, as illustrated here:

ESP32-CAM - Getting Started & Solving Common Problems (16)

In the above diagram you can see the position of this resistor when using the internal antenna.

To use the external antenna you need to remove the resistor and place it in the gap between the bottom pads, as illustrated here:

ESP32-CAM - Getting Started & Solving Common Problems (17)

The surface-mount resistor can be difficult to work with, especially if you are unaccustomed to working with SMD components. But as this is a 0-ohm resistor you can just use a small piece of wire instead, in fact that’s what I did and it worked fine.

Note that you can’t put a wire there and keep the original resistor, you can only use one antenna at a time.

After you have modified the board you can install the external antenna.

Antenna Test Sketch

Here is a simple sketch that you can use to test the antenna performance, you can use it with both the internal or external antenna.

ESP32 Antenna Test

C++

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

/*

ESP32 WiFi Signal Test

esp32-wifi-signal-test.ino

Tests WiFi signal strength

*Requires WiFi SSID and Password

DroneBot Workshop 2020

https://dronebotworkshop.com

*/

// Include WiFi library

#include "WiFi.h"

// SSID and Password - modify for your WiFi network

const char* ssid = "REPLACE_WITH_YOUR_SSID";

const char* password = "REPLACE_WITH_YOUR_PASSWORD";

void setup(){

// Setup serial monitor

Serial.begin(115200);

// Start WiFi and conect to network

WiFi.begin(ssid, password);

// Wait while connection established

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print("-");

}

// WiFi is connected

Serial.println("");

Serial.print("Connected to network ");

Serial.println(ssid);

delay(100);

}

void loop(){

Serial.print(ssid);

Serial.print(" Signal Level: ");

Serial.println(WiFi.RSSI());

delay(2000);

}

This is a very basic sketch and most of its functionality comes from the WiFi Library that Espressif installs with the ESP32 board manager.

You’ll need to modify this sketch with your SSID and WiFi password, just as you did for the CameraWebServer example sketch. These values are assigned to a couple of constants.

In the Setup the serial monitor is initialized and then an attempt is made to connect to the WiFi access point using the credentials you supplied.

Assuming you get a successful connection we move on to the Loop.

In the Loop we just use the WiFi library to read the signal strength and we then display this on the serial monitor. After a 2-second delay we do it all again.

ESP32-CAM - Getting Started & Solving Common Problems (18)

Load the sketch, remember to strap the GPIO 0 pin to ground while you are uploading the code. After that you can remove the jumper and hit the reset key.

You should observe the signal strength on your serial monitor.

In my case I found a substantial difference between the internal antenna and the external one. I was getting readings of about -60dBm with the internal antenna, and -48dBM or better with the external one, a major improvement.

Keep this sketch handy for testing out your other ESP32 installations.

Conclusion

The ESP32-CAM module is an amazing value. At less than 10 dollars you get a full-featured microcontroller that includes both a video camera and a microSD card socket.

The supplied example sketch may be all that you need in order to create a useful product with this device. Of course you can take it much further and create sketches to use this versatile module in a number of IoT projects.

I hope you enjoyed this article and that it inspires you to create your own camera-enabled devices. And if you run into issues with it there is an ESP32-ESP8266 section on the DroneBot Workshop Forums where you can discuss this with other enthusiasts like yourself.

Parts List

Here are some components that you might need to complete the experiments in this article. Please note that some of these links may be affiliate links, and the DroneBot Workshop may receive a commission on your purchases. This does not increase the cost to you and is a method of supporting this ad-free website.

COMING SOON!

Resources

Antenna Test Code – The Antenna level test code in a ZIP file.

Getting started with the ESP32-CAM

Related

Summary

ESP32-CAM - Getting Started & Solving Common Problems (19)

Article Name

Getting started with the ESP32-CAM

Description

The ESP32-CAM is an inexpensive microcontroller that comes with a built-in camera and microSD card interface - all for less than 10 dollars! In this article, I'll show you how to get started with the ESP32-CAM and use it to create a Camera Web Server. We'll also go over some troubleshooting tips you can use if you have problems getting your ESP32-CAM to work.

Author

DroneBot Workshop

Publisher Name

DroneBot Workshop

Publisher Logo

ESP32-CAM - Getting Started & Solving Common Problems (20)

ESP32-CAM - Getting Started & Solving Common Problems (2024)

FAQs

Why is my ESP32 CAM not working? ›

If you're powering your ESP32 through a USB port on your computer, it might not be supplying enough power. Some readers also reported this problem was solved by replacing their actual FTDI programmer with this one. If you get this error, it might also mean that your camera or the camera ribbon is broken.

What are the disadvantages of ESP32 CAM? ›

The disadvantages of ESP32 Cam include the following.
  • ESP32-CAM boards are expensive.
  • This board doesn't contain a USB-to-UART interface, so you cannot connect this board directly to your PC with a USB cable.
  • This board has a narrow field of view.
  • It doesn't have night vision ability.
  • Its length of cable is short.

Why is my ESP32 not working? ›

Check your USB cable and try a new one (some cables are only for charging and there is no data connection). Change the USB port - prefer direct connection to the computer and avoid USB hubs. Some USB ports may share the power source with other ports used, for example, for charging a phone. Check your power supply.

How do I know if my ESP32 CAM is working? ›

The ESP32-CAM module is typically designed to operate with a 5V power supply. You can connect a 5V voltage source to the 5V pin on the module, and it should work within this voltage range. However, you should not exceed this voltage, as doing so can damage the module.

Is ESP32 a security risk? ›

Security researchers have recently described a fault injection attack on ESP32, which may result in some security compromise and unintended disclosure of information. However, ESP32's security design remains safe for the vast majority of our products. Here's how.

What is the lifespan of ESP32? ›

In theory, there's nothing that wears down in the ESP32 itself. However, the flash chip in a module can lose its information over time. For instance, the GD25Q32 we use in our modules guarantees a flash lifetime of 20 years, minimum. The other thing that can wear down the flash is repeated erase cycles.

How long can ESP32-CAM run on battery? ›

Power consumption of 1µA is negligible in most situations. Neglecting voltage effects, a small 3.7V, 850mAh rechargeable battery would be able to power an ESP32 in modem-sleep for approximately 12.5 hours. Light-sleep could run for over 1000 hours.

What is the reset button on the ESP32? ›

As shown in Figure 1-1, the ESP32-DevKitC features two buttons: one marked as “EN”, which is the reset button and is located on the bottom left corner, and another one marked “Boot” on the bottom right corner, which is the download button.

Why ESP32 is not connecting to Wi-Fi? ›

Either the network is too far from the ESP32, or the name (SSID) of the network is incorrect. WL_CONNECT_FAILED : The ESP32 cannot connect to the designated WiFi network.

What is the difference between ESP32 and ESP32-CAM? ›

The main difference between the ESP32 and the ESP32-CAM is that the ESP32 is a Wi-Fi and Bluetooth chip with a dual core processor, while the ESP32-CAM is a Wi-Fi and Bluetooth chip with a single core processor and an onboard camera. Additionally, the ESP32-CAM has more memory and storage than the ESP32.

What can I do with ESP32-CAM? ›

It allows you to set up a video streaming web server, build a surveillance camera, take photos, face recognition and detection, and much more. We have several ESP32-CAM Tutorials and project ideas. You can also get our Build ESP32-CAM Projects eBook with more than 60 projects.

What is the easiest way to program ESP32? ›

Programming the ESP32: The different platforms and languages

For beginners, the most common and easiest way to program the ESP32 is to use the Arduino IDE software . Although it is intended for Arduino boards, we can use it to program other types of boards, thanks to the additional board manager.

Why ESP32 is not connecting to WiFi? ›

Either the network is too far from the ESP32, or the name (SSID) of the network is incorrect. WL_CONNECT_FAILED : The ESP32 cannot connect to the designated WiFi network.

How do I debug ESP32 CAM? ›

Program and Debug Your ESP32 CAM using VSCODE
  1. Create a New Project in VsCOde ESP-IDF.
  2. Download the ESP CAMera Driver.
  3. Copy an Example CamerA Code to your Project's Main file.
  4. Configure YOur Project to Use Your PSRAM.
  5. BUILD, FLASH, AND MONITOR YOUR ESP32 CAM PROJECT.
Jan 22, 2024

How do I connect my ESP32 CAM to ESP32? ›

Yes, you can connect an ESP32-CAM to an ESP32 board. To do so, you will need to use the camera module's gold-plated connector strip to connect it to the ESP32 board. You can then use a USB-to-Serial converter or an Arduino UNO along with the ESP32 to upload code to the ESP32-CAM module.

Can ESP32 CAM work without WiFi? ›

To connect an ESP32 camera module without WiFi, you will need to use a USB cable to connect it to your computer. Then, you can use a serial terminal program to communicate with the module and configure it to your desired settings.

Top Articles
Latest Posts
Article information

Author: Gov. Deandrea McKenzie

Last Updated:

Views: 5308

Rating: 4.6 / 5 (66 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Gov. Deandrea McKenzie

Birthday: 2001-01-17

Address: Suite 769 2454 Marsha Coves, Debbieton, MS 95002

Phone: +813077629322

Job: Real-Estate Executive

Hobby: Archery, Metal detecting, Kitesurfing, Genealogy, Kitesurfing, Calligraphy, Roller skating

Introduction: My name is Gov. Deandrea McKenzie, I am a spotless, clean, glamorous, sparkling, adventurous, nice, brainy person who loves writing and wants to share my knowledge and understanding with you.