How to build a facial recognition system using ESP32-CAM

Facial recognition technology identifies individuals by analyzing and comparing their facial features. It uses biometric patterns and algorithms to map and distinguish a person's unique characteristics. The technology has become an essential component of many security applications.

Facial recognition is commonly used for access control, surveillance, biometric authentication, identity verification, criminal identification, care, emergency response and fraud prevention.

What if you could build a facial recognition system for less than $20? This is possible with an ESP32 camera. The ESP32-CAM module typically costs around $10 (although prices may vary) and is capable of taking photos, streaming videos, and performing facial recognition. In this project, we built a facial recognition system using ESP32-CAM with Arduino.

Required components

  1. ESP32-CAM x1
  2. Arduino UNO or MEGA x1
  3. USB cable to connect Arduino to the computer
  4. Jumper wires

ESP32-CAM
ESP32-CAM is a development board that combines the ESP32 microcontroller with a camera module, capable of capturing images and transmitting video via Wi-Fi. It is popular among developers and enthusiasts of Internet of Things (IoT) applications and projects who require a camera.

ESP32-CAM has a two-megapixel OV2640 camera and a built-in TF card slot. The camera supports JPEG and BMP image formats and various modes like single shot, burst, etc. The module is based on the dual-core Tensilica LX6 microprocessor, a low-power 32-bit CPU. It has a built-in 4 MB flash memory for program storage and a MicroSD card slot can be used for additional storage. It has built-in WI-FI and Bluetooth, and the camera module can transmit video over Wi-Fi.

ESP32-CAM has the following pin diagram:

The module has two power pins – 3.3 and 5 V – and three ground pins. Two pins are for universal asynchronous receiver/transmitter (UART) communication. It does not have a USB port, so the UART port must be used to load code through an FTDI or Arduino programmer. When loading the code, the GPIO0 of the module must be connected to ground.

Circuit Connections
For this project, we will use Arduino to upload the sketch to the ESP32-CAM. Both Arduino UNO and Arduino MEGA work well.

The steps:

  • Connect GPIO1 (U0_TXD) and GPIO3 (U0_RXD) with Arduino's TX and RX pins
  • Connect the ESP32-CAM's 5V and ground pin with the Arduino's 5V output and GND pins.
  • Connect the Arduino RESET pin to the ground pin.
  • After submitting the sketch, connect the GPIO0 of the ESP32-CAM to its ground pin.
  • After loading the sketch, remove the connection between the GPIO0 and ground pins of the ESP32-CAM.

Circuit diagrams
This circuit diagram shows the connections between Arduino and ESP32-CAM when uploading the sketch.

The following circuit diagram shows the connections between the Arduino and the ESP32-CAM to the camera after uploading the sketch. Note that the connection between the ESP32-CAM's GPIO0 and the ground pins has been removed.

The sketch
Before submitting the sketch, you must install the ESP32 add-on and ESP32 library in the Arduino IDE. For the ESP32 add-on, navigate to File->Preferences and add the following lines under 'Additional board manager URLs'. Then click 'OK'.

Then open the board manager by navigating to Tools->Board ->Board Manager. Search for ESP32 and install 'ESP32 by Espressif Systems.'

After installing the ESP32 add-on, navigate to File-> Examples -> ESP32 -> Camera and open the CameraWebServer example. In the CameraWebServer example, you must disable the Brownout feature of the ESP32-CAM. To do this, add the following libraries from the beginning of the example.

#include “soc/soc.h”
#include “soc/rtc_cntl_reg.h”

In the setup function, add one more line of code as follows:

WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);

In the example code, uncomment the following line of code:

#define CAMERA_MODEL_AI_THINKER // Has PSRAM

Replace the SSID and password assignments with the SSID and network key of your WI-FI connection. The complete outline of the modified example is provided below.

#include “esp_camera.h”
#include
#include “soc/soc.h”
#include “soc/rtc_cntl_reg.h”

The code

Loading the sketch
First, complete the circuit connections as instructed above to load the code. Remember to connect the GPIO0 of the ESP32-CAM with its ground pin to correctly load the sketch.

Connect the Arduino to your computer using a USB cable. Select 'ESP32 Wrover Module' as the board and set the following parameters in 'Tools.'

Compile and upload the sketch by clicking the upload button in the Arduino IDE.

Get the IP address
After uploading the code, remove the connection between the GPIO0 and GND pins of the ESP32-CAM. Open the Arduino IDE's Serial Monitor and set its baud rate to 115,200 bps. Press the reset button on ESP32-CAM and wait for the camera to connect to WI-FI.

After the camera is successfully booted and connected to the Internet, the IP address that connects to the video streaming server will be printed on the Serial Monitor.

Accessing the video streaming server
Open the IP address obtained from the ESP32-CAM in any web browser. The video streaming server should open. Scroll down and click 'Start Broadcast'.

Here is a video transmission from ESP32-CAM via WI-FI.

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.