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

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 Pinouts

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 Module - Top

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 Module - Bottom

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 FTDI Hookup

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 and FTDI Adapter

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 Add Board Manager JSON

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 Camera Web Server

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.

Powered USB Hub

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 on Breadboard

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 Antenna Connector

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 Antenna - Internal Strapping

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 Antenna - External Strapping

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.

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 with External Antenna

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.

 

Resources

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

 

Getting started with the ESP32-CAM
Summary
Getting started with the ESP32-CAM
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
Publisher Name
DroneBot Workshop
Publisher Logo

If you have a question...

Comments about this article are encouraged and appreciated. However, due to the large volume of comments that I receive, it may not be possible for me to answer you directly here on the website.

You are much more likely to get answers to technical questions by making a post on the DroneBot Workshop Forum. Your post will be seen not only by myself, but by a large group of tech enthusiasts who can quickly answer your question. You may also add code samples, images and videos to your forum posts.

Having said that, please feel free to leave constructive comments here. Your input is always welcome. Please note that all comments may be held for moderation.

29 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Phillip Neal
5 months ago

-60 to -48dbm.. Very nice.

George Pederson
5 months ago

I followed all the step step by step but my connection still runs out how can I make that last a bit longer because my Wi-Fi is slow
 
thans george

Dave
5 months ago

I found connecting a 330uF 16 volt electrolytic capacitor across the 5 volt input pins of this device cures all brownout and wifi disconnect issues 😉
Works for ESP8266 as well.

Luis
4 months ago

Oops. Hard coded UID and password. A shodan search, and OWNED. Badness.

aseem
4 months ago

hello sir i am having error —
[E][camera.c:1049] camera_probe(): Detected camera not supported.
[E][camera.c:1249] esp_camera_init(): Camera probe failed with error 0x20004
 
 

Last edited 4 months ago by aseem
Warren
4 months ago

Your figure showing connections has the jumper on 5v but the wiring is to 3v???

Sean
4 months ago

Having trouble with esp32 mac port disappears, on Ubuntu snap wont allow instal …disappointment and despairing , can some please help me ?

Stefan
4 months ago

Hello, thanks for this nice tutorial. Is it also possible to use I2C Sensors in Combination with this board? For example I would like to use the board in an area with no internet connection and save the pictures on the SD card. So I would need an external RTC to give the photos proper names according to the time.

Would be great if you can show if and how a I2c connection could be established.

Joe
3 months ago
Reply to  Stefan

Hello,
Great video. Would it be possible to post or provide the link for the sample sketch you used the CameraWebServer sketch?

Thanks,
Joe

tuvan
3 months ago
Reply to  Stefan

Hello,
Did anyone answer to the problem of I2C connection to ESP32-Cam? I have problems too.

erock999
2 months ago
Reply to  Stefan
terapong
4 months ago

i have aht10 but it not work. i set i2c on gpio14, 15 help me

Deb Mohan
3 months ago

Thank you for your article. My ESP-32 Cam module refused to work and just like yours, I was able to make it work with 3.3V to upload the code and run with 5V. I have been going through some tutorials on ESP and your site helped me a bunch. I may create a YouTube video and link to your site. LMK if that would be ok with you.

shyam
3 months ago

Arduino: 1.8.10 (Windows 10), Board: “AI Thinker ESP32-CAM” Sketch uses 2100647 bytes (66%) of program storage space. Maximum is 3145728 bytes. Global variables use 53552 bytes (16%) of dynamic memory, leaving 274128 bytes for local variables. Maximum is 327680 bytes. esptool.py v2.6 Serial port COM8 Connecting… Traceback (most recent call last):  File “esptool.py”, line 2959, in <module>  File “esptool.py”, line 2952, in _main  File “esptool.py”, line 2653, in main  File “esptool.py”, line 460, in connect  File “esptool.py”, line 440, in _connect_attempt  File “esptool.py”, line 379, in sync  File “esptool.py”, line 322, in command  File “esptool.py”, line 285, in write  File… Read more »

