Maker Pro
Maker Pro

How to control 80 relays using ardrino

Farukh Khan

Jun 12, 2015
160
Joined
Jun 12, 2015
Messages
160
Hello,

I am new at the forum. I have been working on a home automation project for my home. I am using raspberry pi as the main controller and two ardrino mega for controlling 80 relays as I got 80 equipments in my home. But now the problem I am having is controlling 80 relays with two ardrino mega. I mean the two ardrino mega will be powered by constant 9V. But each relay will get 5V from the ardrino digital pins. But when I will power up 50 relays with 1 ardrino mega then the 5V output of the ardrino will drop hugely. So my controller might burn out. So what will be the solution here to power up 50 relays at the same time without burning my ardrino...

Please help me guys...
Thanks in advance....
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
... plus a separate supply for powering the relay.

Read this ressource for learning how to do it.
You may want to use a shift register for controlling the transistors to avoid using 80 parallel output pins of the arduinos.
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
What if he want's independent control of the relays? I guess a shift register won't work?
Adam
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
It will, if it has independent output latches. You can then shift the control bits for hundreds of relays, LEds or whatever into the register, then latch it by a single clock pulse into the outputs. If you don't want to change the state of an output, just send the same state again.
Only drawback: you need some time to shift out all that data. But relays are slow anyway, so the shift will be much faster than the relay action.
Use e.g. 74VHC594 for this.

I have used this to control 30 LEDs from 3 pins of an Attiny controller.
 

Farukh Khan

Jun 12, 2015
160
Joined
Jun 12, 2015
Messages
160
ok harald I will research on your suggestion. But according to your suggestion I need seperate power supply. And Using how many ardrino pins I can power up all my 80 relays? and please suggest me what transformer I should use to power up my whole setup? I have a 12V Li ion battery. Now i want the power supply to charge my battery and power up the ardrino and resberry pi without shutting any equipment on the system..please suggest me a transformer for this task..
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
I need seperate power supply.
You don't need a separate supply if the one you use for the arduino can deliver the current for all those relays. If not, a separate supply is in order.
The advantage of a separate supply is that it decouples the relays and their switching-induced voltage spikes from the arduino, but you can use an inductor to achieve this, too.

Now i want the power supply to charge my battery and power up the ardrino and resberry pi without shutting any equipment on the system..please suggest me a transformer for this task..
A simple ransformer will not suffice. You will need a rectifier, smoothing capacitors, possibly voltage regulators and a charger circuit for the battery.
Possibly a charger that is capable to charge the batter while at the same time delivering power to the load (arduino+relays) is a good choice.

Note that relays typically consume quite some power and unless really necessary should not be powered from the backup battery. it may also be a good idea to reset the arduino software to a know safe state in case of a power loss (mains fail). You don't want to turn on arbitrary equipment in your home when power returns only because the software hasn't been aware of the outage. This can be very dangerous!

The supply needs to be rated for 80*relay_current+arduino_current.
 

Farukh Khan

Jun 12, 2015
160
Joined
Jun 12, 2015
Messages
160
Yeah I understood harald. But am very newbie at electronics so I wasn't aware of the calculations. So if you could just tell me what transformer and what model of transistors, diodes, capacitors along with inductor I might need to power up all the stuffs. And also suggest me a good 12V Li-ion battery which could power up all the things (raspberry Pi, 2 Ardrino Mega and 80-100 relays along with some temperature+humidity sensors) for upto atleast 24 hour in-case a huge power outage occurrs. I really dont want to reset anything. I will add a feature which will detect the power outage in the ardrino. So I want the whole setup to run 24/7 along with the battery backup. Please suggest me a battery and also a transformer to charge the battery and power up the relays. At this moment I have already a new transformer in my hand which I am willing to use to power up the ardrino's and raspberry pi only with no noise at all. Because microcontrollers need a smooth and filtered current to run properly. The transformer configuration is:

I/P 220V ~ 50Hz
O/P 12VX2 1000mA


Please provide me a simple guide on how I can use this transformer to power up my ardrinoes and raspberry with a smooth current and possibly also a relay which will switch between this transformer and the battery. Because when power will goes off the relay might switch the battery power to the microcontrollers in some miliseconds without powering them off.
 

Farukh Khan

Jun 12, 2015
160
Joined
Jun 12, 2015
Messages
160
And can you please tell me if I use a Sealed Lead Acid Battery instead of Li-ion battery for this job then is it suitable? Because a Sealed Lead Acid Battery got huge Amp Hour than a Li-ion battery and is also cost effective...
 

Farukh Khan

