problem with serial communication between arduino and esp32

hi guys i am working with esp32 and arduino serial communication in which i want to send data from esp32 to arduino via rx and tx pins and the problem was i cannot use softwareserial library in esp32 so i tried serial2 and it worked but now the new problem is whenever i connect my esp to arduino and connect arduino to computer i am not able to read the data in serial monitor

//here is my esp32 code
#define RXD2 16
#define TXD2 17 
void setup() {
  
  //Serial S Begin at 9600 Baud
  Serial.begin(9600);
  Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2); 
}

void loop() {
  Serial2.println("avanish pratap");
  Serial2.write("avanish pratap");
  delay(1000);
}
// here is my arduino code
void setup()
{
  Serial.begin(9600);
}
void loop(){
  Serial.print("Recieved data");
  Serial.println(Serial.readString());

  
 
  delay(500);
}

THANKS IN ADVANCE

How many serial ports does the Uno have? 1. What's that 1 Uno serial port used for? The answer to that question, widely available, will be why the thing don't do anymore when you plug into the UNO USB thingy.

You could try using software serial on the Uno to fix the matter.

BTW, you have wires going from a ESP32 to a Uno without level shifters? ESPRESSIF has removed all references that the ESP32 is 5V tolerant.

And my own interest, why use an Uno when you have an ESP32?

i jst want to ask a question that does serial port on arduino work wen i connect both esp32 and open serial monitior in pc simultaneously

because when i connect rx tx pin of esp to arduino the serial monitor freezes and when i remove the pin serial monitor again starts working

avanishpratap:
i jst want to ask a question that does serial port on arduino work wen i connect both esp32 and open serial monitior in pc simultaneously

because when i connect rx tx pin of esp to arduino the serial monitor freezes and when i remove the pin serial monitor again starts working

Haven't you answered your own question ?

Use SoftwareSerial on the Uno to communicate with the ESP32 (at 9600 baud) and leave the Rx and Tx pins free for communication between the Uno and the Serial Monitor.

...R

i am using uno because i have project in which already uno is embedded and i wnat to add wifi contro in it and for now i have only esp32 as wifi module

sorry to say that there is no difference after adding software serial library

You MUST use a level shifter to connect TX on a 5V Arduino to RX on the ESP.

avanishpratap:
sorry to say that there is no difference after adding software serial library

You need to post the latest version of your program in your next Reply so we can exactly what you did.

Also make a pencil drawing showing how you have everything connected and post a photo of the drawing. Please DO NOT use Fritzing. See this Simple Image Posting Guide

...R