In this tutorial, I'll show that how can we make an ESP32-CAM based video server which can be hosted on a local server.
This project is sponsored by LCSC. I have been using electronic components from LCSC.com. LCSC has a strong commitment to offering a wide selection of genuine, high-quality electronic components at the best price with a global shipping network to over 200 countries. Sign up today and get $8 off on your first order.
We can set up a video streaming web server with face recognition and detection in less than 5 minutes with Arduino IDE.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: 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).
Here is a list with the ESP32-CAM features:
- 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)
Step 2: ESP32-CAM Pinout
The following figure shows the ESP32-CAM pinout (AI-Thinker module).
There are three GND pins and two pins for power: either 3.3V or 5V. GPIO 1 and GPIO 3 are the serial pins. You need these pins to upload code to your board. Additionally, GPIO 0 also plays an important role, since it determines whether the ESP32 is in flashing mode or not. When GPIO 0 is connected to GND, the ESP32 is in flashing mode.
The following pins are internally connected to the microSD card reader:
- 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: Video Streaming Server
Step 1: Install ESP32CAM add-on
Firstly, we need to add the ESP32 CAM to our boards in the Arduino IDE. This will add the required files which shall be used to program the ESP32 CAM module. You can go here to know to do this. Step 2: Uploading the sketch.
Go to my GitHub repository mentioned in the project below in the attachments. Take the code and paste it into the Arduino IDE. 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";
Upload the code to the ESP32 CAM
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:
- Go to Tools > Board and select ESP32 Wrover Module
- Go to Tools > Port and select the COM port the ESP32 is connected to
- In Tools > Partition Scheme, select "Huge APP (3MB No OTA)"
- Press the ESP32-CAM on-board RESET button
- 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 GND 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.
Step 4: 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.
Step 5: Step 4: 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 onboard 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 in 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.