Jun 12, 2015
160
Joined
Jun 12, 2015
Messages
160
And if possible please provide me a suitable relay model which can hold my household ac equipments easily without any realy heat or other stuffs. And how much mAH each relay which consume....
 

Farukh Khan

Jun 12, 2015
160
Joined
Jun 12, 2015
Messages
160
I just went back checking the raspberry pi FAQ and there it is saying that a fully functional Raspbarry Pi would need 2500mA of current. So my transformer wont gonna serve the purpose of powering up the three microcontrollers I think.

So please suggest me a nice transformer which will serve all the purposes of powering up the sensors, controllers and relays and also charging the battery when needed without any kind of power loss.
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
I would highly recommend using solid state relays for this. They will use far less current, switch faster, and not make annoying clicks every time they switch.

Bob
 

Farukh Khan

Jun 12, 2015
160
Joined
Jun 12, 2015
Messages
160
But as far as I know solid state relays might fail and also they couldn't conduct much electricity?? the annoying clicking noise is not a problem at all to me because the whole setup would be in our store room. But I really want to know that for this purpose solid state relays will be more reliable or normal mechanical relays?
 

Farukh Khan

Jun 12, 2015
160
Joined
Jun 12, 2015
Messages
160
And According to my noob calculation I think I might need a 24 volt and 50Amps transformer to supply regulated power to all my equipments. If I am current then please suggest me a good transformer model which gives a output of 24 vot and 50amps.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
And if possible please provide me a suitable relay model which can hold my household ac equipments easily
Sorry, you will have to know how much power is drawn by each appliance from mains and select the relay accordingly. Once you know which relay(s) to use, you can calculate the total power required to drive all of them.

A back of the envelope calculation: A typical relay consumes between 300mW and 500mW coil power. That is max. 40W. At 12V coil voltage you need ~3.5A for driving the relays.Note thát this only an estimation and needs to be replaced by a calculation with the parameters of the real relays.
Turning to solid state relays: they can be controled from curents as low as 20mA (depending on type) which sums up to only 1.6A max. If you use a 5V supply for the primary side of the solid state relays, the total power is 1.6A*5V=8W, considerably less than the 40W for mechanical relays.

As for the power supply: I suggest you get an off-the-shelf power supply that is rated at the voltage and current you need. can't recommend one as I don't know these parameters.
 

Farukh Khan

Jun 12, 2015
160
Joined
Jun 12, 2015
Messages
160
I want to make my own power supply with a transformer. So that I can control how much voltage will go to every equipment and also keep the noise level down with my own inductor. I have estimated the power consumption which might be around 40-50A. So If I use a 30V 50A transformer then will it workout quite nicely?without any losses?

And for the battery part which battery you recommend for this project? If I go for Liquid Acid Lead Battery then I could buy a huge ampere with low cost. But if I go for Sealed Acid Lead Battery then I could cost a little more for that amp. But if I go for Li-ion Battery then huge cost is needed for that amp. So what battery you recommend for this purpose which will save my cost and also serve the purpose very well?
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
This sounds like an accident waiting to happen after everything is built and the power is applied. Please answer these questions:

1. Are your "equipments" household appliances powered from wall sockets?
2. If you are powering your "equipments" not from a wall socket but instead from a power supply, what is the voltage and (if AC) the frequency?
3. How much power (in watts) does each "equipment" consume?
4. How are you going to "control how much voltage will go to every equipment" using a single 30V 50A transformer?
5. What provision will you make to conduct a current of up to 50A from the transformer?
6. How will an inductor serve to "also keep the noise level down with my own inductor"?
7. How will you make connections to supply power from 80 relays (mechanical or solid-state) to 80 "equipments"?
8. Can you provide a block diagram of what you envision building?
9. Do you want a battery to provide back-up for just the computing and switching components, or do you need back-up power for the "equipments" too?
10. How much money do you have budgeted for this project? Or do you plan to pay-as-you-go by starting small and adding on later as you can afford to do so?

There is nothing wrong with being a newbie, but we are concerned that you work safely and make intelligent design choices. It is ambitious to try to control 80 "equipments" as a first project. It is foolish to think you should do this by adding two or more Arduino boards to obtain 80 digital control outputs. @Harald Kapp suggested an alternative using a shift register with latched outputs that requires only three wires and is expandable to as many "equipments" as you desire. Show us the work you have done so far. Show us that you have investigated Harald's suggestion and have either rejected it or intend to implement it. If you reject it, tell us why. If you accept it, draw up a schematic diagram with pin numbers and signals identified for each component of the design. If you show us your work, and where you may be having problems, we will be glad to assist. But we expect some real effort and understanding on your part... well, at least I do. I am not going to design your system for you. From the nature of your questions, it sounds like you are not yet qualified to do so either. Sorry 'bout that, and it's no reflection on you, but IMHO you need more knowledge about electricity in general, and electronics in particular, to proceed.

