ESP32 guide with arduino Mega

I'm making a safe with arduino mega. The safe is meant to scan a fingerprint then open safe based on the fingerprint. I also wanted to add a camera in case of false fingerprints or user wants to check safe status. I'm pretty new with esp32. I followed a yt tutorial-https://www.youtube.com/watch?v=7-3piBHV1W0&t=116s&pp=ygUWZXNwMzIgd2l0aCBhcmR1aW5vIHVubw%3D%3D
Problems- 1. When I use the esp32 with an Arduino uno, the camera link works and I can see camera footage, but when I plug it into the Arduino mega(connected to all the other components of the safe, fingerprint scanner, lcd, solenoid, buttons etc., it doesn't work for some reason)
2. I'm also trying to like be able to send the url of the camera to the mega, so it can print it on the lcd for users to see, tried some stuff like sending to serial monitor2 or serial monitor1, but it doesn't work either, and the videos i watched use a different serial monitor like serial1, but for cam i use normal serial so don;t know if it would be possible

Code for mega:

#include <Wire.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11);
hd44780_I2Cexp lcd_1;


// Fingerprint Sensor Setup
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

// Pin and Variable Setup
const int button = 4;
int button_state;
int sensorValue = 0;

String print0 = "Welcome to safe";
String print1 = "Open safe      ";
String print2 = "View Camera URL";
String URL = "";
int Gui_status = 0;
bool matchfound = 0;
bool discovered = 0;

int solenoid = 13;
const int sensor_pin = A0;  
int sensor;					
const int threshold = 10;  

void setup() {
  lcd_1.begin(16, 2);
  lcd_1.clear();
  lcd_1.print("hello world");
  pinMode(A5, INPUT);
  pinMode(solenoid, OUTPUT);
  pinMode(button, INPUT_PULLUP);
  Serial.begin(9600);
  Serial2.begin(115200);
  delay(2000);          // Wait for ESP32-CAM to initialize
  while (!Serial)
    ;  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit finger detect test");
  
  finger.begin(57600);
  delay(5);
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    lcd_1.print("Sensor not found");
    while (1) { delay(1); }
  }

  Serial.println(F("Reading sensor parameters"));
  finger.getParameters();
  Serial.print(F("Status: 0x"));
  Serial.println(finger.status_reg, HEX);
  Serial.print(F("Sys ID: 0x"));
  Serial.println(finger.system_id, HEX);
  Serial.print(F("Capacity: "));
  Serial.println(finger.capacity);
  Serial.print(F("Security level: "));
  Serial.println(finger.security_level);
  Serial.print(F("Device address: "));
  Serial.println(finger.device_addr, HEX);
  Serial.print(F("Packet len: "));
  Serial.println(finger.packet_len);
  Serial.print(F("Baud rate: "));
  Serial.println(finger.baud_rate);
  
   finger.getTemplateCount();

  if (finger.templateCount == 0) {
    Serial.print("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.");
    lcd_1.print("No prints stored");
  } else {
    Serial.println("Waiting for valid finger...");
    Serial.print("Sensor contains ");
    Serial.print(finger.templateCount);
    Serial.println(" templates");
  }
}

void loop() {
  if (Serial2.available()) {
    Serial.println("message received: ");
    Serial.println(Serial2.readString());
  } 
  matchfound = 0;
  button_state = digitalRead(button);
  sensorValue = analogRead(A5);
  lcd_1.setCursor(0, 1);
  sensor = analogRead(sensor_pin);   
  if((sensor>threshold) && (discovered == 0)){ 
    Serial.println("Safe has been discovered"); 
    discovered = 1;
  }  
  
  if(sensorValue <= 680){
    lcd_1.clear();
    lcd_1.print(print0);
    Gui_status = 0;
  }
  else if ((sensorValue <= 850) && (sensorValue > 680)){
    lcd_1.clear();
    lcd_1.print(print1);
    Gui_status = 1;
    if(button_state == LOW){
      lcd_1.setCursor(0, 1);
      lcd_1.clear();
      lcd_1.print("Input finger");
      for (int i = 0; i < 30; i++) {
        getFingerprintID();
        if (matchfound == 1) {
          digitalWrite(solenoid, HIGH);
          delay(10000);
          digitalWrite(solenoid, LOW);
          break;
          }
        delay(1000);
      }
      lcd_1.clear();
    }
  }
  else if (sensorValue > 850){
    lcd_1.clear();
    lcd_1.print(print2);
    Gui_status = 2;
    if(button_state == LOW){
      lcd_1.clear();
      lcd_1.setCursor(0, 0);
      lcd_1.print("IP Address:");
      lcd_1.setCursor(0, 1); 
      lcd_1.print(URL);  // Display IP on the LCD
      delay(3000);
      lcd_1.clear();
        
    }
  }
  delay(100);
}

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      lcd_1.clear();
      lcd_1.print("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      lcd_1.clear();
      lcd_1.print("No finger seen");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Error, try again");
      lcd_1.clear();
      lcd_1.print("Error, try again");
      return p;
    default:
      Serial.println("Unknown error");
      lcd_1.clear();
      lcd_1.print("Error, try again");
      return p;
  }
  
  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      lcd_1.clear();
      lcd_1.print("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
    case FINGERPRINT_PACKETRECIEVEERR:
    case FINGERPRINT_FEATUREFAIL:
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Error, try again");
      lcd_1.clear();
      lcd_1.print("Error, try again");
      return p;
    default:
      Serial.println("Unknown error");
      lcd_1.clear();
      lcd_1.print("Error, try again");
      return p;
  }
  
  p = finger.fingerSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
    lcd_1.clear();
    lcd_1.print("Match found");
    matchfound = 1;
    delay(5000);
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    lcd_1.clear();
    lcd_1.print("Error, try again");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    lcd_1.clear();
    lcd_1.print("No match found");
    delay(5000);
    return p;
  } else {
    Serial.println("Unknown error");
    lcd_1.clear();
    lcd_1.print("Error, try again");
    return p;
  }

  // found a match!
  Serial.print("Found ID #");
  Serial.print(finger.fingerID);
  Serial.print(" with confidence of ");
  Serial.println(finger.confidence);

  return finger.fingerID;
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK) return -1;

  p = finger.image2Tz();
  if (p != FINGERPRINT_OK) return -1;

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK) return -1;

  // found a match!
  Serial.print("Found ID #");
  Serial.print(finger.fingerID);
  Serial.print(" with confidence of ");
  Serial.println(finger.confidence);
  return finger.fingerID;
}

