How to make a surveillance using ESP32 Cam + ESP 8266

In this guide. I would like to introduce to you how to make a remote-controlled car with CCTV. Use solid word software to design 3D. DXF. Use CNC laser to cut 3mm mica. The body is assembled from 3mm mica plates. Using ESP 8266 connect to phone via Blynk App. Control the motors by L298N driver circuit. The program is written in C++ language on the Arduino IDE translator. The control interface on the phone is created on the Blynk Web site.

using SolidWorks drawing

file DXF:

Diagram connected wire

code ESP8266

// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
 #define BLYNK_TEMPLATE_ID     "TMPL6TkiMmSlo"
 #define BLYNK_TEMPLATE_NAME   "QuickStart Template"
 #define BLYNK_AUTH_TOKEN "jDnkYYxF_PFr0dZKfLkE37jIe2U4gGPk"
// Comment this out to disable prints and save space
 #define BLYNK_PRINT Serial
 #include <ESP8266WiFi.h>
 #include <BlynkSimpleEsp8266.h>
// #include<Servo.h>
 #define in1 D5
 #define in2 D6
 #define in3 D7
 #define in4 D8
 #define enA D1
 #define enB D2
// Servo servo;
    int x,y;
  char auth[] = BLYNK_AUTH_TOKEN;
// Your Wi-Fi credentials.
// Set password to "" for open networks.
 char ssid[] = "THUC"; 
 char pass[] = "1234";
 int minRange=312;//312
 int maxRange=712;//712
 int speedcar;
   void moveControl(int x, int y)
    {
    //Move Forward
        if(y >= maxRange && x >= minRange && x<= maxRange)
        {
        analogWrite(enA,speedcar);
        analogWrite(enB,speedcar);
        digitalWrite(in1,HIGH);
        digitalWrite(in2,LOW); 
        digitalWrite(in3,LOW); 
        digitalWrite(in4,HIGH); 
        Serial.print("Move Forward=");
        Serial.println(speedcar);
        }
   //Move Forward Right
        else if(x >= maxRange && y >= maxRange)
        {   
          analogWrite(enA,speedcar);
          analogWrite(enB,speedcar);
          digitalWrite(in1,HIGH);
          digitalWrite(in2, LOW); 
          digitalWrite(in3,LOW); 
          digitalWrite(in4,HIGH); 
          Serial.print("Move Forward Right=");
          Serial.println(speedcar);
        }
        //Move Forward Left
        else if(x <= minRange && y >= maxRange)
        {
                   analogWrite(enA,speedcar);
                   analogWrite(enB,speedcar);
                   digitalWrite(in1,HIGH);
                   digitalWrite(in2, LOW); 
                   digitalWrite(in3,LOW);
                   digitalWrite(in4,HIGH); 
                   Serial.print("Move Forward Left=");
                   Serial.println(speedcar);
        }
       //No Move
        else if(y < maxRange && y > minRange && x < maxRange && x > minRange)
        {
                    analogWrite(enA,0);
                    analogWrite(enB,0);
                    digitalWrite(in1,LOW);
                    digitalWrite(in2,LOW); 
                    digitalWrite(in3,LOW); 
                    digitalWrite(in4,LOW);
                    Serial.print("No Move=");
                    Serial.println(speedcar);
        }
       //Move Backward
        else if(y <= minRange && x >= minRange && x <= maxRange)
        {  

                    analogWrite(enA,speedcar);
                    analogWrite(enB,speedcar);
                    digitalWrite(in1,LOW);
                    digitalWrite(in2,HIGH); 
                    digitalWrite(in3,HIGH); 
                    digitalWrite(in4,LOW);
                    Serial.print("Move Backward=");
                    Serial.println(speedcar);
        }
    }
    void setup()
    {
      // Debug console
      Serial.begin(9600);
      Blynk.begin(auth, ssid, pass);
      // timer.setInterval(1000L, myTimerEvent);
      //khai báo các chân  analog điều khiển tốc độ
        pinMode(enA, OUTPUT); 
        pinMode(enB, OUTPUT); 
        pinMode(in1, OUTPUT);
        pinMode(in2 , OUTPUT);
        pinMode(in3, OUTPUT);
        pinMode(in4, OUTPUT);
       // analogWrite(enA,0);
       // analogWrite(enB,0);
  }
  void loop()
    {
      Blynk.run();
      //timer.run();
 }
 BLYNK_WRITE(V0)
    {
        x = param[0].asInt();
        moveControl(x,y);
        Serial.print("X=");
        Serial.print(x);
        Serial.print("Y=");
        Serial.println(y);
     }
    BLYNK_WRITE(V1)
    {
        y = param[0].asInt();
        moveControl(x,y);
        Serial.print("X=");
        Serial.print(x);
        Serial.print("Y=");
        Serial.println(y);    
    }
   // BLYNK_WRITE(V3)
    // {
    //   servo.write(param.asInt());
    // }
   BLYNK_WRITE(V4)
    {
      int speedcar = param.asInt();
      Serial.print("speedcar=");
      Serial.print(speedcar);
      }