Hop
 

Farukh Khan

Jun 12, 2015
160
Joined
Jun 12, 2015
Messages
160
I am really willing to do this project at my home because I am very interested in electronics. But I totally understand your concern @hevans1944. I will take your suggestion and I will also answer all the questions you have asked. I also want to maintain all the safety precautions I can because it's electronics. A single mistake can be an huge accident. But I am really interested in doing this project. So I might not cancel working on it. But I will work on it with proper precaution and time. And for this reason I need help from all of you guys.

So, here I am answering to your questions accordingly :

1. Actually my all home equipments or appliances are not powered by wall sockets. In our country all the household appliances are powered by 220-240V AC current which comes from the outside electrical pole stands on the left side of my house. Actually the house I am living in is a 7 storied concrete building. But my father bought only the 6th level's one apartment. So the whole automation system is gonna happen only on the 6th level of the house in our apartment is located. And all the appliances in our apartment is powered by parallel connections of 220V-240V AC current. All the equipments got powered by wires which lay inside the wall of our apartment. And some equipments like Micro Wave Oven, Fridge etc. got powered from the wall sockets which got the same current of about 220V-240V AC current.

2. I am really not powering the home appliances from any power supply at all. We got 220V-240V AC current in our whole building which is provided by the government. And as far as I read on the books I think the AC current frequency in our country is 50Hz.

3. We got almost 5 fans in our apartment. Each of the fans consume upto 80 Watts in general and runs totally on pure AC 220V-240V. And there are some energy saving lights which consumes 20-60 watts according to the brightness on different purposes. And there is three fridges which consumes a lot of watts I guess. And there is also a TV along with two Air Conditioners. So this things drive out a huge watts. The fridges are 24/7 equipments which runs all the time. The AC is very rarely used because the temperature in our country is very favorable at this moment.

4. I am not going to control any of the household equipment voltages at all. They got instant 220V-240V which I will pass through a relay. Whatever happens after that thing I really don't wanna keep a control on those ac equipments. Only I want to have the switching control only for all those AC equipments. But I am gonna control the voltage on the relays and my microcontrollers using regulator transistor circuit. I will use one circuit for only one microcontroller to maintain the amount of ampere and voltage constant. I will use separated regulator circuit for the relays module with the biopolar transistor and also make a little inductor to reduce the noise which will occur to power up the electromagnetic relays. In this case I am really not willing to use a solid state relay cause I have read about the SSR and the SSR are more costly than the normal relays and also the SSR gets quite hot for 24/7 electrical appliances and might burn out often. I will use the simple relays as they will cost very less and I have no problem with the clicking noise and the time lapse of the relays.

5. I haven't really made any provision yet to conduct the 50A current from the transformer. But I thing I will use high guege wire for this. And I want to ask you all will the 30V 50A AC current which will get generated from the transformer can provide me a normal shock like the AC 220V current does? If so then I will maintain some precautions too while working on the transformer.

6. A inductor is a coil which we do on a round solenoid type thing. With maximum amount of coiling along the round thing and using a capacitor electrical noise level can be put down. As far as I know.

7. I will use the transformer to power up the relays with the biopolar transistor signal from my ardrino. And the relays will act as a switch for all the AC equipments of my house. They will just pass the face or the positive of the AC current through the relay switch when the switch will get on by ardrino signal.

8. At this moment I don't have the block diagram of my building. I will collect it from the builder and will provide soon. But as for now in our apartment we got 1 dining room 1 drawing room and three bed rooms along with two bathrooms and 1 kitchen. Each part of the apartment got some electrical appliances and also electrical wall sockets.

9. I just need a battery pack to backup power only the microcontrollers, relays and other sensors. Powering up all the home equipments with a battery isn't a right solution in my case. We got a huge amount of power outage in our country specially during the summer. So I need to keep track of the power outage and apply certain protocols on power outage which will be applied by the microcontrollers. So I really dont want the microcontrollers and relays to shut down when power outage occurs.

10. I plan to pay-as-i-go by starting small and adding on later as I can afford to do so.


I have researched about harald's suggestion on using 1 pin to control multiple relays with different signal from the ardrino. But I am not going for it because I want to troubleshoot each of the appliances with each pin numbers of the ardrino. And also I want to code stuff cleanly on the ardrino. Just 1 or 0 digital signals to power up the relay end biopolar transistor. I don't want huge amount of coding to be done on the ardrino to control multiple relays with one single pin because that will need huge amount of C coding and also as I am new at C coding I am really comfortable with using 80 pins to control 80 relays other than 1 ping to control multiple relays. So I rejected that suggestion but I am taking the biopolar transistor suggestion to provide a little signal to open the power of the relays from the power supply using the ardrino. I am really willing to use the digital pins of the two ardrino mega that I bought. And the 0 and 1 signals to open or close the biopolar transistor supply to power up the electromagetic relays to switch on or off my electrical appliances. I totally understand your concern about my knowledge hevans but I really believe in big creations with small hands. So I decided to go on this project and I will not step back until successful. But I can ensure you that I will work on keeping all the precautions at high importance.

And about my work I really have not proceed yet much in my work. Because proceeding in my work will need help from you guys. The first thing I want to do is setup the whole electrical part and then keep the electrical setup in a safe mode and then coding each stuff particularly and adding some troubleshooting labels to each wires etc. n all. So to setup the electrical part first thing I need to do is choose the Transformer and the Battery. The battery must be able to power up my whole setup without the AC appliances for upto 12H to 24H. After deciding this two things I will then decide how I will make the regulators which will power up the controllers, relays and sensors with a regulated voltage and ampere. And I will buy those equipments and test on bread board what output I get through digital meter. I will test each and everything particularly on the bread board. After I get each thing work properly I will design a PCB board of my own and provide the design to a manufacturer I know and they will provide me the PCB board designed by my diagram and I will then just solder all the euipments on one board and setup the whole system on our house store room.


This is what I have planned so far. Now I need help from all of you guys choosing the right and most secure equipemtns to build up my controlling unit. That's all

Thanks all who helped me and thanks in advance to all who will help me in future. And really thank you a lot hevan for your concern. I will keep every word of you in my mind.

So, please help me guys with choosing the right transformer and battery for this work.
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
@Farukh Khan Thank you for your detailed and intelligent reply to my questions. I feel somewhat reassured that you won't burn down your concrete abode.

The biggest problem I see you having is: How do you do the actual wiring between the relay contacts and the appliance circuits those contacts will switch on and off? Perhaps the safest way to do that would be to locate each of the relays near the load point, mounting them in individual boxes that plug into a wall receptacle with the appliance cord plugging into a socket on the box. You would then run low-voltage relay-coil wiring back to your Arduino modules located in the storage room.

There are self-contained modules available from X10 that will do this remotely (no additional wiring needed) using a signal propagated in your house over the AC power line from a central command location. Unfortunately, I don't think they offer anything that will control such a large number of appliances as you envision controlling. Plus I don't think their product is designed for your line voltage and frequency. So, mechanical relays sounds like your best bet, but I would not recommend placing them all together, co-located in the storage room. It would not be safe trying to wire all those contacts in series with 220 VAC loads by running external wires scattered throughout your apartment! That was my biggest concern when I made my post. OTOH, running low-voltage wiring all over the place to relays (appropriately hidden and protected inside a small enclosure or project box) is fairly safe. You could have screw-terminal barrier strips inside each box to attach the relay-coil wires.

In Question 8 I was not asking for a block diagram of your building or apartment, although that could be handy for you in determining the wire lengths you will eventually need. What I meant was a block diagram showing the conceptual relationship between all the components you envision using in the system: Raspberry Pi, Arduino modules, PCBs used to drive the relay coils, battery back-up, power supply for the computing components, power supply for the relays (that 30 V 50A monster!)... that sort of thing. It helps to see the "big picture" if you can break it down into easily visualized elements on a block diagram.

I would avoid using an un-sealed lead-acid battery (like a car battery) in a residential environment because of the possibility of generating hydrogen gas while charging (overcharging, actually) the battery. In the United States it would be illegal to co-locate such a battery inside a residential unit. Perhaps your should plan on purchasing a commercial UPS (Uninterruptable Power Supply) that plugs into the wall and provides sealed battery-backed AC power to critical parts of your system. If you insist on using a battery to power your computing components directly, be aware that it is a non-trivial design problem to get it right. I would recommend using so-called "gel cell" batteries such as are found in emergency lighting... the kind that comes on for a short period time when power fails, allowing occupants of the room to safely exit the premises. Use the manufacturer's recommended charging system for these batteries.

As for ampere-hours capacity... more is generally better. You need to plan for how long you want to "stay up" when power fails, which means you need to know precisely how much current you will draw from the battery during the power failure. Figure that out and tell us and someone here can probably recommend a suitable battery.

Hop
 
Top