code for esp32:

#include "esp_camera.h"
#include <WiFi.h>

//
// WARNING!!! PSRAM IC required for UXGA resolution and high JPEG quality
//            Ensure ESP32 Wrover Module or other board with PSRAM is selected
//            Partial images will be transmitted if image exceeds buffer size
//
//            You must select partition scheme from the board menu that has at least 3MB APP space.
//            Face Recognition is DISABLED for ESP32 and ESP32-S2, because it takes up from 15
//            seconds to process single frame. Face Detection is ENABLED if PSRAM is enabled as well

// ===================
// Select camera model
// ===================
//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
//#define CAMERA_MODEL_ESP_EYE  // Has PSRAM
//#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
//#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM
//#define CAMERA_MODEL_M5STACK_CAMS3_UNIT  // Has PSRAM
#define CAMERA_MODEL_AI_THINKER // Has PSRAM
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
//#define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM
// ** Espressif Internal Boards **
//#define CAMERA_MODEL_ESP32_CAM_BOARD
//#define CAMERA_MODEL_ESP32S2_CAM_BOARD
//#define CAMERA_MODEL_ESP32S3_CAM_LCD
//#define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM
//#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM
#include "camera_pins.h"

// ===========================
// Enter your WiFi credentials
// ===========================
const char *ssid = "Flagship-Homes_Tripos-Court";
const char *password = "F1@95hIpcOURt";

void startCameraServer();
void setupLedFlash(int pin);

#define RXp2 16
#define TXp2 17
void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  Serial.println();
  

  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_sccb_sda = SIOD_GPIO_NUM;
  config.pin_sccb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.frame_size = FRAMESIZE_UXGA;
  config.pixel_format = PIXFORMAT_JPEG;  // for streaming
  //config.pixel_format = PIXFORMAT_RGB565; // for face detection/recognition
  config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
  config.fb_location = CAMERA_FB_IN_PSRAM;
  config.jpeg_quality = 12;
  config.fb_count = 1;

  // if PSRAM IC present, init with UXGA resolution and higher JPEG quality
  //                      for larger pre-allocated frame buffer.
  if (config.pixel_format == PIXFORMAT_JPEG) {
    if (psramFound()) {
      config.jpeg_quality = 10;
      config.fb_count = 2;
      config.grab_mode = CAMERA_GRAB_LATEST;
    } else {
      // Limit the frame size when PSRAM is not available
      config.frame_size = FRAMESIZE_SVGA;
      config.fb_location = CAMERA_FB_IN_DRAM;
    }
  } else {
    // Best option for face detection/recognition
    config.frame_size = FRAMESIZE_240X240;
#if CONFIG_IDF_TARGET_ESP32S3
    config.fb_count = 2;
#endif
  }

#if defined(CAMERA_MODEL_ESP_EYE)
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
#endif

  // camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    return;
  }

  sensor_t *s = esp_camera_sensor_get();
  // initial sensors are flipped vertically and colors are a bit saturated
  if (s->id.PID == OV3660_PID) {
    s->set_vflip(s, 1);        // flip it back
    s->set_brightness(s, 1);   // up the brightness just a bit
    s->set_saturation(s, -2);  // lower the saturation
  }
  // drop down frame size for higher initial frame rate
  if (config.pixel_format == PIXFORMAT_JPEG) {
    s->set_framesize(s, FRAMESIZE_QVGA);
  }

#if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM)
  s->set_vflip(s, 1);
  s->set_hmirror(s, 1);
#endif

#if defined(CAMERA_MODEL_ESP32S3_EYE)
  s->set_vflip(s, 1);
#endif

// Setup LED FLash if LED pin is defined in camera_pins.h
#if defined(LED_GPIO_NUM)
  setupLedFlash(LED_GPIO_NUM);
#endif

  WiFi.begin(ssid, password);
  WiFi.setSleep(false);

  Serial.print("WiFi connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  startCameraServer();

  Serial.print("Camera Ready! Use 'http://");
  Serial.print(WiFi.localIP());
  Serial.println("' to connect");     
  Serial2.begin(115200, SERIAL_8N1, RXp2, TXp2);

}

void loop() {
  delay(10000);
  Serial2.println("HELLO");
}


Why use SoftwareSerial on a Mega with three additional hardware UARTs?

Please check https://docs.arduino.cc/learn/built-in-libraries/software-serial/ and pay attention to the pins that are supported by the Mega for SoftwareSerial.

Hi, thx for that, i didn't know cuz like it came in a library, didn't want to mess it up. So like, I read the link u gave thx, it ssid a disadvantage is that- * If using multiple software serial ports, only one can receive data at a time. So i'm gonna change it from software serial like u said. But like I don't really know how to do that and not mess the library up, could you please help?

Anyone know how to help me with the esp32 to take video and also send message to arduino mega problem?