Jobi-Wan:
If you supply power from one Arduino and signal from another, then those two Arduinos should have their grounds connected together.
There are not two Arduinos: there is one Arduino Mega and a power supply of 5V and 50W. It gives enough intensity for both and effectively, they share negative and also positive.
Jobi-Wan:
If you can do it with LEDs, but not with your relays, then your relay board is not wired up correctly.
Both with LED and with relays, both work correctly.
Jobi-Wan:
How did you test and confirm that your outputs are working?Can you explain in detail how your program works? Especially writeRegisters() and setRegisterPin()
I'm trying to reproduce what I did yesterday to check that the exits worked :
.
As soon as I have it, I paste the code.