ESP32 CAM Based Surveillance Robot using Arduino IDE

ESP32 CAM- Surveillance Robot using Arduino IDE

Previously we built a Wi-Fi controlled robot using NodeMCU, this time we are attaching a camera with the robot to make it a surveillance robot car. This web controlled surveillance car can be easily built using the ESP32-CAM module. Apart from the ESP32-Camera module, here we will use two DC motor with Robot chassis and L293D motor driver module to build this Robotic car. ESP32 is one of the most popular boards to build IoT based projects, check all the ESP32 based IoT projects here.


The AI-Thinker ESP32-CAM module comes with an ESP32-S chip, a very small size OV2640 camera and a microSD card slot. MicroSD card slot can be used to store images taken from the camera. Here HTTP communication protocol will be used to receive video streaming from the OV2640 camera over the web browser. The web page will also have buttons to move the car in Left, Right, Forward and reverse directions as shown in the image above.


Components Required

  • ESP32-CAM
  • FTDI Programmer
  • DC Motors (2)
  • Motor Driver (L293D)
  • Battery


ESP32 CAM Module

Also, download and install the Arduino IDE to upload the into ESP32.


Circuit Diagram

All the connections for ESP32- Surveillance Camera is given below:     

ESP32 CAM- Surveillance Camera Robot Circuit Diagram

ESP32-CAM doesn’t have a USB connector, so you need an FTDI board to upload the code into ESP32-CAM. VCC and GND pin of ESP32 is connected with the VCC and GND pin of the FTDI board. Tx of and Rx of ESP32 is connected with Rx and Tx of the FTDI board. Two DC motors are connected to ESP32 through the L293D module. Module pins are connected to IO4, IO2, IO14, and IO15 pins of ESP32.

Note: Before uploading the code, connect the IO0 to the ground. IO0 determines whether the ESP32 is in flashing mode or not. When GPIO 0 is connected to GND, the ESP32 is in flashing mode.

We built a robot by using a ready-made robot chassis, wheels, and DC motors. We used a battery to power the motor drive module and ESP32-CAM. This is how my surveillance robot looks like:

ESP32 CAM Surveillance Robot Setup


Installing ESP32 Board on Arduino IDE

We will program the ESP32-CAM using Arduino IDE. For that, we have to install the ESP32 add-on on Arduino IDE.

To install the ESP32 board in your Arduino IDE, go to File> Preferences

Installing ESP32 Board on Arduino IDE


Now copy the below link and paste it into the “Additional Board Manager URLs” field, as shown in the image below. Then, click the “OK” button:

Installing ESP32 Board on Arduino IDE


Now go to Tools > Board > Boards Manager

Installing ESP32 Board on Arduino IDE


In Boards Manager search for ESP32 and install the “ESP32 by Espressif Systems“.

Installing ESP32 Board on Arduino IDE


Code Explanation

This ESP32 Surveillance Camera has a total of four code files that are attached at the end of the project and also can be downloaded from here. One is the main code file for camera and motors, and the other three codes are for web page, camera index, and camera pins.

Begin the program by including header files and selecting the right camera model. In the code, three camera models are defined. Uncomment the camera model that you are using. Here we have used the AI Thinker camera model that comes with ESP32.

#include "esp_camera.h"
#include <WiFi.h>
#include "camera_pins.h"
// Select camera model


Enter the Wi-Fi name and password of the network.

const char* ssid = "WiFi Name";
const char* password = "Password";


The four pins 4, 2, 14, and 15 of the ESP32 are used to control the DC motors.

extern int leftmotor1 =  4;
extern int leftmotor2 = 2;
extern int rightmotor1 = 14;
extern int rightmotor2 = 15;


Inside the void setup loop, begin the serial monitor and set the DC motors initially low.

void setup() {
  digitalWrite(leftmotor1, LOW);
  digitalWrite(leftmotor2, LOW);
  digitalWrite(rightmotor1, LOW);
  digitalWrite(rightmotor2, LOW)
Define the Pins of DC motors as Output.
pinMode(leftmotor1, OUTPUT);
pinMode(leftmotor2, OUTPUT);
pinMode(rightmotor1, OUTPUT);
pinMode(rightmotor2, OUTPUT);


Connect to the Wi-Fi using the given credentials and wait for the confirmation

WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED) {
  Serial.println("WiFi connected");


Programming ESP32 for Surveillance Robot

To upload the code, connect the FDTI board to your laptop and select the ‘ESP32 Wrover Module’ as your board. Also, change the other settings according to this picture:

Programming ESP32 for Surveillance Robot


Before uploading the code, press the ESP32 reset button and then click on the upload button.

Note: If you get errors while uploading the code, check that IO0 is connected to GND, and you have selected the right settings in the Tools menu.

After uploading the code, disconnect the IO0 and GND pin. Then open the serial monitor and change the baud rate to 115200. After that press the ESP32 reset button, it will print the ESP IP address and port no on the serial monitor.

ESP32 CAM- Surveillance Robot IP Address


Now to access the Webpage for ESP32 video streaming and car controls, navigate to your browser and enter the ESP IP address. It will take you to the web page.

ESP32 CAM- Surveillance Robot Controllers

ESP32 CAM Based Surveillance Robot Working


From here, you can control the car using the control buttons while receiving video streaming from a web browser.

This is how you can make a surveillance robot using ESP32-CAM. Complete code and demonstration video is given below. Code folder has four codes in which the first code is for ESP32 and peripherals connected to ESP32; the second code is for the HTML web page, the third code is for camera index, and the fourth code is for camera pins.

Download the complete code files from here and check the demonstration video below.



i used tthis but i used 4 motors i bought a 4*4 chassis from amazon 20$ and i 3d printed a 86ish datsun/nissan truck to fit chassis it works well now ive modified the truck now has a tank turet that will actully fire airsoft pellets so im here to ask how i can configure a servo motor and trigger switch i added the code but the app doesnt have buttons for servo and trigger how do i modify app to have servo left and right and a trigger to fire pellets in the app and do i need to be on the same wifi to view camera because my home sercurity cams i can view from anywhere id like to do that with this vehicale so if you can point me in the right direction it would be much appreciated and thanks in advance have a great day

Induce you tried the new pull bar product? I'm undeviating you can manufacture the aright mood with our CBD pen. Made with virgin cannabis lubricator extracted from organically grown hemp, our CBD oil vaporizer accoutrements is befitting conducive to anyone who is distressed or needs workers to balmy down and focus. If swiftly this mechanism does not slow working, then require balm you, the actions that you need to do are described in detail.

There are some interesting points in time in this article however I don抰 know if I see all of them middle to heart. There may be some validity but I will take maintain opinion until I look into it further. Good article , thanks and we would like extra! Added to FeedBurner as properly

I discovered your weblog website on google and examine a couple of of your early posts. Proceed to keep up the very good operate. I simply further up your RSS feed to my MSN Information Reader. Seeking ahead to studying more from you later on!?

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.