Victor Ramamoorthy
3 months ago

Hello, I did everything as per your suggestion. I got the following error message:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8

[E][camera.c:1049] camera_probe(): Detected camera not supported.
[E][camera.c:1249] esp_camera_init(): Camera probe failed with error 0x20004

Can you help me? Do I have a wrong ESP32-Cam?

Thanks,
Victor

niranjan
2 months ago

cam not placed correctly.
you have selected wrong cam module…if ur using esp32-s,ov2640 cam select AI-Thinker model .

DaveC
2 months ago

Swap your FTDI to the 5v setting and power your ESP32 on the 5V pin instead of the 3.3v pin that camera error should go away… (if you put 5V into the 3.3v pin all of the smoke will fall out)

Nic
2 months ago

can u stream the video to a mobile phone via wifi direct? If there is no network access?

Marcio Lemos
1 month ago

Hi
I am running home assistant over a virtual machine in Windows. I can get the esp32 cam to connect to any browser but when I try to past the ip addess to the picture card on home assistant it shows a broken link icon. why Hassio is not reading the IP address correctly? Tried with a jpeg image from a public website address and it shows properly but there is no way I can make it accept the camera ip address.
Appreciate any help.
thanks

1 month ago

Its a shitty Website

ashamim
1 month ago

My esp32 cam is working both for streaming and snapshots. However, the picture quality is nowhere near as good as I see on this and other tutorials. Some details: I am using the camerawebserver example included with the library I’ve tried quality settings in the code from 0 down to 20. Doesnt really help. Camera crashes at a quality setting of about 4. The camera model is an OV2640-v2.0. AI-thinker Powered at 5V Wifi signal is fine. The board is 3 feet away from the wireless router. I have searched extensively online and I’ve seen only one discussion on this… Read more »

Alvaro
28 days ago
Reply to  ashamim

Have you find any solution? I’ve got the same problem and I’m starting to think about buying another one

Buscaglia
1 month ago

Hi,

When I uploaded the Antenna Test code in ESP32, there is no information or letter on serial port. After pressing reset button, arduino program shows only this string on screen :

ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x3 (DOWNLOAD_BOOT(UART0/UART1/SDIO_REI_REO_V2))
waiting for download

SergioAP
1 month ago

I’m using an arduino uno as a ttl to serial converter and uploading my code that way but as the arduino cant pass the required current I plugged some batteries to my esp32 cam in order for it to run succesfully but no matter what I do I Can’t get a serial output. Any advice?

1 month ago

Too easy, now I need a fixed IP address

Rune Bertil Johnson
1 month ago

Great instruction. But I get the following error.

[E][camera.c:1049] camera_probe(): Detected camera not supported.
[E][camera.c:1249] esp_camera_init(): Camera probe failed with error 0x20004

hernan palero
20 days ago

Hi
I brought an Esp32 Cam that is not AiThinker, but is similar.( the logo is the same that your fourth picture)
I follow the steps, and i connect it to power supply in breadboard because i had a “Brownout Condition” whit FTDI power.
Then, the camera work well, but when i go to streaming, the camera work until i move any thing trought the camer, the module go to freeze and i must to reset for working again.
Any suggest?
thanks

Luca
6 days ago

hi everyone, I am having problems in running even the wifi signal test to check the strength of the wifi. Unfortunately I get always the same error: A fatal error occurred: failed to connect esp32: invalid head of packet. Moreover, few times, I got also the message: failed to execute script tool serial port does not exist. I have tried to power the esp cam from an external source at 5V, but still same error. In many forum, I got the advice to use a high quality USB cable, but, what does high quality USB cable mean? I think the… Read more »

Last edited 6 days ago by Luca
Tan Lip Seong
5 days ago

Tq for the great Workshop.

29
0
Would love your thoughts, please comment.x
()
x