ESP32-CAM Arduino Source Code (CCTV Video Recorder and IP Camera)

Other projects from this group

ESP32-CAM Arduino Source Code (CCTV Video Recorder and IP Camera)

With this source code, an “ESP32-CAM” module and a 5.0v power source, build a CCTV/IP camera with motion sensing.

Arduino ESP32-CAM CCTV, WiFi IP Camera Source Code - Rev 2.1



Other projects from this group


This project is an “ESP32 WiFi Camera (IPCam)” firmware arduino source code (.ino) with Time Lapse and Chain Network feature which is based on the “ESP32 WebApp Builder” project. The “Chain Network” is a local network which the devices one by one are connected to the each other.

The IPCam project uses the “AI Thinker ESP32-CAM” module which has a 2MP Camera, 10 I/O pins, an on-chip LED and one MicroSD slot to store the images and videos. With its tiny sized camera and 240MHz CPU is able to provide a fair quality images and video frames.

The source code contains the following files:

  1. ESP32CamProgram.ino (Main handler file)
  2. AC.h (Configuration header file)
  3. AC.ino (Configuration handler file)
  4. functions.ino (System functions)
  5. rootPage (UI handler file)
  6. user_global.h – Project global variables and definitions file.
  7. user_init.ino – Project initial script file.
  8. user_loop.ino – This file has a “userLoop()” function which calls repeatedly (like arduino “loop()” function).
  9. user_settings.ino – Project settings file.
  10. user_main.ino – Online video stream handler script.
  11. user_sub.ino – Memory handler script.
  12. user_global.ino – This file has a “userGlobal()” function.
  13. Webapp.h – This file contains the IPCam WebApp’s script.

Compilation and programming of this source code is compatible with “Arduino ESP32” rev 1.0.6

And all you need to use is just a web browser.

esp32-cam arduino

Uploading the project

First open one of the files with Arduino program, then set the settings as the following image (Board and Flash Frequency).

  • The “Board” must be set on one of the ESP32 Modules before doing anything.
  • The start-up CPU speed has been set to 160MHz.
  • For the “download mode”, use a jumper for connecting “IO 0” to the GND.

Then turn on the ESP32 module in the “download mode” (GPIO0àGND) and upload the program with using an USB2Serial module.

Preparing the ESP32 IP Camera

The “Ai Thinker ESP32-Cam” module is completed. You only need a standard 5V power source.

Also you can stick a heat sink to the module’s regulator. It’s not necessary but recommended.

  • The onboard ESP32 module must only receive 3.3v. Higher voltage will hurt the module.
  • Do not use higher voltage for the 5V and 3.3V input pins.

This is the assembled circuit with a 5V power source inside of an enclosure:

spycam esp32-cam

The Chain Network

The “Chain Network” is a local network which the devices one by one are connected to the each other (Series). In the chain network, the first device is the master of network. The starter (either the master or the last joined module) is directly connected to the WebApp. It sends the command to the next device, and the next device sends it to the next one till the last device. The last device response will be sent to the first device and finally the WebApp via the middle devices.

You can join up to 4 cameras, either with “ESP32 SpyCam” firmware (Audio and Video recorder) rev 1.4 or “ESP32 IPCam” firmware (which has not the audio record feature) rev 1.4 in a chain network and see the online stream of the Cameras.

  • In the current revision, the online stream is available for only 2 devices in the network, but the file access is available for all of the devices.

The ESP32 IP Camera Web Application

Plug the power and turn on the circuit and the module in “normal mode”.

Then the LED will blink once (in case of everything is ok). Then you’ll be able to see the module’s hot spot ssid via the WiFi networks in your PC or smart phone.

The default SSID is WiCardCam and the default password is 12345678. Connect and go to with a PC or smart phone web browser (Chrome or Firefox).

Here’s the web UI:

ip camera microphone esp32-cam arduino cctv

Right after loading the page, the module starts recording and buffering automatically.

By tap on the video image, the image will scale to full with and original size.

There are two buttons under the image. With “CAPTURE”, the module will take and save a shot and with tap or click on the “LIGHT” button, the on-chip flash light will turn on and off.

In case of using the “Chain Network” feature, If you join multiple ESP32-Cams to the network, you’ll be able to see an online stream of all of the joined cameras at the same time. in the “Streams” page:

spy camera esp32

By one click on each image, the “Capture” and “Light” buttons will appear and by double click on each images, you can enlarge and see the selected camera stream in higher quality.

By tap or click on the “menu button” (top-right), the menu items will be appeared:

  • The box blow of streams shows the audio signal of “ESP32 Camera Microphone” devices. For the IP Camera firmwares (this firmware), It will write “Not Supported” in the box.
  • Do not open two pages at the same time. The module can handle only one page at a time.
  • The WiFi signal strength takes effect on the module capability and the video streams.
  • The ESP32 module is weak and the arduino ESP32 compiler (rev 1.0.6) still needs to be updated, so when the module’s access point (hotspot) is turned off (by connecting the module to a modem and turning the temporary hotspot button on in the settings page), the device has a better performance.

The responsive WebApp

This web application is also compatible with both of mobile and desktop device browsers:

