Introduction: ESP32 Security Camera

About: Self-made, well made

I had few ESP32-Cameras laying around and I did not have real ideas what to do with them. After some research I found an Instructable how to combine the camera module with servos. Like this the camera could be turned and tilted like a real security camera.

As this idea sounded very interesting, I started to look deeper into the topic. The presented camera tilting system in the Instructables was not what I liked. Thus, I redesigned it.

Hier is the original Instructable: Link

Supplies

What you need:

  • 1x ESP32-Camera
  • 2x SG-90 Servos + horns and screws
  • 4x M3 10mm screws
  • 1x M3 nut
  • 2x M2 max 10mm screws
  • Wires to connect everything
  • Power cable
  • A way to program the ESP32

Step 1: Printing

Building it up is relatively straightforward and I assume one can assume what goes where. Each part is required and used once. “ServoHolder1” has a support part that needs be break off next to the teeth. Like this none of the parts require a support. “ServoHolder2” has several holes to add additional M3 screws to hold the wires. The “CamerCover2” presses the camera against the frame, thus the M2 screws are required, otherwise the camera is not really fixed.

Step 2: Coding

Programming the module is not very convenient, however it is doable with a separate module. I had to modify the found code to adjust the possible turning angles. It took some time before I figured out where in the code the limits were set. Additionally, the original code used only one servo, although they show two of them. I had to adjust the code little bit to add my second servo.

Lines 55-56 (.ino file) define the servo pins:

const int ServoPin = 2; // IO2 up-down servo

const int ServoPin1 = 14; // IO14 left-right servo

The most important lines are in “app_httpd.cpp”:

  • Line 278 – Define how much your camera can turn left-right.
    Here adjust the min=”??” max=”??” value=”??”
    with the ones you have. It is a trial-and-error work and it is useful to use the Serial reading to define the limits. I set the limits at first relatively low/high and then found out the limits. It is better to start slowly and not with some extremes. To prevent errors, I introduced the limits additionally in lines 209-210. You have to comment these lines out or adjust it according to your limits.
  • Line 280 – Define how much your camera can turn up-down.
    Here adjust the min=”??” max=”??” value=”??”
    with the values you have. It is a trial-and-error work and it is useful to use the Serial reading to define the limits. I set the limits at first relatively low/high and then found out the limits. It is better to start slowly and not with some extremes. To prevent errors, I introduced the limits additionally in lines 216-217. You have to comment these lines out or adjust it according to your limits.

Step 3: Results

The Camera module itself does not have very high quality. Nevertheless, it is cheap and allows easy usage for different projects. The camera can be turned left and right, additionally tilting up and down is possible. The upwards movement is limited due to the narrow distance between the housing and the next servo. That could be improved by using larger gears, however that would require some redesign.

I used an USB cable to power everything and the used cable is slightly too thick. It is sticking out way more than I expected. Still, it is a minor issue.

In the end the camera works and one can adjust the viewing direction directly from the browser. If the set Wi-Fi Net is not available, the module generates its own and one can connect to it. The HTTP user interface is simple and easy to use.

Hopefully somebody finds it useful.