Code ESP 32 Cam


/*
  This is a simple MJPEG streaming webserver implemented for AI-Thinker ESP32-CAM and
  ESP32-EYE modules.
  This is tested to work with VLC and Blynk video widget.
  Inspired by and based on this Instructable: $9 RTSP Video Streamer Using the ESP32-CAM Board
  (https://www.instructables.com/id/9-RTSP-Video-Streamer-Using-the-ESP32-CAM-Board/)
  Board: AI-Thinker ESP32-CAM
*/
#include "src/OV2640.h"
#include <WiFi.h>
#include <WebServer.h>
#include <WiFiClient.h>
// Select camera model
//#define CAMERA_MODEL_WROVER_KIT
//#define CAMERA_MODEL_ESP_EYE
//#define CAMERA_MODEL_M5STACK_PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE
#define CAMERA_MODEL_AI_THINKER

#include "camera_pins.h"
#define SSID1 "Ghost Rider"
#define PWD1 "1984Nvdt"
OV2640 cam;

WebServer server(80);
const char HEADER[] = "HTTP/1.1 200 OK\r\n" \
                      "Access-Control-Allow-Origin: *\r\n" \
                      "Content-Type: multipart/x-mixed-replace; boundary=123456789000000000000987654321\r\n";
const char BOUNDARY[] = "\r\n--123456789000000000000987654321\r\n";
const char CTNTTYPE[] = "Content-Type: image/jpeg\r\nContent-Length: ";
const int hdrLen = strlen(HEADER);
const int bdrLen = strlen(BOUNDARY);
const int cntLen = strlen(CTNTTYPE);

void handle_jpg_stream(void)
{
  char buf[32];
  int s;
  WiFiClient client = server.client();
  client.write(HEADER, hdrLen);
  client.write(BOUNDARY, bdrLen);
  while(true)
  {
    if (!client.connected()) break;
    cam.run();
    s = cam.getSize();
    client.write(CTNTTYPE, cntLen);
    sprintf( buf, "%d\r\n\r\n", s );
    client.write(buf, strlen(buf));
    client.write((char *)cam.getfb(), s);
    client.write(BOUNDARY, bdrLen);
  }
}
const char JHEADER[] = "HTTP/1.1 200 OK\r\n" \
                       "Content-disposition: inline; filename=capture.jpg\r\n" \
                       "Content-type: image/jpeg\r\n\r\n";
const int jhdLen = strlen(JHEADER);
void handle_jpg(void)
{
  WiFiClient client = server.client();
  cam.run();
  if (!client.connected()) return;
  client.write(JHEADER, jhdLen);
  client.write((char *)cam.getfb(), cam.getSize());
}
void handleNotFound()
{
  String message = "Server is running!\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET) ? "GET" : "POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  server.send(200, "text / plain", message);
}
void setup()
{
  Serial.begin(115200);
  //while (!Serial);            //wait for serial connection.
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;
  // Frame parameters
  //  config.frame_size = FRAMESIZE_UXGA;
  config.frame_size = FRAMESIZE_QVGA;
  config.jpeg_quality = 12;
  config.fb_count = 2;
#if defined(CAMERA_MODEL_ESP_EYE)
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
#endif
  cam.init(config);
  IPAddress ip;
  WiFi.mode(WIFI_STA);
  WiFi.begin(SSID1, PWD1);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(F("."));
  }
  ip = WiFi.localIP();
  Serial.println(F("WiFi connected"));
  Serial.println("");
  Serial.println(ip);
  Serial.print("Stream Link: http://");
  Serial.print(ip);
  Serial.println("/mjpeg/1");
  server.on("/mjpeg/1", HTTP_GET, handle_jpg_stream);
  server.on("/jpg", HTTP_GET, handle_jpg);
  server.onNotFound(handleNotFound);
  server.begin();
}
void loop()
{
  server.handleClient();
}

video tutorial

Comments

Leave a Reply

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