Introduction: ESP32-CAM Video Streaming, Face Recognition Using Arduino IDE

This article is a short introduction to the ESP32-CAM motherboard. We'll guide you through how to create a web server using facial recognition and detection in under 5 minutes using Arduino IDE.


The ESP32 camera is a compact camera module that comes with the ESP32-S chipset that is priced at around $10. Apart from the OV2640 camera and a variety of GPIOs for connecting peripherals, it also comes with an SD card slot which could be used for storing images taken by the camera, or to store files for clients to use.

The ESP32-CAM isn't equipped with a USB connector, therefore you'll require an FTDI programmer to upload the code through the U0R or U0T connectors (serial pins).

Supplies

Step 1: Features

Here is a listing of the features of ESP32-CAM:

  • The tiniest 802.11b/g/n Wi-Fi Bluetooth SoC module
  • Low power 32-bit CPU, which can be used by the application processor
  • Up to 160MHz of clock speed, the summative computing power of up to 600 DMIPS
  • Built-in 520 KB SRAM external 4MPSRAM
  • Supports UART/SPI/I2C/PWM/ADC/DAC
  • Support for OV2640 as well as OV7670 cameras, with built-in flash lamp
  • Support image WiFI upload
  • Support for TF card
  • Supports different sleep modes.
  • embedded Lwip and FreeRTOS
  • Operation mode STA/AP/STA+AP is supported.
  • Support for Smart Config/AirKiss technology.
  • Support for local port serial and remote firmware updates (FOTA)

Step 2: ESP32-CAM Pinout

Three GND pins as well as two pins to power them that are or 3.3V or 5V.

GPIO 1 and GPIO 3 are serial pins. You require these pins to upload your code onto your board. Furthermore, GPIO 0 also plays an important part, as it decides if the ESP32 is in flash mode or not. If GPIO 0 is connected to GND and this indicates that the ESP32 has entered flashing mode.

There are the following pins internal attached to the microSD reader's pins.

  • GPIO 14: CLK
  • GPIO 15: CMD
  • GPIO 2: Data 0
  • GPIO 4: Data 1 (also connected to the on-board LED)
  • GPIO 12: Data 2
  • GPIO 13: Data 3


Step 3: Streaming Server

Take the following steps for building an online video streaming server using the ESP32-CAM which you can connect to through any local network.

Very Important: Make certain you've had your Arduino IDE installed along with the latest version of the ESP32 add-on.


Step 4: Install the ESP32 Add-on

In this case we are using the Arduino IDE to program the ESP32-CAM board. This means that you have to be running Arduino IDE installed as well as the ESP32 add-on. Follow the following instructions on how to set up the ESP32 add-on if you aren't yet:


Installing the ESP32 Board in Arduino IDE

Step 5: Camera Web Server Example Code

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


The following code should load.

change with your own SSID and Password

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


uncomment only #define CAMERA_MODEL_AI_THINKER

// Select camera model
//#define CAMERA_MODEL_WROVER_KIT
//#define CAMERA_MODEL_ESP_EYE
//#define CAMERA_MODEL_M5STACK_PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE
#define CAMERA_MODEL_AI_THINKER

If none of these are applicable to your camera then you must add the pin assignments for your particular board to the camera_pins.h tab.

The code is ready to be uploaded onto your ESP32.

Step 6: ESP32-CAM Upload Code

Connect the ESP32-CAM card to your computer with an FTDI programer. Follow the following schematic diagram:

Many FTDI programmers include the ability to use a jumper to choose 3.3V and 5V. Be sure the jumper is placed in the right location to choose 5V.




In order to upload your code, you must follow the steps below:

1.) Click the ToolsBoardand select AI-Thinker ESP32-CAM..

2.) 2. Go to the Toolsand then Port and choose the port that the ESP32 is connected to.

3.) Click the submit button, which will upload your code.

4.) Once you start to see these dots appear on the debugging display as illustrated below then press the ESP32 CAM on-board RST button.

Step 7: Getting the IP Address

After uploading your code, remove GPIO 0. GND.

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

This ESP32 IP address must be displayed in the Serial Monitor.


Step 8: Accessing Video Streaming Server

Now, you are able to connect to your camera's streaming server via the local internet. Start a browser and enter the IP address ESP32-CAM. Hit the Start streaming button to begin streaming video.

There is also the option to capture photos using"Take Photos" by clicking the "Get Still" button. Unfortunately, this option doesn't save photographs, but you could alter it to utilize the microSD Card to save the images.

There are a number of camera settings you can alter to change the settings of your image.

Then, you can also do facial recognition as well as detection.




In the beginning, you must register a new face. It will try several times for saving the facial. When a user is enrolled as a new one it will be able to recognize the face later (subject 0.).

It's that simple. Now you've got your web server streaming video running, with recognition and face detection using the sample of the library.


Step 9: Troubleshooting

If you're encountering one of these errors take a look at our ESP32-CAM Troubleshooting Manual The Most Common Problems Solved

  • Failure in connecting to ESP32 Timed out waiting for header packet
  • Camera failed to start with error code 0x20001 or similar
  • Brownout detectors and Guru meditation error
  • Sketch too big error - Wrong partition scheme selected
  • board at COMX is not accessible - the COM port is not selected
  • Psram error message: GPIO isr service isn't installed
  • Poor Wi-Fi Signal
  • There is no IP address within Arduino IDE Serial Monitor
  • Can't open web server
  • The image is slow or shows lots of latency


Step 10: Wrapping Up

The ESP32-CAM offers a low-cost method to create more sophisticated home automation systems that incorporate photography, video and facial recognition.

In this tutorial , we've tried our CameraWebServer example to check the camera's functions. The next step is to alter the code or write entirely new program to create other projects. For instance, take photos and save them to a microSD card whenever motion is recognized, integrate video streaming into your home automation software (like The Node Red or the Home Assistant), and many more.

We hope that you've found this guide helpful. If you don't yet have an ESP32-CAM You can purchase it here..