# How to extends Arduino Mega to 250 I/O pin

the title actually quite sums up my question, How to extends Arduino Mega to 250 I/O pin ? I will use it to drive 250 12 V relays (if a direct ic/chip that are 12V capable (max 50 mA per pin will be used) solution is available i would prefer it.

Currently, im thinking on using a daisy chain of a high power shift register(im still not sure of? need recommendation on it too(12V,max 50 mA),the next problem is will it be fine to daisy chain all of those from one data pin? is there any other solution?

Thx!

+UPDATE: ater some times i found this ic http://www.ti.com/lit/ds/symlink/tpic6a596.pdf will it works? Daisy Chained to 30 of them?

• There are many ways to achieve this: I doubt you will find a simple IC solution without some extra interfacing. Jul 10 '16 at 12:22
• Can you please name some of it? Im really new to this kind of things.. prefer not to program more things tho. Jul 10 '16 at 12:37
• Yes, the 596 will work. Be sure to keep all the chips disabled while shifting in the new configuration or the relays will toggle, and be aware that during the shift all relays will be off. Not sure if this is acceptable for your application. You will only need three pins on the arduino. At 10MHz a shift will take 24us, plus a few ns, which is way less of the switching time of a relay. Jul 10 '16 at 12:54
• Will the relay switching be noticeable for thing like lamp,fan,etc? is there a way to have it on while switching? Jul 10 '16 at 12:55
• What do you need 150 relays for anyway? I've got the feeling that your design might be simplified. Jul 10 '16 at 12:56

You can definitely use the TPIC6A596 from Texas Instruments.

Its outputs are more than capable of driving your relays, to have 150 outputs you will need to daisy chain 19 of them.

The chip features an eight bit shift register, clocked by the SRCK pin. This shift register can then be loaded at once in the output register, so that the relays will always be driven.

To daisy chain the chips you will need to connect the SER OUT pin of the first chip to SER IN pin of the second, and so on. The last SER OUT can be left unconnected, while the first SER IN must be connected to the Arduino.

The SRCK, RCK, /SRCLR and /G pins can all be connected together and to other four outputs of the Arduino, so that you will need a total of five pins to drive your chain.

A pseudo routine to manage the whole thing follows:

At power up you want to keep both clock inputs low while resetting both the shift register and the output register tying /SRCLR low. It is probably a good idea to keep the output stage disabled too, keeping /G high.

Now that the chips are in a know state, release the reset and tie the enable high. All the relays are off and you are ready to clock in the first
152 bits.

To do so just start toggling the SRCK pin while putting data on the output pin of the Arduino. The data is sampled by the chips on the rising edge of the clock. For proper timing please refer to the datasheet, maximum clock frequency is 10MHz, a full shift requires about 15.2us.

When all the data is clocked in, stop toggling SRCK, keeping it low, and produce a single clock pulse on RCK: the output registers are simultaneously loaded with your data.

When you want to change something just clock in the new bits and only when you are finished strobe RCK: doing so you ensure that the relays status is known at any given time.

This is about it, but there are a couple of remarks:

You will need to add protection diodes to your relays. This site is full of examples about it so I won't dig into the issue.

The typical RdsON is $1\Omega$. Your relays are 50mA, eight of them adds up to 400mA, this is 400mW dissipated in the chip. Times 19 chips it adds up to 7.6W. This is quite some power, and your board design should take this in account. There are some thermal suggestions on the datasheet, please read them and understand the implications. Without a copper heatsink the thermal resistance is 80degC/W, at 0.4W that's 32degC above ambient temperature. Depending on your application this might be acceptable or not.

Maximum operating frequency is 10MHz, but I have got the feeling that you do not need to go this fast. Keep also in mind that you will be driving 19 inputs with a single Arduino output for the common pins. This is probably fine but the capacitive load can be quite high, so the rise and fall time will be long. I am not sure if this is an issue, this needs some measurements, but if you keep your clock slower you are safer and probably meet your timing specifications anyway.

• This device has CMOS inputs, so if the clock gets slowed down too much by driving 19 inputs, a buffer may be necessary to get the edge rate fast enough to prevent internal heating of the input stage during transitions. Jul 10 '16 at 13:29
• Slower clock rate does not imply slower edges, my last paragraph means that if the edges are slowed by the load then clock rate must be reduced. Jul 10 '16 at 13:31
• Hi,Im still have a quetion regarding whether it'll turn off the whole building lamp or not by using shift register like this.. " is known at any given time." does that means that it will not/doesnt need to be turned off as data being sended? Thx for detailed anwers! Jul 10 '16 at 13:41
• Yes, it does mean precisely that. Please, note that I answered your question but transistor gives some very useful insights here. Read them. Jul 10 '16 at 13:43
• @AufaHusen I feel the need to rephrase it. I strongly advise you not to implement such a thing if you are not a certified electrician and you definitely know what you are doing. Can you imagine a cabinet with 150 cables coming out of it? Not smart, not safe, not serviceable, not easy... Jul 10 '16 at 13:52

... for controlling 150 lamps & fans on a building.. yeah i know there's quite a lot of it.

I would recommend that you consider an alternative control strategy.

• Arduino is not an industrial or building control platform. I would be nervous about living or working in a building controlled by a hobby micro controller board.
• The control strategy will not be easily modified other than by the system expert.
• All mains wiring will have to be brought back to the central control point.
• Not easily expanded.

Instead you should consider a small building or industrial controller capable of supporting remote inputs and outputs. The advantages are:

• Robust.
• Can be built into a proper control cabinet.
• Mains wiring will be local to the load.
• Networking can be wired (Ethernet, RS485, etc.) or wireless.
• Program can be read and understood (assuming it's commented well) by other controls engineers / electricians.
• Better long-term support. 25 years would not be unusual.
• Programming software available.

Sorry if that's not what you want to hear. It will cost more in the short-term but will pay off in the long term. There are many low-cost PLCs or controllers that will do this sort of task.

• Yeah, this does not answer the question of course, but I totally agree. An Arduino with IO expanders is suitable for a nativity scene, not light management of a building. Jul 10 '16 at 13:44
• Hi, Thx for the suggestion. Im quite doubting it (using arduino) too actually.. but since all the on and off will be done by the relays (i use relays that are usually used in industrial application), wont it be fine to just use arduino as an on and off? im still quite new at stuff.. this application use android device connected to arduino with a usb serial and also get a connnection from database (i us android device as a "host" like app) and will be controlled by another device by the internet. Is there any PLC solution kinda suite my needs? Jul 10 '16 at 13:53
• Start by looking at openhab.org (from open (source) habitat, I guess) where they have worked out protocols for connecting to all sorts of stuff and have a HTML5 front end for control. Otherwise search for "building (energy) management systems". You can't turn your question into a shopping question. (Site rules.) ;^) Jul 10 '16 at 14:12
• Ok.., Thx ! Will defenitely check that out! Jul 10 '16 at 14:14