Arduino Mega 2560 + Ethernet Shield + 40 Relays

Hi all,

I'd like to know if is viable to use 40 relays (each one to switching a different lamp) connected on an Arduino Mega 2560 with an Ethernet Shield W5100. I'll use a power supply 6V 800mA.
The relays will turn on/off the lights through an web application.
There is any point (like EMI) that I need to check before execute this test?

Thanks in advance.

Please detail how you will connect the 40 relays to the Mega?
Details on hardware connection and driver and type of relay and how you will power the relays.
Detail your safety approach to controlling what I assume to be mains powered lamps.
Detail what the 6 volt 800mA PSU will be used for, hopefully not for Mega and W5100.
Detail your layout of hardware and what you will do to reduce EMI.
Detail if the lamps will still function if your Arduino program fails.

Unless you provide detailed information you are asking us to guess, not something I would suggest you base your project on.


Paul

Hello,

I have five 8-relay boards. They will be connected to Mega through jumper. I'll use pins 2-9 and 22-53 to connect each relay in a pin. And I'll have 40 lamps connected, one per relay.

The lamps will work manually, in case of failures.

The power supply 6V 800mA is for Mega and W5100.

At the moment I have nothing to avoid EMI, it's just a doubt.

As this is for a graduation work of college, I haven't too much details of the project.

Thanks.

Not a good choice of power supply. Too many volts for direct application to the 5v pin, not enough to go through the regulators reliably, and probably not enough power either.

usr_rj wrote:

I have five 8-relay boards

So, is this as much detail as you are going to give on relays, yet you have asked us about EMI?

I suggest you make sure each relay will have their own transistor driver and back EMF diode, will this be the case?

And I'll have 40 lamps connected

Again, on the loads, is this as much as you wish to give us?
How are you addressing safety if you are using mains powered lamps?

Like Nick has pointed out, the power supply you intend for the Arduino Mega with W5100 will not be suitable at all, research a suitable power supply and buy that.

When you do get details of everything and can explain it here clearly, then we can help, or it will all be guess work.


Paul

Can you please upload your arduino and HTML code.

I am facing some problems in Arduino+ethernet+sd card.
Please help

If it helps, the model of my 8-relay board is SRD-05VDC-SL-C
In this case there is 5 of these boards in the 5V output of the Mega.

Do you suggest a power supply for the Mega and another to the 8-relay modules? Because I suppose that a 6V 800mA can supply the Mega and W5100 right?

Thanks in advance.

usr_rj:
I suppose that a 6V 800mA can supply the Mega and W5100

No - for the reasons previously given

And what about a 9V 1A? It will supply Mega, with a W5100 and the five relay modules connected. By my researchs, this is sufficient for the operation voltage of the boards, that is 5V.

usr_rj wrote:

If it helps, the model of my 8-relay board is SRD-05VDC-SL-C

Not really, you are wanting us to to spend our time to locate this somewhere online? Why not help us by providing a link to the exact board you have.

Please learn to think carefully about your questions and formulate them in such a way that you are providing concise and clear information. With this, we can far better help you with the information you provide. Please learn to do your own research as much as possible, thereby making it much easier for us to understand what you have, what you are doing and what your questions are.

If you can do these things, you will have far greater success with your future projects if you so choose.

The power supply you talk about, saying 9volts at 1 Amp, again, we can only assume it is a regulated 9 volts DC at 1 Amp power supply. It really is important to either show us a picture or a link.

A part answer to your question, will this power supply be suitable for the Arduino Mega and W5100 shield and five relay boards, how can we tell, we have no idea how much power the relays take on each of the relay boards.

You should be able to work this out, by knowing how much each relay will take, or, better still, why do you not read the specifications for the relay board, it should tell you everything you need?

At a guess, you will need a nice regulated, I'll say that again, 'regulated' power supply capable of 3Amps minimum at 9 to 12 volts DC to be able to power your project. Anything less will potentially cause you problems.


Paul

Paul, thanks again.

My power supply is regulated 9VDC 1A. Like this:

