Introduction: Getting Started With ESP32 CAM | Streaming Video Using ESP CAM Over Wifi | ESP32 Security Camera Project

Today we will learn how to use this new ESP32 CAM board and how we can code it and use it as a security camera and get a streaming video over wifi.

Step 1: Things You Need

Before we start make sure you have these following things with you :

ESP 32 CAM :

https://www.utsource.net/itm/p/8673370.html



FTDI :
https://www.utsource.net/itm/p/7958953.html

Step 2: ESP32 Arduino IDE Setup

Make sure you have Arduino IDE in your PC and you installed ESP32 Boards in your Arduino IDE, and if it is not the case please follow the following instructables of mine to install it. :

https://www.instructables.com/id/Getting-Started-W...

Step 3: ESP32 CAM Board Specifications

Before we go to do anything make sure you know specification and pinout etc of ESP32 CAM board, and for that pinout image is added please refer that and specifications of ESP32 CAM board is given below :

The smallest 802.11b/g/n Wi-Fi BT SoC moduleLow

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 cardSupports multiple sleep modes

Embedded Lwip and FreeRTOSSupports STA/AP/STA+AP operation mode

Support Smart Config/AirKiss technology

Support for serial port local and remote firmware upgrades (FOTA)

Pins used for 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 4: Connect Everything Together

To program this thing we need to connect a FTDI/usb to ttl to program this thing because this board isn't having one.
So connect the Ftdi/usb to ttl according to schmatics.

Step 5: Getting the Code

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

OR you can use the following given code , copy the following code :

#include "esp_camera.h"
#include
#include "esp_timer.h"
#include "img_converters.h"
#include "Arduino.h"
#include "fb_gfx.h"
#include "soc/soc.h" //disable brownout problems
#include "soc/rtc_cntl_reg.h" //disable brownout problems
#include "dl_lib.h"
#include "esp_http_server.h"

//Replace with your network credentials
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

#define PART_BOUNDARY "123456789000000000000987654321"

// This project was tested with the AI Thinker Model, M5STACK PSRAM Model and M5STACK WITHOUT PSRAM
#define CAMERA_MODEL_AI_THINKER
//#define CAMERA_MODEL_M5STACK_PSRAM
//#define CAMERA_MODEL_M5STACK_WITHOUT_PSRAM

// Not tested with this model
//#define CAMERA_MODEL_WROVER_KIT

#if defined(CAMERA_MODEL_WROVER_KIT)
#define PWDN_GPIO_NUM -1
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 21
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27

#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 19
#define Y4_GPIO_NUM 18
#define Y3_GPIO_NUM 5
#define Y2_GPIO_NUM 4
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22

#elif defined(CAMERA_MODEL_M5STACK_PSRAM)
#define PWDN_GPIO_NUM -1
#define RESET_GPIO_NUM 15
#define XCLK_GPIO_NUM 27
#define SIOD_GPIO_NUM 25
#define SIOC_GPIO_NUM 23

#define Y9_GPIO_NUM 19
#define Y8_GPIO_NUM 36
#define Y7_GPIO_NUM 18
#define Y6_GPIO_NUM 39
#define Y5_GPIO_NUM 5
#define Y4_GPIO_NUM 34
#define Y3_GPIO_NUM 35
#define Y2_GPIO_NUM 32
#define VSYNC_GPIO_NUM 22
#define HREF_GPIO_NUM 26
#define PCLK_GPIO_NUM 21

#elif defined(CAMERA_MODEL_M5STACK_WITHOUT_PSRAM)
#define PWDN_GPIO_NUM -1
#define RESET_GPIO_NUM 15
#define XCLK_GPIO_NUM 27
#define SIOD_GPIO_NUM 25
#define SIOC_GPIO_NUM 23

#define Y9_GPIO_NUM 19
#define Y8_GPIO_NUM 36
#define Y7_GPIO_NUM 18
#define Y6_GPIO_NUM 39
#define Y5_GPIO_NUM 5
#define Y4_GPIO_NUM 34
#define Y3_GPIO_NUM 35
#define Y2_GPIO_NUM 17
#define VSYNC_GPIO_NUM 22
#define HREF_GPIO_NUM 26
#define PCLK_GPIO_NUM 21

#elif defined(CAMERA_MODEL_AI_THINKER)
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27

#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
#else
#error "Camera model not selected"
#endif

static const char* _STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary=" PART_BOUNDARY;
static const char* _STREAM_BOUNDARY = "\r\n--" PART_BOUNDARY "\r\n";
static const char* _STREAM_PART = "Content-Type: image/jpeg\r\nContent-Length: %u\r\n\r\n";

httpd_handle_t stream_httpd = NULL;

static esp_err_t stream_handler(httpd_req_t *req){
camera_fb_t * fb = NULL;
esp_err_t res = ESP_OK;
size_t _jpg_buf_len = 0;
uint8_t * _jpg_buf = NULL;
char * part_buf[64];

res = httpd_resp_set_type(req, _STREAM_CONTENT_TYPE);
if(res != ESP_OK){
return res;
}

while(true){
fb = esp_camera_fb_get();
if (!fb) {
Serial.println("Camera capture failed");
res = ESP_FAIL;
} else {
if(fb->width > 400){
if(fb->format != PIXFORMAT_JPEG){
bool jpeg_converted = frame2jpg(fb, 80, &_jpg_buf, &_jpg_buf_len);
esp_camera_fb_return(fb);
fb = NULL;
if(!jpeg_converted){
Serial.println("JPEG compression failed");
res = ESP_FA

Step 6: Upload the Code

After getting the code , you need to upload the code and it requires few settings to upload the code so make sure you did following thing during upload because its a hug code so it will not get uploaded by normal method.

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)“

Before uploading the code, you need to input your wifi credentials in the following part of code:

const char* ssid = "REPLACE_WITH_YOUR_SSID";

const char* password = "REPLACE_WITH_YOUR_PASSWORD";

and make sure you select the right camera module.

As here we’re using the AI-THINKER Model so select the following So, comment all the other models and uncomment this one:

#define CAMERA_MODEL_AI_THINKER


Press the ESP32-CAM on-board RESET button
Then, click the upload button to upload the code.

Step 7: Getting the IP

Remove the jumper connected between GPIO0 & GND then,

Open the Serial Monitor with the baud rate : 115200 & then Press the ESP32-CAM Reset button and wait for the IP to appear and wait for few seconds and then hit reset again.

As you can see i got my IP and it is highlighted in the image.

Step 8: Getting the Wifi Streaming Video

Open your browser and make sure your PC is connected to same network as ESP32 CAM and then type the IP in your Browser then click on stream button and you’ll get your video stream and there are few settings here as well so you can try those and get a better video as well.