Running code on two Uno's

I am trying to cause two Uno's to communicate. This is a one way communications from Uno 1 to Uno 2.
Using pin 8 on Uno 1, I set it up for OUTPUT and set its state to LOW. Using pin 2 on Uno 2, I set it up for INPUT and set its state to LOW as well.

The goal is that when I set pin 8 to HIGH on Uno 1, pin 2 on Uno 2 goes HIGH and executes the appropriate code.

The problem is as follows. When I set pin 8 on Uno 1 to HIGH, it stays high which what I want to happen but pin 2 on Uno 2 fluctuates from high to low and back. I need pin 2 on Uno 2 to stay HIGH when pin 8 on Uno 1 is HIGH and when Pin 8 on Uno 1 is LOW, I need pin 2 on Uno 2 to stay LOW.

What do I need to do to achieve this?

Maybe a 10k pull down resistor on Uno2/pin2, but post the code that runs on Uno1 and Uno2 for a more comprehensive answer.

Did you connect the grounds between the two Unos?

The attached code is a grade crossing module that I have created for my model railroad. When it is inactive it looks like Gates Up.jpg. An approaching train activates The Grade_Crossing_Final_Update.ino which is loaded in Uno 1, controls the alternating flashing lights and the movement of the gates up and down as shown in Gates Down.jpg. Uno 2 has the DFPlayer_Grade_Crossing_Bell_Update.ino Its sole purpose is to play a mp3 file sound of a Grade Crossing Bell.

I need Uno 1 to demand that Uno 2 start playing and stopping the mp3 files as necessary.

When a train approaches the crossing, the sequence is as follows:

  1. Uno 1 tells Uno 2 to start playing the mp3 file.
  2. Uno 1 starts the flashing lights.
  3. After a 2 second Delay, Uno 1 lowers the gates.

This must be maintained until the train passes the crossing.

When the trains leaves the crossing, the sequence is as follows:

  1. Uno 1 tells Uno 2 to stop playing the mp3 file.
  2. Uno 1 raises the gates.
  3. Uno 1 stops the flashing lights.

Grade_Crossing_Final_Update.ino (6.45 KB)

DFPlayer_Grade_Crossing_Bell_Update.ino (3.54 KB)

Connecting the grounds fixed the issue. Uno 1 communicates with Uno 2 perfectly now.

Thanks to all for your help!

You're welcome. I'm glad to hear it's working now. Enjoy!
Per