And here is a link for my relay boards:

Each relay operates with 15~20mA

The relay board has 8 relays, and if each relay consumes ~20mA, you also have that 4pin DIL devoce which will most likely be an opto-coupler with an LED taking another 10mA and then I think there is a LED on board for each relay, again another 10mA.

So, if you were to make a guess and allow 50mA for each relay, that makes 400mA per relay board when all relays are on.

Then you have five of these boards, so that makes 5 x 400mA, which makes 2000mA or 2 Amp, do you see where I am going with this with what I said before?

To power relays and a board like an Arduino, you need a power supply capable of supplying more current than the total of your load by some factor. This is because to turn on a relay, more current is needed at that point in time. You can call this surge current, and it is due to the inductance in the relay. It is a coil of wire, just as an inductor is. The steady state current of the relay may well be 20mA, but you need to allow for the current to operate the relay.

Operating a relay takes power for your power supply, and if your power supply is weak or under-rated, it will experience droop or a lowering of volts and that may well cause issues with the Arduino, which I mentioned in a previous post.

The link to the power supply you gave will be only ok for a Arduino Mega and a shield like a W5100, but not any relays.

Please, get a good power supply, rated at at least 3 Amps at 9 to 12 volts.
A small wall plug pack like that will simply not do the job.

technically speaking, the power supply needs a fair amount of capacity for surge currents, which will be made up of capacitors in the power supply.


Paul

and if each relay consumes ~20mA

That might be an invalid assumption. Some relay boards are optically isolated and may require less current to operate the optical isolator than directly operating a coil. The OP needs to examine his relay board and schematic to see just what he has. The "this is for a graduation work of college" indicates that the OP needs to have a better idea of his equipment and what he is working on.

Paul, I bought a power supply 12V 5A for testing my project. I connected two relay boards (total 16 relays) in the Arduino 5V pin. When I turn on the Mega, then all the relays also turns on, but in sequence Mega is restarted and relays turns off. Then this happens again like a infinite loop.

Below is the code running on Mega:

#include <SPI.h>
#include <Ethernet.h>

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 190); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80

String HTTP_req;          // stores the HTTP request
int portas[] = {2, 3, 4, 5, 6, 7, 8, 9, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 
                35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53};

void setup()
{
    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients
    Serial.begin(9600);       // for diagnostics

    for (int i = 0; i < 40; i++) {
        digitalWrite(portas[i], LOW);
        pinMode(portas[i], OUTPUT);
    }
}

void loop()
{
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                HTTP_req += c;  // save the HTTP request 1 char at a time
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");
                    client.println();
                    verifyPin(client);
                    Serial.print(HTTP_req);
                    HTTP_req = "";    // finished with request, empty string
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}

void verifyPin(EthernetClient cl)
{
    if (HTTP_req.indexOf("ON001") > -1) {
        digitalWrite(portas[0], HIGH);
    } else if (HTTP_req.indexOf("OFF001") > -1) {
        digitalWrite(portas[0], LOW);
    }
}

From a quick view, change the

void setup()
{
    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients
    Serial.begin(9600);       // for diagnostics

    for (int i = 0; i < 40; i++) {
        digitalWrite(portas[i], LOW);
        pinMode(portas[i], OUTPUT);
    }
}

To

void setup()
{
    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients
    Serial.begin(9600);       // for diagnostics

    for (int i = 0; i < 40; i++) {
       pinMode(portas[i], OUTPUT);        
       digitalWrite(portas[i], HIGH);  // HIGH --> Switch off the relay and LOW --> Switch it on
        
    }
}

To save some memory this option is better:

const byte portas[] = {2, 3, 4, 5, 6, 7, 8, 9, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53};

You can't supply all this relays with 5V from arduino.

Put an external power supply between JD-VCC and GND.

To save some memory this option is better:
const byte portas[] = {2, 3, 4, 5, 6, 7, 8, 9, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53};

But pay attention that if you are using an ethernet shield you must not use the SPI pins to control your relays.
So you must get those pins out from your array portas[]

SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS).