RoboticsIntermediatePRJ-015

ESP32-CAM Surveillance Robot

A Wi-Fi robot you drive from your phone’s browser while it streams live video.

Built and tested by Akhil K Madanan · Industrial Robotics Institute

Circuit diagram of the ESP32-CAM Surveillance Robot using ESP32-CAM (AI-Thinker)
Circuit diagram · ESP32-CAM (AI-Thinker)
LevelIntermediate
Build time4–5 hours
BoardESP32-CAM (AI-Thinker)
Parts9 components

What is the ESP32-CAM Surveillance Robot?

A mobile surveillance robot that moves around while streaming live video over Wi-Fi. The ESP32-CAM captures video and hosts a small web server. Open the robot’s IP address in a browser to get a control page with movement buttons and the camera stream; each button press drives the motors through an L298N motor driver.

How it works

  1. The ESP32-CAM connects to your Wi-Fi network.
  2. It starts a web server that hosts the control page.
  3. You open the robot’s IP address in a browser on the same network.
  4. Pressing Forward, Back, Left, Right or Stop sends a command to the ESP32.
  5. The ESP32 reads the command and sets the L298N inputs to drive the two motors.
  6. The camera streams live video to the same page.

Parts list

ComponentQty
ESP32-CAM Module1
FTDI Programmer1
L298N Motor Driver1
BO Gear Motors2
Robot Chassis1
Wheels and Caster Wheel1 set
18650 Lithium Batteries2
2-cell 18650 Battery Holder with Switch1
Jumper WiresAs needed

Software

  • Arduino IDE
  • ESP32 board package
  • WiFi library

Wiring and connections

FromConnect to
L298N IN1 (left motor)GPIO12
L298N IN2 (left motor)GPIO13
L298N IN3 (right motor)GPIO14
L298N IN4 (right motor)GPIO15
Battery +L298N 12V
Battery −L298N GND
ESP32-CAM 5VL298N 5V
ESP32-CAM GNDL298N GND

How to build the ESP32-CAM Surveillance Robot

  1. Mount the two BO motors, wheels and caster on the chassis, and fix the battery holder.
  2. Wire both motors to the L298N outputs and the battery pack to the L298N 12V and GND terminals.
  3. Connect L298N IN1–IN4 to ESP32-CAM GPIO12, 13, 14 and 15, and power the ESP32-CAM from the L298N 5V pin.
  4. Enter your Wi-Fi name and password in the code.
  5. Upload the code to the ESP32-CAM with the FTDI programmer from the Arduino IDE.
  6. Open the Serial Monitor at 115200 baud and press reset; note the IP address it prints.
  7. Connect your phone or laptop to the same Wi-Fi and open that IP address in a browser.
  8. Use the on-screen buttons to drive the robot while watching the live video.

ESP32-CAM Surveillance Robot code

Complete, tested Arduino C++ code for this project. Copy it into Arduino IDE and upload it to the ESP32-CAM (AI-Thinker).

#include <WiFi.h>

const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";

#define IN1 12
#define IN2 13
#define IN3 14
#define IN4 15

WiFiServer server(80);

void setup()
{
  Serial.begin(115200);

  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
  }
  Serial.println("WiFi connected");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());

  server.begin();
}

void forward()  { digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW);  digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW);  }
void backward() { digitalWrite(IN1,LOW);  digitalWrite(IN2,HIGH); digitalWrite(IN3,LOW);  digitalWrite(IN4,HIGH); }
void left()     { digitalWrite(IN1,LOW);  digitalWrite(IN2,HIGH); digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW);  }
void right()    { digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW);  digitalWrite(IN3,LOW);  digitalWrite(IN4,HIGH); }
void stopRobot(){ digitalWrite(IN1,LOW);  digitalWrite(IN2,LOW);  digitalWrite(IN3,LOW);  digitalWrite(IN4,LOW);  }

void loop()
{
  WiFiClient client = server.available();
  if (client)
  {
    String request = client.readStringUntil('\r');

    if (request.indexOf("/forward") != -1) forward();
    else if (request.indexOf("/back") != -1) backward();
    else if (request.indexOf("/left") != -1) left();
    else if (request.indexOf("/right") != -1) right();
    else stopRobot();

    client.println("HTTP/1.1 200 OK");
    client.println("Content-type:text/html");
    client.println();
    client.println("<html><body style='text-align:center;'>");
    client.println("<h2>ESP32 Surveillance Robot</h2>");
    client.println("<img src='http://" + WiFi.localIP().toString() + ":81/stream' width='320'>");
    client.println("<br><br><a href='/forward'><button>Forward</button></a><br><br>");
    client.println("<a href='/left'><button>Left</button></a>");
    client.println("<a href='/stop'><button>Stop</button></a>");
    client.println("<a href='/right'><button>Right</button></a><br><br>");
    client.println("<a href='/back'><button>Backward</button></a>");
    client.println("</body></html>");
    client.stop();
  }
}

Real-world uses

  • Home and office security
  • Remote inspection
  • Monitoring hard-to-reach areas
  • Learning Wi-Fi robotics

Frequently asked questions

What is a ESP32-CAM Surveillance Robot?

A mobile surveillance robot that moves around while streaming live video over Wi-Fi. The ESP32-CAM captures video and hosts a small web server.

What components are needed for the ESP32-CAM Surveillance Robot?

You need: ESP32-CAM Module (1), FTDI Programmer (1), L298N Motor Driver (1), BO Gear Motors (2), Robot Chassis (1), Wheels and Caster Wheel (1 set), 18650 Lithium Batteries (2), 2-cell 18650 Battery Holder with Switch (1), Jumper Wires. Software: Arduino IDE, ESP32 board package, WiFi library.

Is the ESP32-CAM Surveillance Robot project good for beginners?

It is rated intermediate and takes about 4–5 hours to build, using the ESP32-CAM (AI-Thinker). The guide on this page explains every connection and step.

Where can I get the code for the ESP32-CAM Surveillance Robot?

The complete, tested Arduino C++ code is free on this page. Copy it into Arduino IDE and upload it to the board.

Can I buy a kit for the ESP32-CAM Surveillance Robot?

Yes. IRI sells a kit with the parts for this project (PRJ-015). Message IRI on WhatsApp at +91 86060 82634 for the kit price and delivery details.

Industrial Robotics Institute
Logo