Controlling relays connected to arduino Mega by sending a high signal from nodemcu esp8266

Hey Guys I’m working on Garden monitoring and control project where in my project, I’m using an Arduino Mega to do all local control for 16 relay but applying the control by using Node MCU to send a high signal once the button on Cayenne dashboard is toggled to send a HIGH single from D4 pin on the Node MCU board which will be read by the Arduino mega to shutdown all the relays.

so now my problem is to find the proper way to write the simple code for generating a HIGH output from the Node MCU board.

the following is my Arduino IDE script
//-------------------------------------------------------

//—Publishing Monitoring station readings on Cayenne MQTT

// Defining Reqired libraries
#include <CayenneMQTTESP8266.h>
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <SimpleDHT.h>

int pinDHT22 = D7; // Initalizing DHT sensor pin
SimpleDHT22 dht22(pinDHT22);

int outPin = D4;

//================================
// for DHT22,
// VCC: 3.3V
// GND: GND
// DATA: 7
//================================

float temperature = 0;
float humidity = 0;
int Dewpoint = 0;

char ssid = “Digital Signage”;
char password = “dsdsds123”;

char username = “d8790590-49aa-11eb-a2e4-b32ea624e442”;
char mqtt_password = “3b6664bbd96e6465aea585ccdcfb9be6c3eeb790”;
char client_id = “e6aee4c0-4a51-11eb-b767-3f1a8f1211ba”;

void setup()
{
Cayenne.begin(username, mqtt_password, client_id);
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
pinMode(outPin, OUTPUT);
Serial.begin(9600);
delay(1500);

}
void loop()
{

Serial.println("=================================");
Serial.println(“Sample DHT22…”);

Cayenne.loop();
//---------------------------------------------

int sensor_analog;
float moisture_percentage;

sensor_analog = analogRead(A0);
moisture_percentage = (( 100 - ( (sensor_analog/1023.00) * 100 )));
moisture_percentage = constrain(moisture_percentage, 0, 100);

Cayenne.virtualWrite(1 ,(float) moisture_percentage, “Soil Moisture”, “p”);
Serial.print(“SOIL %”);
Serial.println(moisture_percentage);

//-------------------------------

int err = SimpleDHTErrSuccess;
if ((err = dht22.read2(pinDHT22, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print(“Read DHT22 failed, err=”); Serial.println(err);delay(2000);
return;
}

float Dewpoint = temperature - ((100 - humidity )/5);

Serial.print(“Sample OK: “);
Serial.print((float)temperature); Serial.print(” *C, “);
Serial.print((float)humidity); Serial.println(” RH%”);
Serial.print((float)Dewpoint); Serial.print(" %");
Serial.print("");

Cayenne.virtualWrite(2, (float)temperature, TYPE_TEMPERATURE, UNIT_CELSIUS);
Cayenne.virtualWrite(3, (float)humidity, TYPE_RELATIVE_HUMIDITY, UNIT_PERCENT);
Cayenne.virtualWrite(4, (float)Dewpoint, “Dew Point”, “p”);
delay(1500);
}

CAYENNE_IN(V0)
{
digitalWrite(2,getValue.asInt());

}

CAYENNE_OUT(V5){

int A;
digitalWrite(outPin, HIGH);

Cayenne.virtualWrite(V5, A);
}

Have a look at this topic on how to communicate between two devices. https://engineeringprojectshub.com/serial-communication-between-nodemcu-and-arduino/#:~:text=For%20example%2C%20Arduino%20has%206,any%20of%20the%20following%20protocols.