spy camera android ios web application

The menus

The Web Application is divided to 3 menus. The menus can be selected by click on the menu button.

“Streams” refers to the “Online Stream” page, “Memory” refers to the file manager and “Settings” refers to the settings page.

The File Manager

In the “Memory” page, you can see the saved images (.jpg format) and the recorded videos.

spycam video player

The videos save in “.jp5” format and in the current firmware revision, you can only play the videos in this page.

Also you can access to another device’s memory in this page with setting the “Target” device in the settings page.

There are 3 buttons under the image:

  • File name (direct link) button.
  • Next file button
  • Remove button

The left button under the image (blue button) shows the file name and has the direct link of file (you can right click on it and copy the link).

The middle button shows the next file.

And the right button, removes the file.

You can download the images by tap or click on the image.

By click on the play button (middle of the JP5 file image), the video will be downloaded and played along with the audio and you can pause the video by tap or click on the image.

  • Downloading the videos may take a while, it depends on the video data length and the WiFi signal strength.

The Settings menu

The web application’s settings menu has been divided to 5 parts:

  1. Modem Configuration
    In this section you can see the available access points, the connection status, the device MAC address and the DHCP IP.
    Also in this section you can set the SSID and password of the modem’s access point.
    * If the modem is not available, clear the SSID text box and save it.

  2. Device Hotspot Configuration
    In this section you can set your module’s hotspot SSID and password.
    The secure link is a string which will be added at the end of your module’s IP address. For example if you set it “123”, the IP address of the WebApp of your module will be instead
    The even means the default IP is, the Odd means the default IP is
    Hidden HotSpot will set the HotSpot hidden.
    Temporary HotSpot will disable the HotSpot right after the module is connected to the modem or joined to the network (For the last device in the network).
    * The SSID must be without space in case you’re going to join the device to the network.
    * You can’t join or link two devices with the same IP or SSID, so use Even-Odd-Even-Odd… IPs.
    * The linked device is the device which has been connected to the module’s HotSpot In the network.
  3. Camera Configuration
    In this section:
    * You can set the device’s network channel. The channel must be a number between%26nbsp;%26nbsp; 0-7 and the devices can’t have the same channel.
    * The “Quality” of online stream and recording which can be Low (320*240), Medium (640*480) or High (800*600).
    * The “Record Time” can be 10Sec, 30Sec, 1Min, 2Min or 4Minutes.
    * The “Motion Detector Sensitivity” is the internal image processing sensitivity for motion detecting and can be Off, Low, Medium or High.
    * The “PIR Input” switch enables and disables reading getting record command from “GPIO 3”.
    * The “Flash Light” switch turns on and off the on-chip power LED during the recording.

    The internal image processing sensitivity also depends on the scene light and objects.

  4. Local Network Configuration
    In this section you can set the “Master” device and also set the userGlobal() function execution delay.
    The linked WiCard IP is the IP of linked device to the module’s access point.
    If you don’t turn on the “Join Required” switch, the module will be set as Master.

    * If you’re not going to use the chain network feature, do not turn on the “Join Required” switch.
    * Only one device can be the “Master” in the chain network, which is the first device. So the “Join Required” switch must be turned on in the other devices.

  5. Local Network Map
    In this section, the attached devices in the chain network will be shown.
    For the master, it starts with master’s SSID, then the second ESP device, until the last one, but for the last device, the sort is vice versa.
    With typing the target device SSID in the target text-box, you can access to the target device’s memory.
  • With the target feature, you can access to both of IPCams and SpyCams (rev 1.3) memories and play the .JP4 and .JP5 videos.
  • You can directly access to the settings menu with http://ip#settings link (e.g.
  • The process of smaller images is faster.
  • If you have not enough programming and electronics knowledge, do not make change in the program.
  • The size of every packet is limited, so increasing the quality may cause problems in the video recorder and player.
  • The WiFi signal strength takes effect on the module capability and the streams.

- Compatibility of WiFi Microphone devices for the Network feature
- Bugs fixed
- Online Audio stream added for the SpyCam devices in the network

- Faster online stream
- Faster network stream
- Time lapse added
- File manager added
- AVI file export added
- Bugs fixed

- The capacity of network increased up to 4 streams
- The quality of network stream increased
- Page loading speed increased
- Buffer size increased
- Connection secured with upgrading the secure link feature
- Settings bug fixed
- Auto network channel and target selector added

- Network Stream feature added.
- Network memory access added.
- Online signal scope added.
- .jp5 file added in the player.
- Video player upgraded.
- Bugs fixed.

- The WebApp appearance (Web UI) changed
- The audio decoder added to the WebApp
- SPI mode added
- Supports FAT32 and newer microSD cards
- Flash light during recording
- PIR input added
- SecretLink bug fixed

- Motion Sensor
- Recoding videos
- Playing videos and images
- Camera configuration
- Server option
- Internal pages secure link
- Server script
- Shop MAC and IP in config page

- Video stream
- Saving the images
- LED toggle on/off
- Set module hotspot and modem’s ssid and password
- Automatically connection to the modem
- Config page
- Hidden hotspot button
- Disable hotspot button

Similar Projects: