Creating an ESP32-CAM web server that streams video over both a local network and the internet is a useful and interesting project. Below, I’ll provide you with a step-by-step guide on how to achieve this:
Table of Contents
Features of ESP32 Cam module:
- ESP32 cam module is a cheaper one with nearly 9$.
- It is one of the smallest soc to have 802.11b/g/n Wi-Fi BT SoC which has inbuilt WiFi and Bluetooth.
- Low power 32-bit CPU
- Built-in 520 KB SRAM, external 4MPSRAM
- Support OV2640 and OV7670 cameras, with built-in flash LED light.
- Supports TF microSD card.
- Supports UART/SPI/I2C/PWM/ADC/DAC
- Supports local and remote firmware upgrades(FOTA)
ESP32 Cam module Pinout:
The following image show pinout diagram of ESP32 CAM (AiThinker module).
Here the GPIO0 Pin has an important role which is used to put board into flash mode when a jumper wire is connected between GPIO0 and GND. We need to use this mode while code uploading.
GPIO1 and GPIO3 are serial pins which are used for uploading code into the board and all the other pins connected internally to MicroSD card reader on board.
- GPIO 4: Data 1 (also connected to on-board LED blinks when SD card is used)
- GPIO 2: Data 0
- GPIO 14: CLK
- GPIO 15: CMD
- GPIO 13: Data 3
- GPIO 12: Data 2
Interfacing ESP32 Cam module with FTDI Programmer
What is an FTDI programmer? : “An FTDI programmer, or FTDI USB-to-Serial adapter, is a device used for programming and communicating with microcontrollers, development boards, and other embedded systems that use UART (Universal Asynchronous Receiver-Transmitter) or serial communication. The term “FTDI” stands for Future Technology Devices International, which is a company known for its USB interface chips and associated software drivers.”
You might have observed from the above images that ESP32 Cam module doesnot have an USB pin to connect it to PC to upload the code so in this case we are using a FTDI programmer connected to ESP32 cam. The following schematic diagram shows how to connect the FTDI programmer and how to put the ESP32cam in flash mode.
Detailed guide: How to upload the code to ESP32 CAM using Arduino or programmer
Upload the code to ESP32 cam module with Arduino IDE:
Connect the FTDI with USB to PC where Arduino IDE is installed and follow the steps.
- Paste the code in the IDE
- Click on tools and select ESP32 Wrover Module from Boards
- Select the port where our device is connected.
- Choose the baud rate to 115200
- In Tools ->select Partition Scheme, and select “Huge APP (3MB No OTA)“
ESP32 Cam Live stream in local server Code
The below code is to just to watch the live video on local server by accessing it through a generated IP address.
Get the code from the examples section in the arduino IDE as below
Choose the camara board model by removing the “//” before the model by default it is selected as WROVER_KIT as we are using the AI_THINKER board we can remove the backslash before aithinker and comment the default one with //.
// Select camera model
as the next step change the WiFi credentials to your WiFi ssid and password and then upload the code.
const char* ssid = "Your wifi name goes here";
const char* password = "your password goes here";
After code upload remove the flash jumper pin connected between GPIO0 and GND. then click ok reset button on board.
Open serial monitor in Arduino IDE and set the baud rate to 115200 if it not as default and then you can see that the board is connected to the wifi network and IP address to access the video stream are printed as shown in the below image.
As you got the Local ESP32-CAM IP address from the serial monitor you can watch the live stream from any device which are connected to the same wifi network where ESP is connected by just entering the IP address in any web browser and click on start stream.
Here You have the option take a photo by clicking get still button but we added libraries of SDcard so it wont be saved in storage. We will cover that topic in another article. As you can see in the above image there are lots of options to customise the video quality and add filters to it discover the best settings which suits you.
Live Streaming the ESP32-CAM over internet with the help of NGROK
1)The first step is to create an account in ngrok website and obtain a auth token as shown in the below image
2)Now download the ngrok for windows as we are running it on windows 10 PC.
4)Add your authtoken to ngrok with command “ngrok authtoken paste_you_token”
6) Thats it, You will be granted an URL which you can share to anyone who wants to watch the live stream anywhere from the world.
With this URL you can stream on your android device also through a blynk application just by adding a video streaming widget and adding URL in the URL address field.
If you have any doubts, questions, or encounter any errors while working on this project, please don’t hesitate to comment below. Our community is here to help, and we’ll do our best to provide you with the assistance you need to overcome any challenges.
Additionally, if you found this project helpful, informative, or simply enjoyable, we encourage you to share it with your friends and colleagues. Sharing knowledge and innovative projects not only benefits your immediate circle but also contributes to the broader community of enthusiasts and learners. Your support is greatly appreciated, and it helps us continue to create and share valuable content.