Make an ESP32 WiFi CCTV Camera (ESP32-CAM) DIY Wireless Security Cam

by Max Imagination in Circuits > Cameras

89679 Views, 487 Favorites, 0 Comments

Make an ESP32 WiFi CCTV Camera (ESP32-CAM) DIY Wireless Security Cam

MVI_2226.00_00_27_22.Still005.jpg
DIY WiFi Security Camera ESP32-CAM Rechargeable | Step by step Tutorial

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)

Programming ESP32-CAM

MVI_8457.MOV.00_00_07_13.Still001.jpg
MVI_2226.00_04_11_20.Still013.jpg
MVI_2226.00_02_30_29.Still011.jpg
MVI_2242.MOV.00_00_05_06.Still001.jpg

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.

Making Sure You've Got the "ESP32 .json Link"

MVI_2226.00_02_42_20.Still012.jpg
Preferences tap IDE.JPG

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.

In the Code: Filling in Necessary Parameters

MVI_2226.00_04_22_11.Still017.jpg
MVI_2226.00_04_25_22.Still016.jpg
MVI_2226.00_04_30_16.Still015.jpg
MVI_2226.00_04_38_16.Still019.jpg

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.

Uploading Code to Board

MVI_2226.00_04_53_22.Still021.jpg
Upload.JPG

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

Preparing ESP32-CAM for Use & Getting IP Address

MVI_2226.00_04_48_18.Still020.jpg
MVI_2226.00_03_56_12.Still014.jpg
MVI_2226.00_05_23_20.Still026.jpg
MVI_2226.00_04_57_11.Still022.jpg

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

Opening Up ESP32-CAM's Web-server

MVI_2226.00_05_05_18.Still024.jpg
MVI_2226.00_05_16_01.Still025.jpg

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.

Assembling the DIY Security Camera

MVI_2226.00_05_42_16.Still029.jpg

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)

Enabling Board for an External Antenna

MVI_2226.00_05_47_12.Still030.jpg
MVI_2226.00_05_52_00.Still033.jpg
MVI_2226.00_05_59_04.Still031.jpg
MVI_2226.00_06_00_03.Still032.jpg

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.

Connecting Up the ESP32-CAM's Power Supply

MVI_2226.00_06_15_14.Still035.jpg
MVI_2226.00_06_17_02.Still036.jpg
MVI_2226.00_06_24_27.Still037.jpg

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)

Extending Connections of Components

MVI_2226.00_06_08_21.Still034.jpg
MVI_2226.00_06_50_26.Still039.jpg
MVI_2226.00_07_16_25.Still040.jpg
MVI_2226.00_07_30_11.Still041.jpg

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.

Circuit Diagram

MVI_2226.00_07_33_08.Still042.jpg

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.

Choosing the Right Battery to Fit a Certain Case

MVI_2226.00_08_27_23.Still043.jpg
MVI_2226.00_08_34_04.Still044.jpg
MVI_2226.00_08_46_28.Still045.jpg

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.

Preparing the Hardware to Be Fit Into Its Case

MVI_2226.00_08_52_12.Still046.jpg
MVI_2226.00_08_57_06.Still047.jpg
MVI_2226.00_09_17_04.Still048.jpg

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.

Fitting Things In

MVI_2226.00_09_58_10.Still057.jpg
MVI_2226.00_10_02_24.Still058.jpg
MVI_2226.00_10_04_28.Still060.jpg
MVI_2226.00_10_12_23.Still061.jpg

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)

Weather-proofing

MVI_2226.00_10_17_27.Still062.jpg
MVI_2226.00_10_19_10.Still063.jpg
MVI_2226.00_10_24_26.Still064.jpg
MVI_2226.00_10_46_21.Still069.jpg

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.

Testing the End Product

MVI_2226.00_10_33_17.Still067.jpg
MVI_2226.00_10_35_28.Still068.jpg
MVI_2226.00_10_56_28.Still070.jpg
MVI_2226.00_11_01_13.Still071.jpg

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.

Camera's Live Video Feed Panel

MVI_2226.00_11_05_23.Still072.jpg
MVI_2226.00_11_32_16.Still076.jpg

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.

Making a Wall Mount

MVI_2226.00_12_06_22.Still078.jpg
MVI_2226.00_12_21_24.Still079.jpg
MVI_2226.00_12_24_23.Still080.jpg

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.

Powering the Camera Via USB

MVI_2226.00_11_17_04.Still074.jpg
MVI_2226.00_13_51_10.Still004.jpg
MVI_2226.00_00_06_01.Still007.jpg

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.

Emptying Recorded Footage

MVI_2226.00_05_25_23.Still027.jpg

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".

MVI_2226.00_12_55_15.Still002.jpg
MVI_2226.00_13_13_21.Still083.jpg

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.

MVI_2226.00_00_06_08.Still008.jpg
MVI_2226.00_00_02_19.Still006.jpg
MVI_2226.00_13_17_08.Still084.jpg
MVI_2226.00_12_44_04.Still081.jpg

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