Reading Pin from Mega to Uno

Hello,

I have connected a pin from Arduino Mega to Uno. The aim of the program is to run a specific task on Uno whenever the pin on Mega goes HIGH. I am using an if statement for this purpose but the code continuously executes the if block as if the pin on Mega is continuously HIGH, which is not the actual case. What should be a possible solution to this problem as I am also writing that particular pin LOW on arduino Mega whenever the Uno should not execute that block. But even then the problem persists and Uno reads the pin as HIGH.

The code for Uno is as follows:

int cameraPin = 6;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(cameraPin,INPUT);
delay(1000);
}

void loop() {
if (digitalRead(cameraPin) == HIGH)
{
Serial.println("10");
delay(1200);
}

}

cameraimage.ino (270 Bytes)

Do you have the Mega GND pin connected to the UNO GND pin?

Is the pin on the Mega set to pinMode OUTPUT?

Yes, I did set pinMode OUTPUT. Probably I forgot to connect Mega gnd to Uno gnd. I will connect it today and see if it works.