Arduino mega

Hey I have a question i want to set up my work place with an Arduino mega to relays and touch screens and some sensors but I want to use 3 arduinos megas to do it but I also need them to be able to communicate with each other and I want it to be an easy way for them to communicate with each other just in case I want to add more arduinos together later is there any way to do that?

Thanks hope to hear from you soon

Each has 4 serial ports; connect them up uniquely.
Mega1 to Mega2 on Serial1
Mega1 to Mega3 on Serial2
Mega2 to Mega3 on Serial3

This leaves Serial free on all 3 for programming/debugging.

...or you could put them all on a network.
Plenty of examples.

Wouldn't a network need more hardware, and I would think more complex software? Vs just Serial.write & Serial,read between the machines?

@CrossRoads
Mega1 to Mega2 and then Mega 2 to Mega3... Shure, it can work but the time aspect, real time programming… that calls for really experienced people.
Just connecting devices is very easy but to make them do something useful and not get hung up, run into dead lock….. And then the task of debugging… Brrr. I'll pull my hat down lower than my eyes.

You want to use 3 Megas; question would be if you need 3.

A better description of your project might be useful.

" just in case I want to add more arduinos together later"

Yes, I suppose some kind of network would be better towards that end.

Half-duplex RS485 is pretty simple,
Full-duplex RS485 not that much harder,

I think there's even some libraries for it. Basically everybody listens all the time, then enable the Tx side when one wants to send something out. If have a situation with one master and multiple slaves, then keep it simple and slaves only respond when addressed by the master.

If anyone can send at any time, gets a little trickier to determine when it is clear to send.
Could do something like have one bus master, everyon one else listens.
Master periodically queries each 'slave' if they have something to send.
If get a positive response, bus master basically says "ok, your bus" and the slave then sends whatever to whomever it needs to send to, and when done tells the master "slave x is done" and the master goes back to querying everyone again, or sending out commands, such as "slave x, send your current status".

Maxim has some good articles on RS485, like these two

My network engineer wife says ethernet protocol might be what you want also.
Google "arduino ethernet shield" for lots of hits.

What task is that cloud of Megas intended to handle? Spend as many CPU cycles as possible?

Xbee wireless might be another way to go. Xbee controller takes care of the arbitration, control stack, similar to how an Ethernet controller does.

A contribution to make OP confuced, or chooked…. Why not Bluetooth....

Hey thanks everyone I was thinking about using wifi to connect each other bc later I could set up a automated system aka Google home or Alexa to it and when I get the chance to I could put one onto my solar system and I should be able to get battery % and alot more useful information out of each one plus I could get some debugging information out over wifi if something does go wrong or if I need some information about my solar system I could over wifi

So thanks everyone I was just hoping there could have been a different way but it is okay

Wifi is one of the wireless ethernet standards. Bluetooth is point to point.

Railroader:
What task is that cloud of Megas intended to handle? Spend as many CPU cycles as possible?

I have a workbench and I want to control the outlets and sensors and whether or not to use solar. so I want to use one Arduino mega to control the relays for the outlets. One to control the sensors. And one to choose weather or not to be on solar and one to have a touch screen so if I want to switch over to solar or turn off an outlet I could. but an easy way to connect each other so that later if I want something else to be connected to the system I could without a problem.

Railroader:
A contribution to make OP confuced, or chooked…. Why not Bluetooth....

I could do it that way also but I want to be able to later connect with my home automation

So faar, to me it looks like a task that preferably should be done using one processor board, especially a Mega. Why add communication issues by splitting the code out to different processors? Well working communication does not at all come for free. As I already wrote, You need to be a higly experienced real time programmer to manage such a multi controller system.

If glenhull wants to use multiple, lets help to do that. Maybe 70 IO is not enough for future expansion plans. And we get to delve into networking at the same time.
A couple of years ago, Electronik magazine had a series of articles on using RS485 for wiring up a whole house controller. I thought that'd be neat to do, if I wanted that much info (vs just walking upstairs to check).

Home automation, I suspect Alexa/Siri/Echo whatever must have some kind of connection to lights, thermostats, doorlocks, etc. to dim the lights, change the heat, lock the doors. I don't know if that is wired or wireless. I suspect a change of light switch, thermostat, door lock mechanism is needed to allow the Alexa/Siri/Echo/whatever to control it.
I don't have one of those, no idea what the interface or wireless protocol might be.

Railroader:
So faar, to me it looks like a task that preferably should be done using one processor board, especially a Mega. Why add communication issues by splitting the code out to different processors? Well working communication does not at all come for free. As I already wrote, You need to be a higly experienced real time programmer to manage such a multi controller system.

I went to college for computer science.

I use Arduinos in my house all of the time. I was just seeing if there was any other way to connect each other and I know I could just use one mega for everything I want but I would much rather use one mega for each task then to use one mega for everything.

Also why use more bc Its possible. And I know
"Well working communication does not at all come for free." I am fully aware of this I mean like if I wanted to I could use light to communicate with each other and just have one mega as the main system useing wifi

But I would much rather have several megas for each individual task.

And crossroads I have the Google home
No I have not looked at what the protocol is for the Google home or even the interface is like for the Google home but it should not be hard to deal with and thanks for haveing my back

Good. You have, hopefully relevant, eduaction and You have experience from Arduino, and programming. Good.
Of cource You can add a second Mega and make the two of them communicate on some resonable level. Fine.
However, planning for a large number of Arduinos You need "system thinking", how will/can a cloud of them communicate. What does that communication need to do, performance, time aspects etc. System integration really calls for a high level of planning if You don't want to reconstruct the entire communication idea over and over again.
No Arduino will communicate with any other Arduino automatically. Every message exchange must be foreseen and programmed by You. It's a huge undertaking but also a thrilling project.

Often skilled helpers kick the butts of newbies. They spend time kicking ass, asking for better action from OPs. In the next second they spend any amount of time supporting wild dreams that will never come tru, This is way I push You to make sure You know what You're heading for. I had a similiar idea, a construction, in my head 40 years ago but let it be just a dream understanding the terrific amount of work needed.
Good luck!

Distributed processing is certainly valid in this type of application.
It’s up to you, whether the extra effort is necessary.

All the comms options are also valid, choosing one based on ease / cost of implementation, performance - and in this case switching mains - safety.

In all cases, design for fail-safe, with watchdogs and heartbeat monitoring between nodes..