I have a project in which I need to drive 28 relays with an Arduino Mega 2560. The highest resistance relay for 5V is 178ohms. This would mean that if I connect the the coil to a digital pin and the other end of the coil to ground and put the digital pin on high 20mA will be drawn by the relay. The maximal output current of a digital pin is 40mA so for one relay it should work. My question is, if I connect 28 Relays, each to its own pin, will each pin be able to supply 40mA or will it act like the relays are in parallel and will draw voltage as if they resistance where only 178/28ohms ?
You might find this useful, where it shows that with opto-isolation the Arduino only has to power a tiny led for each relay, and the relay coil 5V is provided externally.
As long as a power limit per pin, where the absolute maximum is 40mA (I try to keep it at about 20mA), there's a per chip limit too. I think the mega is somewhere around 200mA. That's a lot of current going through such a small factor chip! As pet the above reply I'd consider opto-isolation or buffering with a transistor.
See Max current through an Arduino Mega? - Arduino Stack Exchange
Also, I'd make arrangements to get that sort of 5v current from another supply as well, it would be an awful lot of current to take from the Arduino regulator. I'm not sure what it's rated for but probably not a few amps.
If you drive relays direct from Arduino pins you must have a schottky free-wheel diode across the winding
or you'll fry the Arduino immediately.