Getting Started & Solving Common Problems

26 Mar.,2024

 

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.

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:

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.

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.

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:

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.

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.

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.

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.

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.

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.

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:

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:

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

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.

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

Summary

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