Communication between NodeMCU esp8266 and Arduino Mega 2560

Hi guys
I have been trying to set serial communication between NodeMCU ESP8266 and Arduino Mega 2560(clone).
I found out how to do that on this website: Serial Communication between NodeMCU and Arduino - Arduino Project Hub.

But i wanted it in reverse so ESP will send something to arduino and when arduino will receive something, it puts that into some variable and then for example turn on a led.

But I have one trouble. I cannot convert received text from serial into any variable cause it only displays 1 or some wierd characters.
Can somebody help me with this?

Here is code for ESP8266:

void setup() {

void loop() { 



And here is Arduino code:

void setup(){
  pinMode(13, OUTPUT);
/*while (!Serial1) {
    ; // wait for serial port to connect. Needed for native USB port only
void loop()
  if (Serial1.available()) {

  int str =;
    digitalWrite(13, HIGH);
    digitalWrite(13, LOW);

On arduino i have wires on RX1, TX1, PMW port 13 with ground and one ground is directly connected to ESP
On ESP i have only RX connected to TX1 and TX to RX1 and also that ground.

Thanks for any help :slight_smile:

you send '1' and test 1

Yeah that is mistake but it is not reason why it is not working....i have tried it different times with "", '', or just in () but still doesnt work..