Introduction: Make an ESP32 WiFi CCTV Camera (ESP32-CAM) DIY Wireless Security Cam
Hey, fellow makers! I welcome you to my first instructable about this Homemade wireless ESP32-CAM WiFi Surveillance Camera which we're going to make today to monitor our home, environment, or perhaps to even spy on someone ;)
Even though decent commercial WiFi Security Cameras aren't all super expensive, they still cost quite a bit especially when you're wanting to buy several of them for your home security. In this instructable, you will learn how to make your own DIY Surveillance camera for cheap, under $15 depending on the supplies you may already have. This project will be based on the $9 ESP32-CAM AI thinker WiFi camera module, in my opinion, one of the best and cheapest camera development boards out there.
With this security camera, you can log into the web server by typing in its unique IP address into your web browser, and view what the camera sees along with being able to change things around on the side control panels. The camera with its current code can save recorded .MJPEG video files to an SD card when something/someone moves in front of the camera triggering it to start recording. The Security camera comes loaded with even more features which will be mentioned below.
So without taking up any more of your time, let's prepare to make this CCTV cam!
You may also want to watch the project's YouTube video. Link:
https://youtu.be/0uz-YrfaSO8
Supplies
• ESP32-CAM with OV2640 2MP camera sensor
• FTDI USB to Serial converter (for programming) + Female-to-female jumper wires
• 4GB MicroSD card (TF Card)
• Clip-on antenna
• TP4056 1-cell Li-Ion Charging module
• (x2) 18650 3.7V 2600mAh battery
• Mini SPDT sliding switch (3A toggle switch is recommended)
• Some 24-gauge electrical wire
• 3mm Red LED
• 220 Ohm resistor
• Cylindrical plastic container (choice of camera's enclosure is optional)
• GoPro mount accessories (if you want your camera to be attached to a wall)
Step 1: Programming ESP32-CAM
First, let's upload the ESP32-CAM_MJPEG2SD code to the ESP32-CAM (credits to GitHub user "s60sc" for making their code available for anyone to download) please visit https://github.com/s60sc/ESP32-CAM_MJPEG2SD for more information and specs about the code, as well as the code itself.
To program the camera module, connect the camera module to a USB-to-serial converter "FTDI" like in the diagram seen above, with GPIO pin 0 connecting to GND allowing you to program the ESP. Don't forget to press the onboard reset button on the back of the camera module to set it into flash mode before uploading.
Step 2: Making Sure You've Got the "ESP32 .json Link"
Before we move on to the actual code, check that you have the ESP32 .json link from this website linked below pasted in the preferences tab of the Arduino IDE. This link gives you access to example codes, all of the needed libraries, etc...
https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html
Make sure your ESP32 board library version is at 2.0.2 or higher.
Step 3: In the Code: Filling in Necessary Parameters
Open the Security Camera's code which you've downloaded (ESP32-CAM_MJPEG2SD) and fill in the necessary params such as selecting your camera model (uncomment "CAMERA_MODEL_AI_THINKER" if that's your board), enter your WiFi credentials, and lastly, FTP credentials (optional) if you're into getting hold of recorded footage remotely.
This now has to be done in the "utils.cpp" tab. Please don't get it confused for the "myConfig" tab, as that's what has been leading to many errors.
Step 4: Uploading Code to Board
Make sure you select "ESP32 Dev Module" with partition scheme "Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS)", enable PSRAM, and select your COM port. Then hit upload. Do know that uploading to the board may take a while, it's totally normal, please be a bit patient :)
Code: https://github.com/s60sc/ESP32-CAM_MJPEG2SD
Step 5: Preparing ESP32-CAM for Use & Getting IP Address
Be sure to unplug the jumper wire going from IO0 to GND, press the reset button, insert a Micro SD card into the module's slot (Min. 4GB), then obtain its unique IP address from the Serial monitor (Serial button can be found at the top right-hand corner of the Arduino IDE).
Step 6: Opening Up ESP32-CAM's Web-server
After typing in the given IP address into your web browser with the camera still being powered, you should get a page looking like this, by pressing the "Start Stream" button, you will be able to view live what the camera sees.
(With the latest version of this code from the GitHub user "s60sc", you can now manually start and stop recording. Before, you were only able to trigger it to record when it sensed a movement.
Step 7: Assembling the DIY Security Camera
Here are the parts you'll need in order to make the actual WiFi CCTV Cam. (Not totally accurate on the image to what was used)
• ESP32-CAM
• TP4056 1S battery charging board
• 18650 Li-Ion 3.7V battery
• SPDP Micro slide switch or 3A toggle switch
• 3mm Red LED
• 1/4W 220-ohm resistor
• Antenna
• 24-gauge electrical wire
• GoPro-compatible screw-mount
For its case/enclosure, choose a container or material that will be easy for you to work with, as for myself, I've had lots of trouble getting the hardware fitted into that flattened PVC pipe shown above. (Later, you see me use a cylindrical plastic container)
Step 8: Enabling Board for an External Antenna
Desolder this 0-Ohm resistor that connects the ESP to its onboard antenna and resolder it to connect the ESP to the external antenna port.
This step must be done if you want a better range by being able to connect your own antenna.
Step 9: Connecting Up the ESP32-CAM's Power Supply
Hook up this TP4056 4.2V charging board to the battery, B+ & B- connections from the board to the battery go as shown (Connect the board's input terminals near the Micro USB port to the battery's terminals)
Step 10: Extending Connections of Components
De-solder the ESP32-CAM's pin headers from both sides, instead, extend those pin headers by soldering them back on through wires. (Not to confuse you, try to use matching wire colors to their asserted purposes.
You can also add an LED (3mm Red LED) as a power indicator, connect it across the input power terminals of the camera board with a 220-ohm resistor.
Step 11: Circuit Diagram
Here's the DIY WiFi Security Camera's full circuit diagram.
Following this simple wiring diagram, you should have all of the hardware for your Homemade CCTV cam complete.
Step 12: Choosing the Right Battery to Fit a Certain Case
As you saw, I started out with a flat Li-Ion battery since I thought the components would go into a differently shaped case. Then realized swapping out the battery was needed in order for it to fit into its new, proper cylindrical case.
Best to use a battery with a capacity or mAh rating higher than 2000 for better performance.
I ended up using x2 3.7V 2600mAh 18650 batteries in parallel, giving 5200mAh in total. A decent amount of power capacity.
Step 13: Preparing the Hardware to Be Fit Into Its Case
Mark and drill out holes for certain parts of the hardware to poke out of the case
When choosing a good case for your camera, use something with two parts to it, a case that's fairly easy to work with.
3D printing your own one is definitely an option going for if you've got a printer.
Step 14: Fitting Things In
Next, add some adhesive/double-sided tape to parts such as the ends of the battery pack and ESP32-CAM module, then stick them into the case.
Seal any component that sticks through with glue (preferably hot glue)
Step 15: Weather-proofing
You may use hot glue to secure certain parts to the case if needed. Tape off the halves' joining section with electrical tape to prevent any water such as raindrops from seeping into the cam.
Slice corresponding pieces of rubber, fit them into any gaps/holes such as the Micro USB port at the back and SD card slot at the top front.
Step 16: Testing the End Product
Slide in your Micro SD card into the cam's slot, push that little piece of rubber back in, power the camera up by sliding the switch on the rear, and find its unique IP camera web-server (Return to previous steps 5 & 6 for more clarity).
The camera's procedure to starting up and finding its web server goes as followed, though, this time you won't have to press any reset button as you're not reprogramming the camera.
On your viewing device, in the camera web-server menu, simply press the "Start Stream" button and you should get a live video feed from the CCTV camera.
Step 17: Camera's Live Video Feed Panel
In this panel of the webserver, you should see a live video feed once you've pressed on "Start Stream".
Below you have additional info about whether it's recording or not, detecting low light (night time), space left on SD card, recording date, camera temperature, etc...
You may even toggle the ESP's onboard LED lamp with the slide of a panel button, show AI-detected motion, alter sensitivity on certain functions, and more.
To change the camera's recording resolution (not only viewing res.) you can open the resolution tab, scroll through and choose a lower or even a higher one. (1600 × 1200 is the highest)
Under the "Get Folder" tab, there you can preview the recorded video files and start playing the selected video file by pressing the same "Start Stream" button.
Step 18: Making a Wall Mount
This is optional, you may even create a mount to attach the DIY CCTV camera onto a wall, or the surface of your choice where you'd like to monitor things from.
I happened to use a set of action cam attachments for my mount.
Step 19: Powering the Camera Via USB
With the Homemade CCTV camera being attached to a wall, one would be better off having it continuously powered. So you may connect a 5V power supply to the Micro USB charging module connected via the cam's rear (Micro USB cable from wall socket phone charger). This is basically recharging the battery, but at the same time continuously powering the ESP32-CAM.
The battery won't last for too long if let's say you're going to record a spot overnight. Though running the camera on the battery can come in handy when you want to monitor an outdoor environment for a shorter period of time where a power outlet can't be reached.
Step 20: Emptying Recorded Footage
Once you can see your MicroSD card is getting full, you can slide it out of the camera and slot it into your PC via an SD card adapter to then view the .MJPEG files via a player such as "VLC Media player".
Step 21:
As you can see on the left-hand side of the phone's screen under the "Recording" status, when nothing is moving in the frame, the camera won't record anything until something or someone moves within the frame. It stops recording as soon as it doesn't detect any more motion.
Step 22:
There you have it, folks! Since you made it this far with your new cool little Homemade WiFi Security Camera, go out there with your new DIY CCTV cam and add an additional layer of security to your home! :)
Once again, here is the code & its extensions, additional information, specifications, possibilities, and more at the ESP32-CAM MJPEG2SD GitHub repository (Repository credits to the user "s60sc"): https://github.com/s60sc/ESP32-CAM_MJPEG2SD
You may also prefer to watch the full video tutorial on my YouTube channel:
https://youtu.be/0uz-YrfaSO8

Runner Up in the
Anything Goes Contest 2021
93 Comments
4 weeks ago
How can I do it with smartphone?The code at gitHub seems not for Android phone.I have esp32 cam module but struggling in programming by phone.I tried many codes but Arduino Droid is giving errors for libraries or board types.
Pl. Help
Reply 11 days ago
Hi there. Please excuse my late reply. It's actually possible if you use an Arduino UNO to program the ESP32-CAM. This video might help: https://www.youtube.com/watch?v=FLL1UMKYnU4
4 months ago
Outstanding build Max! Thank you for sharing.
I see answers to some of my questions below, but one problem I am still trying to rectify is that I can't connect to the IP address that it provides me with. I can see from the serial monitor that motion is activating the camera and that a few seconds of video has been taken, but I can't seem to get past Step 5 to play around with the other features.
Can you, or anyone else reading this, provide me with any insight?
Reply 4 months ago
Hi there! Thanks for your comment.
That is strangely odd...
Have you tried entering the IP it gives you from other devices within your WiFi network? It may be worth checking to see if it's something with your web browser or PC.
Feel free to get back to me if the problem persists.
Cheers.
Reply 4 months ago
Hi Max,
I'm not quite sure what you mean or what I should be looking for. However, there is nothing else on my network and I get the same results using my mobile hotspot. I might be missing something else as I am only entering information for the Hostname, SSID, and password. I am not exactly sure what the rest of the information below that in the code is just yet. I am simply trying to get to the control panel and figured those areas were for advanced settings. Do I need to have those filled out? If so, what exactly is that information? If it is not clear by now, I am extremely new to these types of projects.
I also get an error when I run the unaltered code regarding the following lines.
config.pin_sccb_sda = SIOD_GPIO_NUM;
config.pin_sccb_scl = SIOC_GPIO_NUM;
It says that these pins do not exist and it suggests the following.
config.pin_sscb_sda = SIOD_GPIO_NUM;
config.pin_sscb_scl = SIOC_GPIO_NUM;
Changing the sccb to sscb allows the program to compile and upload. I am using the AI Thinker esp32-cam module and I have that board selected in the IDE. Is there any more information that I can provide you that could possibly help you help me?
Question 7 months ago on Step 22
Hi
Max thank You
I
have a problem:
Alternatives
for bits/error_constants.h:
[]
ResolveLibrary(bits/error_constants.h)
->
candidates: []
In
file included from c:\users\thinkpad
t430\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\ios_base.h:46,
from
c:\users\thinkpad
t430\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\ios:42,
from
c:\users\thinkpad
t430\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\ostream:38,
from
c:\users\thinkpad
t430\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\iterator:64,
from
c:\users\thinkpad
t430\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\regex:43,
from
C:\Users\THINKP~1\AppData\Local\Temp\arduino_build_499045\sketch\globals.h:92,
from
C:\Users\ThinkPad
T430\Desktop\ESP32-CAM_MJPEG2SD-master\ESP32-CAM_MJPEG2SD\ESP32-CAM_MJPEG2SD.ino:9:
c:\users\thinkpad
t430\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\system_error:39:10:
fatal error: bits/error_constants.h: No such file or
directory
#include
<bits/error_constants.h>
^~~~~~~~~~~~~~~~~~~~~~~~
compilation
terminated.
library
usageESPmDNS version2.0.0
folder: C:\Users\ThinkPad
T430\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.3\libraries\ESPmDNS
library
usage Preferences version 2.0.0 folder: C:\Users\ThinkPad
T430\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.3\libraries\Preferences
exit
status 1
Error
compilation ESP32 Dev Module.
ESP32
Espressif systems version 2.05
Arduino
IDE version 1.8.13
Answer 6 months ago
Hi there.
Please excuse my late response. By the looks of it, it might pay to try uploading to your board with having Wrover instead of Dev as your board selection. Try with either one again.
Two, did you check to have GPIO 0 & Ground shorted together then pressing on the reset button once before uploading?
Cheers,
Max
Question 8 months ago
how do you enable continuous recording? this thing has a massive delay with motion sensitivity and typically if someone were to walk into the field of view past the camera it wouldnt even start until they already passed
Answer 7 months ago
Hi. Sorry for the late reply. This can be done by disabling motion-triggered recording in the code, then manually clicking on the record button in the web-server.
8 months ago
Hey. What use if my board esp32-cam (AI_THINKER) without PSRAM ?
Reply 8 months ago
Hello there.
As it's an ESP32, not a ESP8266 chip, there's enough memory onboard the chip to support imaging applications, such as the low-quality ESP32 cam with this code.
In most cases, you won't need PSRAM, so that shouldn't be an issue with using your ESP. You can actually read more about PSRAM - the added-on chip to help boost memory: https://thingpulse.com/esp32-how-to-use-psram/
Cheers,
Max
Question 10 months ago
Hello Max, thanks for sharing !
You might help me with the following : I was able to upload the code onto the ESP32 but when I open the serial monitor i have the following message :
[00:11:23.717 setup] =============== Starting ===============
15:27:01.944 -> E (502) sdmmc_common: sdmmc_init_ocr: send_op_cond (1) returned 0x107
15:27:01.944 -> E (502) vfs_fat_sdmmc: sdmmc_card_init failed (0x107).
15:27:01.944 -> [00:11:23.745 ERROR @ utilsSD.cpp:49] SD card mount failed
15:27:01.944 -> [00:11:23.750 WARN setup] Insert SD card, will restart after 10 secs
Note that i put a 8MB SD card in my ESP 32 and, as I was not sure that the code was able to (re) format the card i did it separately. Even with this, i was not able to start using the cam. Any idea?
Answer 10 months ago
I had same problem, not sure if this is correct but I add an include in myConfig.h : #include "FS.h" after this change, SD card mounted successfuly and app run
Reply 8 months ago
the files it tries to download from github to place in the SD card may exceed 8MB, also 8MB micro SD cards are probably ancient and beyond slow
Answer 10 months ago
Hello, Gael. Glad to hear you liked the Instructable.
By the look of it, your ESP32 could be giving you complaints due to you using an MicroSD card with a capacity greater than 4MB.
The ESP32-CAM is used to writing on 4MB of media onto a card, and only using up that much space, from what I've heard. You could try reformatting your card in FAT32, and not exFAT, if you haven't done it that way yet.
You could try to use an SD card that's preferably 4MB, in doing so, it might just work.
I've also come across these lines of text in my serial monitor when I was underpowering my ESP32, this was followed by a brownout error. You could try to hook yours up to a power source that can deliver more current. Changing out a cable for a better quality one may do the job.
From my experience, these are all of the things that come to mind that I believe may help you.
I hope this helps.
Cheers,
Max
1 year ago
Hey! Awesome project! How long does work with two 18650 batteries?
Reply 9 months ago
About 3 to 3 and a half hours.
Reply 1 year ago
Hi. Thanks! Well, from my calculations based on knowing the ESP's average power consumption, those two batteries should last about 24h running the ESP32-CAM.
Cheers,
Max
9 months ago
I got an error in this<a href="https://apkbobs.com/acode-mod-apk/">.</a>;
Reply 9 months ago
Hi there. Please visit the code repository page for more help: https://github.com/s60sc/ESP32-CAM_MJPEG2SD