ESP32-CAM Video Streaming and Face Recognition with Arduino IDE

This article is a quick getting started guide for the ESP32-CAM board. We’ll show you how to setup a video streaming web server with face recognition and detection in less than 5 minutes with Arduino IDE.

Note: in this tutorial we use the example from the arduino-esp32 library. This tutorial doesn’t cover how to modify the example.

Watch the Video Tutorial

You can watch the video tutorial or keep reading this page for the written instructions.

Parts Required

To follow this tutorial you need the following components:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Introducing the ESP32-CAM

The ESP32-CAM is a very small camera module with the ESP32-S chip that costs approximately $10. Besides the OV2640 camera, and several GPIOs to connect peripherals, it also features a microSD card slot that can be useful to store images taken with the camera or to store files to serve to clients.

The ESP32-CAM doesn’t come with a USB connector, so you need an FTDI programmer to upload code through the U0R and U0T pins (serial pins).

Features

Here is a list with the ESP32-CAM features:

This is our complete guide to program the ESP32 with Arduino IDE, including projects, tips, and tricks!  SIGN UP NOW »

This is our complete guide to program the ESP32 with Arduino IDE, including projects, tips, and tricks! SIGN UP NOW »

  • The smallest 802.11b/g/n Wi-Fi BT SoC module
  • Low power 32-bit CPU,can also serve the application processor
  • Up to 160MHz clock speed, summary computing power up to 600 DMIPS
  • Built-in 520 KB SRAM, external 4MPSRAM
  • Supports UART/SPI/I2C/PWM/ADC/DAC
  • Support OV2640 and OV7670 cameras, built-in flash lamp
  • Support image WiFI upload
  • Support TF card
  • Supports multiple sleep modes
  • Embedded Lwip and FreeRTOS
  • Supports STA/AP/STA+AP operation mode
  • Support Smart Config/AirKiss technology
  • Support for serial port local and remote firmware upgrades (FOTA)

Pinout

The following figure shows the ESP32-CAM pinout.

Video Streaming Server

Follow the next steps to build a video streaming web server with the ESP32-CAM that you can access on your local network.

1. Install the ESP32 add-on

In this example, we use Arduino IDE to program the ESP32-CAM board. So, you need to have Arduino IDE installed as well as the ESP32 add-on. Follow one of the next tutorials to install the ESP32 add-on, if you haven’t already:

2. CameraWebServer Example Code

In your Arduino IDE, go to File > Examples > ESP32 > Camera and open the CameraWebServer example.

The following code should load.

If you can’t find the code in your Arduino IDE, you can download it from our GitHub repository. After downloading, unzip the folder, and open the CameraWebServer.ino file.

Before uploading the code, you need to insert your network credentials in the following variables:

const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

Then, make sure you select the right camera module. In this case, we’re using the AI-THINKER Model.

So, comment all the other models and uncomment this one:

#define CAMERA_MODEL_AI_THINKER

Now, the code is ready to be uploaded to your ESP32

Uploading the Code

Connect the ESP32-CAM board to your computer using an FTDI programmer. Follow the next schematic diagram:

Download our Free eBooks and Resources

Important: GPIO 0 needs to be connected to GND so that you’re able to upload code.

To upload the code, follow the next steps:

  1. Go to Tools > Board and select ESP32 Wrover Module
  2. Go to Tools > Port and select the COM port the ESP32 is connected to
  3. In Tools > Partition Scheme, select “Huge APP (3MB No OTA)
  4. Then, click the upload button to upload the code.

Important: if you can’t upload the code, double-check that GPIO 0 is connected to GNDs and that you selected the right settings in the Tools menu. You should also press the on-board Reset button to restart your ESP32 in flashing mode.

Getting the IP address

After uploading the code, disconnect GPIO 0 from GND.

Open the Serial Monitor at a baud rate of 115200. Press the ESP32-CAM on-board Reset button.

The ESP32 IP address should be printed in the Serial Monitor.

Accessing the Video Streaming Server

Now, you can access your camera streaming server on your local network. Open a browser and type the ESP32-CAM IP address. Press the Start Streaming button to start video streaming.

You also have the option to take photos by clicking the Get Still button. Unfortunately, this example doesn’t save the photos, but you can modify it to use the on board microSD Card to store the captured photos.

There are also several camera settings that you can play with to adjust the image settings.

Finally, you can do face recognition and detection.

First, you need to enroll a new face. It will make several attempts to save the face. After enrolling a new user, it should detect the face later on (subject 0).

And that’s it. Now you have your video streaming web server up and running with face detection and recognition with the example from the library.

Wrapping Up

The ESP32-CAM provides an inexpensive way to build more advanced home automation projects that feature video, taking photos, and face recognition.

In this tutorial we’ve tested the CameraWebServer example to test the camera functionalities. Now, the idea is to modify the example or write a completely new code to build other projects. For example, take photos and save them to the microSD card when motion is detected, integrate video streaming in your home automation platform (like Node-RED or Home Assistant), and much more.

We hope you’ve find this tutorial useful. If you don’t have an ESP32-CAM yet, you can grab it here.

If you like this project, you may also like other projects about cameras:

Learn more about ESP32: Learn ESP32 with Arduino IDE (video course and ebook).


Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »


Enjoyed this project? Stay updated by subscribing our weekly newsletter!

32 thoughts on “ESP32-CAM Video Streaming and Face Recognition with Arduino IDE”

  1. TF card 4GB limit. Will larger capacity cards, i.e. 8GB work, but only 4GB will be usable? Smaller cards are getting harder to find. FAT-16 format required?

    • Hi Bruce.
      I haven’t tested with 8GB sd cards. I’ll need to check if those work too.
      It needs to beet FAT-32 format.
      Regards,
      Sara

  2. Thanks very much for this ESP32-CAM project, I am looking forward to learning the camera applications, it is my first.
    Unfortunatly I am getting the following error returned to the serial monitor after reset:

    SCCB_Write [ff]=01 failed
    SCCB_Write [12]=80 failed
    [E][camera.c:1085] esp_camera_init(): Camera probe failed with error 0x20001
    Camera init failed with error 0x20001

    I have updated the arduino IDE to 1.8.9 and ESP32 boards as per instructions, but cant find the problem. If you have any ideas I really appriecate it.

    • Hi James.
      Did you select the right camera module in the code?
      Please double check that your camera is well connected to the board.
      I also found this issue: github.com/espressif/esp32-camera/issues/5
      It seems the same as yours, so it might help.
      Regards,
      Sara

      • Hi Dan, yes I took Sara’s advice and selected the correct camera module in the code but commenting out the ones that don’t apply. I did also find reducing the upload speed made things more stable. I think my programmer is not the best.
        Very happy it works very well. Thanks again

  3. Hi. Great tutorial; worked like a charm once used a separate 5V supply.

    Any way you know of to see the video stream or stills via a TFT display on another ESP through web browser or otherwise? I’ve used ESPNow between ESP12’s or 32’s for display of thermal cam images but they’re much smaller. Avoids need for phone or laptop tied up….
    Thanks
    Mel

  4. Hi, thanks for the tutorial, but I’m getting 2 problems with the code :

    1. I can’t include the zip file through “Add .ZIP library” from Arduino IDE

    2. When I put it manually through extracting the zip file and moved it to my Arduino libraries folder, then compile the code, I got “no headers files (.h) found” error

    Any help would be appreciated, thanks again for the tutorial.

    • Hi Mario.
      You don’t need to install any library. You just need to have the ESP32 add-on installed.
      The zip file that we provide contains all the code that you need.
      You just need to unzip the file, open the CameraWebServer folder and open the CameraWebServer.ino.
      Your arduino IDE should open the code and you’ll see three tabs at the top. Then, you just need to upload the code to your board.
      Alternatively, if you have the latest updated ESP32 add-on, you should have the code in your examples. Go to File > Examples > ESP32 > Camera and open the CameraWebServer example.
      I hope this helps.
      Regards,
      Sara

  5. I was looking for something like this for my recent project, Thanks! Great tutorial! But I think ESP32-CAM is “unofficial” combination of ESP32 with a camera. I think Espressif themselves released a dedicated “official” ESP32+camera board called ESP-EYE with their own “official” software library called ESP-WHO.

    Well I got all the information from here: https://www.ebay.com/itm/254177708782

    Have not tried that board myself. Can you make a tutorial on that as well since that is the “official” hardware and software and would have longer support from Espressif itself.

    Also a comparison between the 2 would be great too.

    I follow a lot of Random Nerd Tutorials. You guys make easy to follow guides. Cheers! Keep it up!

    Thanks!

    • Hi Ryan.
      Thank you for your nice words.
      The ESP-EYE is an Espressif release.
      We haven’t fully tested the ESP-EYE yet. We’ve played with the example firmware that they provide and we made a blog post about it that you can read here: https://makeradvisor.com/esp-eye-new-esp32-based-board/
      At the moment, we don’t have any more tutorials with the ESP-EYE.
      Thank you for your interest in our content.
      Regards,
      Sara

  6. Brownout detector was triggered

    ets Jun 8 2016 00:22:57

    rst:0xc (SW_CPU_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:1100
    load:0x40078000,len:10088
    load:0x40080400,len:6380
    entry 0x400806a4

    What happened? ¿Qué ocurre? Thx

  7. Greetings and congratulations for the tutorial. You are a very nice couple.
    Is it possible to take this captured image to a server on the internet?
    Can I have this camera in my house and see what happens from my work?

    Thank you.

  8. Hi Rui & Sarah,
    How do you set up face recognition ?
    I have the whole thing working as expected, however the Enroll face button does nothing ?

  9. Hi Guys,
    I purchased two units and both fail with the following:

    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:1100
    load:0x40078000,len:10088
    load:0x40080400,len:6380
    entry 0x400806a4
    [D][esp32-hal-psram.c:47] psramInit(): PSRAM enabled

    [E][camera.c:1085] esp_camera_init(): Camera probe failed with error 0x20001
    Camera init failed with error 0x20001
    I’ve selected AI Thinker in the code and reduced the upload to 115200. Anyone have some insights? I have a M5Stack Camera which works pretty well with the code but these two are dead.
    Thanks
    Dan

  10. Hi! good tutorial!, I need to put the upload speed 115200 and the flash frequency in 40Mhz to avoid a Guru Meditation Error: Core 0 panic’ed (InstrFetchProhibited) error if someone have the same problem 🙂

  11. I am having problems getting errors: camera_probe(): Detected camera not supported.
    esp_camera_init(): Camera probe failed with error 0x20003.

    That occurs selecting AI Thinker. The other two options give me the 0x20001 error. I bought the esp camera from DIYMORE.CC. The description in their ad prints AI Thinker on the chip, but my actual device does not have AI Thinker printed. It just has DM-ESP32-S.

    Any ideas?

  12. Thanks Great Job
    But i have almost the same problem as Neil.
    face recognition works very bad i get almost no yellow square
    how to ficks that?

    • Hi.
      Face recognition is a bit slow, however we managed to make it work fine.
      Please make sure that you have proper lighting to make the face recognition process easier and more efficient. Also, when enrolling a new face, you need to be steady and don’t move much, so that it properly saves your face features and can recognize it in the future.
      Regards,
      Sara

  13. Hi,
    Got my hardware last week from banggood. It had the issue “Brownout detector was triggered”. Seaching the web i found this video where they say to feed by 5v not 3.3v.
    https://www.youtube.com/watch?v=tzmcXZ-irIc ~2:30
    This solved the brownout issue for me.
    Then the web service did not appear in google chrome browser. Error message was something about too much header lines or so. In MS Edge it was ok. But i have no image from the cam. Cam must be broken. So i have to wait another month to get this as spare part. Have also ordered another ESP board with an external antenna hoping to get better connection to the router.

    • Hi Patrick.
      I’m sorry you’re getting trouble using your ESP32-CAM.
      The brownout detector error usually means that the ESP32 is not being powered properly. You can read more about this on our troubleshooting guide, bullet 8: https://randomnerdtutorials.com/esp32-troubleshooting-guide/
      Our camera worked flawlessly following the steps we describe in our tutorial.
      The ESP32-CAM should work fine being powered either with 3.3V through the 3.3V pin or 5V through the 5V pin. You’re probably not providing enough current.
      Also, we didn’t have any trouble accessing the web server on Google Chrome.
      After you get a new camera, let us know how it went.
      Regards,
      Sara

  14. Any ideas what would cause a 20003 error? I have tried all three camera types. The AI Thinker gives 20003. The other two cause a 20001 error

    • Hi John.
      I’m sorry you’re having that issue.
      Those errors usually mean that the camera is not properly connected. So, or your camera module is faulty or it is not properly connected.
      If these are not the reasons, it is very difficult for us to understand what is going on.
      Can you try using a new camera probe?
      Regards,
      Sara

  15. Thanks. The camera came installed. I bought 2 of them, and they both fail. I decided to buy from another source and see if that works.

    I am not sure what you are referring to regarding a new camera probe.

  16. Dear ALL

    ESP32 doesn´t connect with mit Network and no text in Serial Monitor is being printed. SID and PW changed in coding. Any Ideas?
    Message in Arduino 1.8.8:

    Der Sketch verwendet 2233514 Bytes (71%) des Programmspeicherplatzes. Das Maximum sind 3145728 Bytes.
    Globale Variablen verwenden 50692 Bytes (15%) des dynamischen Speichers, 276988 Bytes für lokale Variablen verbleiben. Das Maximum sind 327680 Bytes.
    esptool.py v2.6-beta1
    Serial port COM9
    Connecting…….
    Chip is ESP32D0WDQ6 (revision 1)
    Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
    MAC: cc:50:e3:b6:e5:90
    Uploading stub…
    Running stub…
    Stub running…
    Configuring flash size…
    Auto-detected Flash size: 4MB
    Compressed 8192 bytes to 47…

    Writing at 0x0000e000… (100 %)
    Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 4096.1 kbit/s)…
    Hash of data verified.
    Compressed 17664 bytes to 11528…

    Writing at 0x00001000… (100 %)
    Wrote 17664 bytes (11528 compressed) at 0x00001000 in 1.0 seconds (effective 138.4 kbit/s)…
    Hash of data verified.
    Compressed 2233680 bytes to 1788374…

    Wrote 2233680 bytes (1788374 compressed) at 0x00010000 in 158.5 seconds (effective 112.7 kbit/s)…
    Hash of data verified.
    Compressed 3072 bytes to 134…

    Writing at 0x00008000… (100 %)
    Wrote 3072 bytes (134 compressed) at 0x00008000 in 0.0 seconds (effective 768.0 kbit/s)…
    Hash of data verified.

    Leaving…
    Hard resetting via RTS pin…

    • Hi.
      It seems that your code was uploaded successfully.
      Make sure you open the serial monitor at a baud rate of 115200, so that you can see the text on the serial monitor.
      After uploading the code, you should disconnect GPIO from GND. Open the Serial monitor, and then press the ESP on-board reset button.
      Please make sure you’ve inserted the right network credentials.
      Can you access the web server when you insert the IP address on your browser?
      Regards,
      Sara

  17. Dear Sara,
    may I ask you please to advise on the issue below.
    I purchased an AI Thinker, but it is not printed on the chip.
    This product contains the OV2640 Camera Module.

    Can you please advise on which Camera Model to use?
    The use of #define CAMERA_MODEL_AI_THINKER refers to the error. Also the other led to issues.

    Thanks

    Brownout detector was triggered

    ets Jun 8 2016 00:22:57

    rst:0xc (SW_CPU_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:1100
    load:0x40078000,len:9232
    load:0x40080400,len:6400
    entry 0x400806a8

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

Leave a Comment

Download our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.