Pan and Tilt Control for an ESP32-CAM


Mounting an ESP32-CAM into a pan and tilt platform with a mobile phone touch interface to control and view the video stream.

This servo part of this project was much harder to make work than with other ESP32 modules. The ESP32-CAM has limited resources available and at every turn it presented a new problem!

With a standard ESP32, controlling servo motors is easy using the ESP32Servo library. For example this pan and tilt sketch controls the 3D printed pan and tilt platform below. You can even power the servos from the 5v pin of the micro-controller.

Lolin ESP32 Pan and Tilt

Attempting to use this library with the ESP32-CAM however led to instant hangs. From my experiments it appears there is a clash on the channels. I found some different code that allows the channels to be chosen and after a few tests I found I could use channels 2 and 4 with the ESP32-CAM.

Mounting the ESP32-CAM in a pan and tilt platform was also a bit tricky. In the end I 3D printed some parts and glued and bolted it together. It doesn’t look great and could do with being designed from the ground up but this is just a proof of concept for later projects so it doesn’t matter

ESP32-CAM Pan and Tilt Platform

I also tried various web server libraries and the ESPAsyncServer library seemed to work the best. I also moved to WebSockets for the data transfer because it seemed to be more efficient and not queue up requests from the mobile phone.

ESP32-CAM Pan and Tilt Wiring Diagram

ESP32-CAM Pan Tilt Code

If you need help with the ArduinoWebSockets or ESPAsyncWebServer libraries please see this tutorial:

Demonstration Video

I got variable results from the ESP32-CAM. Sometimes it was as fluid as the Lolin in the video below and other times it was quite jerky. I don’t know if this is an issue with (my) Wi-Fi or if the data transfer from the video overwhelms the web socket servo control data.


Lolin32 Pan and Tilt Platform:
ESP32-CAM Pan Tilt with Servos:
Touch Interface:

7 Replies to “Pan and Tilt Control for an ESP32-CAM”

  1. rob says:

    Do you think it would be possible to overlay the pan tilt control on top of the camera image, a bit like this

    1. WordBot says:

      I looked at the Github quickly and it looks like he’s using HTML Canvas to draw the interface on top of the video. This could be one approach. It might also work using CSS Z-Index to layer the control with a transparent background on top of the video.

  2. Enn Ellandi says:

    I made a little investigation abd foun out that this part on ESP32 Cam code is preventing Servo library to work:

    // camera init
    esp_err_t err = esp_camera_init(&config);
    if (err != ESP_OK) {
    Serial.printf(“Kaamera init viga 0x%x”, err);

    sensor_t * s = esp_camera_sensor_get();
    s->set_framesize(s, FRAMESIZE_SVGA);

    1. WordBot says:

      It should be OK. Which camera are you using?

  3. Petko Petkov says:

    Hello my friend!!!
    I am quite a beginner and I would very much like to carry out your project. Can you send me screenshots of Arduino ID to learn out which sketch you use, which board, which file (.in) because this one is here (.cpp) and only I can’t add it.
    I apologize for my bad English !!!
    Thank you very much !!!

    1. WordBot says:

      Hi, everything is in the tutorial. You can use any ESP32 board. The code in the tutorial is an .ino file so you just paste it into a new Sketch in the Arduino IDE.

  4. Petko Petkov says:

    It worked….. 🙂 Supeeeerrrrrr !!!
    Thank you so much!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

scroll to top