Introduction: Home Automation - How to Add Relays to Arduino

Picture of Home Automation - How to Add Relays to Arduino

How to select Relays – Its all about Power.

When you are selecting a relay to connect to your Arduino you need to consider

a) the power (voltage and current) of what you want to switch on and off and
b) the power (voltage and current) required to drive the relay (i.e. to energise the relay coil)

We will look at a number of configurations for connecting relay modules to Arduino boards:-

1) Direct driven reed relays
2) Single 5V power relays powered from the Arduino board's 5V supply
3) Four (4) relay shields using a separate supply. The shield powers the Arduino board.
4) Separate multi-relay 5V modules high triggered and low triggered
5) Separate multi-relay 12V modules high triggered and low triggered
6) Modifications for Driving a 5V relay module from a 3.3V Arduino board
7) High/Low Triggered Relays for Use with 3.3V boards, e.g. ESP8266-01
8) FET Sheilds
9) Solid State Relays
Finally there small section on Help My Relay Stopped Working (RC Snubbers)

If you are looking for a simple way to switch these relays on and off from your Android mobile, via bluetooth, wifi or SMS, with optional 128 bit security, check out pfodDesigner (www.pfod.com.au) and this instructable Code generator for custom Android/Arduino menus to switch Arduino outputs on and off Absolutely NO programming required. No Android programming and no Arduino coding. The pfodDesigner generates all the Arduino code you need for your custom menus and the pfodApp takes care of displaying the menus on your mobile and handling your selections.

Step 1: Relay Selection Based on What You Want to Switch on and Off.

Picture of Relay Selection Based on What You Want to Switch on and Off.

This is relative straight forward so we will consider it first. While there are may different types of relays (see http://en.wikipedia.org/wiki/Relay), for home automation and control there are four main types that would be used.

i) Reed relay for switching low voltage and low current devices

ii) FET switches for switching 30V to 60V DC voltages and up to 20Amps

iii) 110V and 240V power relay for switching mains powered devices

iv) Solid State switches for switch mains powered devices.

Reed Relays

Reed relays are small low power relays suitable for switching <100V at current <0.5Amps. While designs vary, total switched power is usually less than 10 VA (volts x Amps < 10). Examples of IC form factor reed relays are TRR-1A relays and COTO TECHNOLOGY – 8L01-05-001

Power Relays

Most relay modules sold to connect to Arduino are power relays and are rated for either 110V or 240V. The ratings are usually printed on the relay case.

Notice that the maximum DC voltage that can handled is much less then the AC rating.

This is the type of relay you will need to use of switch mains powered devices. These relays will handle most devices used in homes except the highest powered ones like room heaters, stoves, motors. Make sure the VA (Volts x Amps) of the device you are switching on/off is less than the relay rating.

Any wiring to the mains power should only be done by a qualified electrician.

A final point, the power relays commonly use silver alloy contacts and are not suitable for switching very low currents like switching Arduino digital inputs. If you are only switching a few milliamps, for example by putting a relay across a low voltage garage door push-button, you should use a reed relay (or a relay with gold contacts) as the power relays need a “wetting current” to break through the surface film resistance and will not switch very small currents reliably.

“Normally, a switch's wetting current rating is far below its maximum current rating, and well below its normal operating current load in a properly designed system. However, there are applications where a mechanical switch contact may be required to routinely handle currents below normal wetting current limits (for instance, if a mechanical selector switch needs to open or close a digital logic or analog electronic circuit where the current value is extremely small). ... Normal silver or copper alloy contacts will not provide reliable operation if used in such low-current service!” (http://www3.eng.cam.ac.uk/DesignOffice/mdp/electric_web/Digital/DIGI_4.html )

FET switches do not have this problem and can be used to switch very low currents.

Step 2: Relay Module Selection Based Power Required to Drive the Relay

Picture of Relay Module Selection Based Power Required to Drive the Relay

The Arduino digital outputs can only supply +5V (or +3.3V) and less than 40mA max. (typically <20mA for continuous use). So, except for some reed relays, you cannot drive the relay coil directly from the digital output since 5V power relays typically require ~100mA to operate the relay coil. This means for most (all) relay modules you need to provide a separate supply to the module in addition to the Arduino digital output which is used to control the relay switching.

We will look at a number of configurations for connecting relay modules to Arduino boards:-

a) Direct driven reed relays

b) Single 5V power relays powered from the Arduino board's 5V supply

c) Four (4) relay shields using a separate supply. The shield powers the Arduino board.

d) Separate multi-relay 5V modules high triggered and low triggered

e) Separate multi-relay 12V modules high triggered and low triggered

f) Modifications for Driving a 5V relay module from a 3.3V Arduino board

g) Solid State Relays

Direct Driven Reed Relays

5V Reed Relays can be driven directly from the Arduino digital output provided their coil current is less than 20mA. TRR-1A relays and COTO TECHNOLOGY – 8L01-05-001 only require 10mA each so you can easily drive 8 or more of these relays from an Arduino board supplied by a USB 500mA power supply plugged into the USB connector (The Arduino Uno has 500mA resetable fuse on the USB input).

Alternatively if the Arduino board is powered via 12V to its power plug, limit the number of 10mA reed relays to less than 6 as the on board 12V to 5V regulator limits the maximum current that can be drawn from the 5V supply to about 70mA or so.

Above is a circuit for a single 5V reed relay being driven directly from D7

Direct Drive Clamping Circuit

Two things to note:

a) The 1N4004 diode across the coil of the relay and

b) the 33 ohm resistor between D7 and the relay coil +

The diode is there to clamp the voltage/current spike the relay coil produces when it is switched off. Do a search on “flyback diode” for more details on this. (http://en.wikipedia.org/wiki/Flyback_diode for example)

The 33 ohm resistor protects the D7 output from excessive current and allows the diode to do the clamping. When a digital output is turned off it does not go open circuit, rather it connect the output pin to GND via a very low resistance. Without the additional 33 ohm resistance, the current spike from the coil would preferentially go back into the microprocessor via D7 to GND.

The coil resistance is about 500 ohms so when D7 is high (+5V) most of the voltage appears across the coil (I.e ~4.7V ) (search for Ohm's Law or checkout Sparkfun's tutorial) The “pull in” voltage on the datasheet for the TRR-1A 5V reed relay is 3.75V which means any voltage higher that than must close the contacts so 4.7V is more then enough to ensure the relay operates.

All commercial relay modules should already have the clamping diode fitted across the relay coil.

Step 3: 5V Power Relay Modules Powered From the Arduino Board's 5V Supply

Picture of 5V Power Relay Modules Powered From the Arduino Board's 5V Supply

There are a number of different single 5V relay modules available on-line. But most do not have any circuit diagrams available. Here are two examples (the first one from DX.COM's website).

Both operate the relay when the input (IN) is HIGH (+5V). The second board as an optical isolator and separate connectors for the IN ground (COM) and the main 5V supply ground (GND). The jumper is connecting these two grounds together so you can use it just like the left hand board.

Removing the jumper lets you have isolated supplies, one for the the Arduino and another completely separate one for the relays. Separate supplies provides some extra protection against mains volts getting back into the microprocessor. But this extra protection is mostly illusory. The pcb tracks on the back of the board are quiet close and nothing will protect you against a lightning strike on the power line outside your house.

So for either board, connect the relay GND to one of Arduino's GND pins and the relay 5V or Arduino's 5V pin and the relay IN to one of Arduino digital outputs, say D4. Then when the digital output, D4, is High the relay will operate.

The photo above shows this wiring. Note the Arduino is being powered by the 5V USB power. The relay is 5V so everything is at the same voltage.

The relay's contacts consist of a Normally Closed (NC) and Normally Open (NO) connection and a COM connection. When the relay is un-powered the NC terminal is connected to the COM terminal and the NO terminal is not connected. When the relay is operated, the COM terminal switches over and is now connected to the NO terminal and NC terminal is not connected. The screw terminals are either marked NO, NC and COM or small drawing is shown like the image above. It the image above, the top terminal is the NO one the centre terminal is the COM and the bottom terminal is the NC one.

Connecting these relay modules to the Arduino's 5V pin means both the trigger current (IN) and the current to drive the relay coil are being supplied by the Arduino board. From the datasheet for the SRD-05VDC-SL-C you can read that the relay coil takes ~72mA to operate. Added to this is the current required by the IN input to trigger the coil. For the optically isolated relay that is about 4mA and perhaps a bit more for the non-isolated one. (Measure it for your module).

In any case each of these relay modules will take <100mA from the Arduino's 5V supply. So if a USB supply is used to power the Arduino,you can attach up to 4 of these modules. Indeed that is just what the 4 channel relay shield from Seeed Studio does.

In Seeed Studio's 4 channel relay board, the relays are controlled by D4,D5,D6 and D7 so you can just plug this relay shield on top the Bluetooh Shield V2 to get a complete remote control of up to 4 relays controlled by Android and pfodApp. Use pfodDesigner to design the Android menu and generate all the code you need.

This shield is quoted as drawing 250mA, but 300mA would be more realistic based on the datasheet for the relays. In any case it is fine if you are powering the Arduino board via a USB supply. However it is not suitable if you are using a 9V or 12V supply due to the limitations of Arduino's on-board regulator.

Step 4: Four Channel Relay Shields Using a Separate Supply

Picture of Four Channel Relay Shields Using a Separate Supply

An example of this type of relay shield is the DFROBOT Relay Shield for Arduino V2.1

This shield can be configured in a number of ways using the jumper strips. When operating all 4 relays it should be powered by 9V applied to the screw terminal on the left of the picture.

By default the relays are controlled by D2, D7, D8 and D10. The Itead Bluetooth Shield that I usually use already uses D2 as an output so only 3 relays can be driven in the default configureation, if you use that Bluetooth Shield.

However the DFROBOT relay shield can be reconfigured to use any digitial pins to drive the relasy. It also includes an Xbee socket so you can plug in an RN-42XV Bluetooth or RN-XV Wifi module and configure the jumpers to work with it. Note: in this case you should cut off the reset pin from the relay shield as it is driven by the RS-232 flow control on the Xbee socket.

Step 5: Separate Multi-relay 5V and 12V Modules, High Triggered and Low Triggered

Picture of Separate Multi-relay 5V and 12V Modules, High Triggered and Low Triggered

Separate multi-relay 5V and 12V modules, high triggered and low triggered

If you want more the 4 relays then there are a number of multi-relay modules available. Typically with 8 relays but some with 16 relays. SainSmart has an 8 channel module.

The specification for the SainSmart say each channel needs 15mA to 20mA to drive it. I expect this is an error as all the modules I have measured need <5mA to drive them. However I suggest you measure the actual current needed to drive the inputs of any 8 channel board you use. The Arduino microprocessor has an absolute maximum total digital output current of 200mA, so 8 times 20mA = 160mA is higher then I would like to run continuously.

Since both the Arduino drive voltage and the relay coil voltage is the same, +5V, there is no problem with low triggered inputs since the voltage from the relay board being pulled down by the digital output will not be more the 5V. But as will discussed below this is not the case for 12V relay modules. It is also not the case if you are driving a 5V relay module from a 3.3V Arduino board like the Due or Fio or SparkFun's FioV3.

Separate multi-relay 12V modules, high triggered and low triggered

It is sometimes more convenient to use 12V relays driven by a 5V Ardunio board. You may have a 12V battery supply or need to use 12V for some other part of the circuit, or the lower current used by the 12V relay coils may be a consideration. In these cases you have to be careful about how the 12V relay coil is driven by the 5V Arduino output.

As mentioned above a lot of the relay modules available do not come with circuit diagrams. Problems can occur if the relay module is low triggered. That is the relay control input is pulled to GND by the Arduino digital output pin. In that case, then when the Arduino output pin is high there may be 12V applied to it from the relay module. This may damage the Arduino microprocessor.

This is also an issue if you are driving 5V relay module from a 3.3V Arduino board like the Due or Fio or SparkFun's FioV3. Again the +5V from the relay board applied to the 3.3V digital output pin may damage the microprocessor.

There are two ways to avoid this problem.

i) Use a module that is high triggered by +5V. In this case there will not be any excess voltage coming back from the module when the Arduino output is low.

ii) Use an optically isolated module that has a separate trigger supply terminal in addition to the 12V supply terminals for the relay coils. In this case the Arduino +5V supply goes to the trigger supply terminal and no excess voltage will be applied to the digital outputs.

Above is an indicative circuit of one channel of 8 channel relay module (This circuit from SainSmart)

As you can see with an optical isolator and a separate Vcc input (+5V from Arduino) and the Arduino digital inputs are isolated from the 12V relay voltage by the optical isolator.

Also shown is a typical optical isolated 12V 8 channel relay board. Notice the Gnd and VCC near the IN terminals. That VCC is for the 5V supply from Arduino. At the right hand end is the JD-VCC pin which is for the 12V for the relay coils.

The photo above shows an example connection for 12V optically isolated relay. Note that the Arduino is being powered by 12V via the plug in power. The Vin socket on the Arduino is the same voltage as the power plug, i.e. 12V, so the relay module JD-Vcc is connect to Arduino Vin to supply the 12V for the relay coils. The Arduino Vcc is 5V and is connected to the relay module Vcc to set the trigger voltage. The trigger GND is connected to Arduino GND and D4 is connected to IN1 to drive relay 1. In this module the JD-Vcc and the Vcc connections both have the same GND point so only one ground connection is needed and no jumper is needed.

Step 6: Modifications for Driving a 5V Relay Module From a 3.3V Arduino Board

Picture of Modifications for Driving a 5V Relay Module From a 3.3V Arduino Board

One final point about drive 5V relay modules from 3.3V Arduino boards. In addition to using one of the above two solutions to prevent the 5V being feed back to your 3.3V digital outputs, you may need to modify relay board, if the 3.3V output does not reliably drive the relay. The problem is the circuit was designed for 5V to drive the optical isolator U1, and U1 may not be getting sufficient current from your 3.3V Arduino's output.

There are two common modifications for 3.3V operation of a 5V relay board:-

1) If the drive circuit has a led in series with it, i.e. IN1 in the circuit above, just short it out by soldering a wire from one side to the other. The led was using up about 2V so shorting it out means now you only need about 3V instead of 5V to drive the relay.

2) If there is not led in series with the drive pin, then add another resistor across R1 to reduce the series resistance and so increase the current available from you 3.3V drive. R1 is typically 10K (102) so adding another 10K resistor across the existing R1 should be sufficient. This will require some careful soldering.

Step 7: High/Low Triggered Relays for Use With 3.3V Boards (e.g. ESP8266)

Picture of High/Low Triggered Relays for Use With 3.3V Boards (e.g. ESP8266)

I recently went looking for a single relay board to use with an ESP8266 module. The ESP8266 has 3.3V supply rails. The module I found did not have a separate IN+/-, instead it featured a High/Low Trigger selection jumper (see the above photo). Unfortunately there is no schematic provide for the very inexpensive module, so you need to test it to see if it is suitable for use with a 3.3V output from your microprocessor board.

Testing consists of selecting the High Trigger jumper, powering up the module with 5V and then measuring the voltage on the IN terminal, with nothing connected to that terminal. In my case the IN open circuit voltage, when in the High Trigger setting, was a few millivolts. So this in will not harm the 3.3V microprocessor board. Next apply 3.3V to the IN input and check that the relay operates. In my case the relay did operate with a 3.3V input and only draw 1mA. If your relay board does not operate you may have to find a series resistor in the input circuit and reduce its value as described above.

I actually did this testing using an UNO board. I used the UNO 5V and GND pins to power the relay module and then measure the open circuit IN voltage. Then I used the 3.3V pin on the UNO to test driving the relay with this voltage.

Step 8: FET Shields and Solid State Relays

Picture of FET Shields and Solid State Relays

FET Shields

An alternative to relays for switching low to moderate DC voltages is FETs. There are a number of boards available:-

All these can be driven by a 5V Arduino output and can control voltages up to 30V to 60V at 0.6A to 20A.

The actual voltage and current that can be controlled depends on the the FET used on the particular shield. You need to check the FET specifications. Look for the MIN Drain-to-Source Breakdown Voltage to see how much voltage the board can switch. The current carrying capacity depends of the how well the FET can get rid of the heat. Check the boards published specifications.

The LEDSEE 8 channel FET shield (with jumper JP1 removed) and the Yourduno 4 channel optical isolated board should also be able to be driven by 3.3V Arduino outputs, but I have not tested this.

Solid State Relays

Solid State relays are inexpensive and can handle high current loads. The one shown above will switch a load of up to 40Amps from a 24 to 380V AC supply. The control input is DC 3 to 32 Volts. However there are a number of things to look out for when using Solid State Relays with Arduino.

a) Make sure the relay is controlled by DC volts 3 volts and up. Some solid state relays have AC control inputs of higher voltages instead on DC control inputs.

b) Choose a relay that is rated for the current you need to switch. The one in the photo is a 40Amp relay

c) Make sure the relay can handle more then 1.414 times the AC line voltage. That is >340VAC for a 240V supply and >180VAC for a 120V supply.

d) Always attach the relay to a suitable heat sink using a thin smear of thermal compound that completely covers the base of the relay. Solid State relays can get very hot and burn out if the heat sink is too small. For a 10amp load, the relay needs to get rid of about 16Watts of heat.

e) Solid State relays are best suited for resistive loads like heating elements. If you are trying to turn a motor on and off a normal relay and a snubber is probably a better choice. This article has some information on Solid State Relays Common Precautions. While this posting discusses snubbers.

The main advantage of Solid State relays is that if it still working after 3 months (infantile failure) it will probably work for many years.

The solid state relay can be controlled with 3V, so is suitable for the 3.3V arduino boards. However it takes about 12mA to switch the solid state relay, so do check that your board can supply that amount of current from a digital output. Some 3.3V boards, like LinkIt ONE, will only supply 3mA from a digital output. Arduino Uno boards can supply about 20mA.

Step 9: Help My Relay Stopped Working (RC Snubbers)

You have tested your relay on the bench with a multi-meter, but after you install it, it stops working. That is it won't turn OFF. This happens most commonly if you are switching inductive loads, like motors, ceiling fans, etc, but can also happen when switching incandescent lights and is caused either by the contacts welding close due to high initial current OR arcing on opening and continuing to pass current.

Assuming you can normally hear the relay operate (a small click), then if you can not hear it click when it should be opening then the contacts may be welded together, you will need to replace the relay in this case. If you can hear it click when it opens but the motor keep running then the contact are probably arcing.

The solution to these problems is to add a snubber network. This pdf has some examples and suggested sizings. This discussion also has information on choosing snubbers. RC snubbers are also available pre-built in a variety of sizes, e.g at element14.

Conclusion

There are a number of types of relays you can add to your Arduino to switch real things on and off. You need to choose a relay appropriate to your needs.

The simplest solution for on/off Home Automation is to use the free pfodDesigner to design your control for upto 4 switches and then use a Arduino Uno + Bluetooth module + 4 channel relay board powered by a USB power supply and controlled by pfodApp and, if switching mains power, have an electrician wire it in.

Comments

TheAquaponicman (author)2017-12-06

What most people are failing to realize is with the optical isolated multi relay boards all the opto's high side are tied together through the 5 volt coming from the Arduino board. this means you have to connect the low side pins on the relay board to the output pins on the Arduino and set that pin to low to make the relay turn on, when the pin is high the relay will be off. if you do not declare this in your sketch setup the relay will be on from the start up because the pins are automatically set to low and your project will not function properly.

Setup ()

digitalWrite(RELAY1, HIGH); // This will Turn Relay 1 Off so when the loop starts your relay will be off......if not they will all be on.

aaryank4 (author)2016-12-03

I'm planning to do a home automation project
how can i interface 5V 4 Channel relay and a sim 900 module (without power supply) to arduino uno which has only one 5V pin and one 3.3 V ?
_I'm new to arduino

drmpf (author)aaryank42016-12-04

For an alternative and better means of powering the arduino/SIM900/relay boards see this project

http://www.forward.com.au/pfod/RoboticArm/index.ht...

It is a robotic arm powered from a 3A 5v supply via prototype shield directly to the Arduino 5V header pin. Note the capacitor 220uF on the prototype shield between +5V and GND close to the Arduino 5V pin Both the SIM900 and the relays draw current in spikes and the capacitor helps smooth these out.

Using this approach you would power the SIM900 from the Arduino +5V (plug the SIM900 into the prototype shield header) and also wire the relay +5V to the prototype shield 5V rail.

drmpf (author)aaryank42016-12-03

This tutorial shows you how to connect a SIM900 and a Mega and one solid state relay
http://www.forward.com.au/pfod/pfodSMS/SMS_HotWate...

An Arduino Mega is used as it has more RAM available then the UNO.

For your case of 4 relays, the free Android app pfodDesignerV2 lets you design an android menu and then generates all the code necessary to turn outputs on and off via SMS (using pfodApp). There is an option for a 128bit security password to prevent un-authorized people controlling the relays.

You may find the UNO does not have enough RAM to run the generated code. If you already have the UNO try it and see. Otherwise order a Mega.

What is left to do is to supply your 4Channel relay board with 5V from the supply and connect the digital outputs to the relay inputs to turn them on and off.

Both the UNO and the Mega have a polyfuse on the USB supply input. So if you find the Arduino keeps rebooting, it probably means you are drawing too much current via the Arduino USB input. In which case use a 7V to 9V (note not 12V) supply to power the Mega via the power jack and power the SIM900 and relay board from the Mega 5V pin.

In any case DO NOT use your computer's USB to power the Mega with the SIM900 connected as the computer's USB ports are limited to 500mA.

Contact pfod.com.au via support if you have any problems.

AssaliH (author)2016-11-02

Hi! I hope you can help me, I'm really a noob with this. I have a four channel relay board and my idea is to connect three different things that use different voltages and different amp.

It's a desk lapm that is now connected directly to 220v

A fan that is also connected to 220v

and a RGB led strip that uses a 12v 2.0 amp power supply. My Idea is to control the relay board with the arduino and centralize it in one sector of the room. How would I connect every device to the relay board? is it ok that all devices use different voltage or amps? I hope I made myself clear.

Thanks in advance!

drmpf (author)AssaliH2016-11-02

Hi AssliH,

Yes that is possible. but be careful 220V can kill you. It is recommended you get a electrician to wire the 220V parts.

Basically you take the two leads running to the device, say the RGB strip, and cut one of the leads and connect one of the cut ends it to the Common (C) and the other to the Normally Open (NO) relay terminals. When the relay operates it connects these two terminals together and joins the wire you just cut and your RGB strip turns on (if you have already turn on the 12V 2.0amp supply)

This tutorial, Home Automation for Beginners, shows you step by step and also shows you how to build a custom Android App to control the relays. No coding required.pfodApp handles all the Android side and the free pfodDesignerV2 lets you design your own menu and then generates all the Arduino code for you.

Iliyaaa made it! (author)2016-10-09

Very nice instructable. Exactly what I was looking for to switch a 12V optically isolated relay board. Thank you.

AmaanS6 (author)2016-10-03

Hello, I wanted to know if I could use an arduino relay for switching power to a whole house. (for switching between a solar power and main grid power lines)

drmpf (author)AmaanS62016-10-03

I think you would need to use the Arduino relay to switch the voltage to the coil of the HIGH POWER relay that actual switches between solar and mains power. The relays shown here only carry enough current for one power point. Not enough for a whole house.

Mark JanezS (author)2016-10-01

How do you control the relay?

drmpf (author)Mark JanezS2016-10-01

In the second picture above, Output D4 is connected to the relay. Make Output D4 high/low to control the relay.

If you are using pfodApp to control your Arduino from your Android mobile then you can use the free pfodDesignerV2 app to design the Android on/off slider user interface, interactively, and then generate the Arduino Code to connect to pfodApp to allow you to control the relay from your Android mobile, (no Android coding required)

You can connect to your Arduino with pfodApp via Bluetooth, Bluetooth Low Energy (BLE), Wifi, Ethernet or SMS

drmpf (author)2016-09-28

Added a section, Help My Relay Stopped Working (RC Snubbers)

killeriq (author)2016-03-11

Hello, i have i more question.

If i would use 5V 16 Channel relay board and switch it from Arduino:

1. use external power for 16xRelay board - Can i switch with Arduino all 16 Relays at once? does it still apply the 200mA limit?

2. if 200mA is applied ,do i need to switch it via some kind of power tunner?

This is the board

drmpf (author)killeriq2016-03-11

For that many relays I would use an external 5V supply to power the coils.

It is a bit hard to see what the circuit on the board is, but I assume there is at least a transistor driver to switch the relays.

I suggest you use a multimeter to measure the current needed to switch one relay and work out from there how hard you will be stressing the Adruino chip. I would keep the the total to 100mA or less, myself.

lemaxnut (author)drmpf2016-08-11

These relays draw only 40milli-amps @ 5V. But it is always a good idea to make it a habit of placing an ammeter between source and load. Also, most of these relays are switched on via an optocoupler, so no need for flyback diode protection. see my video: Control 8 relays, plus 2 servos, completely independently AND simultaneously with a $3.00 ARDUINO 'Nano' and a simple sketch based on Object Oriented Programming and State Machines methods,https://youtu.be/xOqstsdmj54

killeriq (author)drmpf2016-03-23

Need to wait till it arrives, then i can test, but the Relays are SRD-05VDC-SL-C, as i test it on the 8x relay board it was 33mA/relay

1. so if i want to use all 16 Relays at once, does the EXTERNAL 5V power supply to the Realy board makes any difference/help for Arduino board?

2. if not how to drive all of them at once?

Thanks

drmpf (author)killeriq2016-03-23

Did you measure the current from Arduino digital output to drive the relay IN? Should only be a 1 or 2mA.

16 relays at 33mA each coil is about 530mA, This greater than the 500mA USB ports normally provide but you could use a USB Wall adapter instead, say a 1A or 2A one, and power the Arduino from it and then use the 5V Arduino output to power the relays. Note: do not use the 7V to 12V Arduino input to power the board and relays as the onboard Arduino 5V regulator is not designed to handle this much current.

If you want to program the Arduino while the relays are being driven then use a powered USB hub to supply the power and to protect your computer's USB port from power overload.

The Arduino has a 1A resetting fuse in the 5V line but you should be OK at 530mA + some trigger drive current per relay.

Finally if you are using an UNO you will need to use some of the A0 to A5 pins to drive the relays. You can control the A0 to A5 as outputs by referencing them as Pins 14 to 19 in your code

lemaxnut (author)2016-08-11

Control 8 relays, plus 2 servos, completely independently AND simultaneously with an ARDUINO 'Nano' and a simple sketch based on Object Oriented Programming and State Machines methods.

boilermanc (author)2016-07-19

Hi! You mention that the ssr is not good for turning motors on and off. i have 30amp motors and was planning on using ssr. but not the right option? i should use something like this? https://www.amazon.com/SainSmart-4-Channel-Duemila...

and i should get a sheild to power it as well?

drmpf (author)boilermanc2016-07-19

It is not that you "cannot" use SSR for motor control. In fact most industrial application do just that. It is just that you have to take a lot of care to ensure the motor spikes don't destroy your SSR and vise vera. The design of the necessary protection is situation specific and beyond this posting (and my experience). The link you mention is a 240V 2A SSR and so is definitely NOT suitable for a 30A motor,

This article has some more info Solid State Relays Common Precautions

If you are just turning the motor on and off, I would suggest a heavy duty relay and a snubber. This posting has some info on snubbers.

Otherwise I suggest you search for a commercial solution for controlling your 30 amp motors and look at integrating that driver into your system.

drmpf (author)2016-06-25

A user has reported
"I was able to modify a 5V relay module to work w/ a 3.3V microprocessor by
following your suggestion of bypassing the LED that was on the board."

But as noted in this instructable, First try driving the 5v opto isolated relay board from the 3V3 output. It may just work without the mod.

Mjtrinihobby (author)2016-06-23

I love this instructable!

Anirr (author)2016-06-14

Working with 1 channel 5V
relay module. It trigger with LOW digital supply from Arduino UNO.


  • Does this relay working correctly?
  • Continuous use of this will it consume more
    power. (I planning to turn on some device for 10 to 20 min in a day)?
drmpf (author)Anirr2016-06-14

There are lots of different relays out there. Without a circuit I cannot tell precisely.
... BUT if it is advertised as Uno compatible and it is 5V then it is probabily OK

You can use a multimeter, in mA mode to check how much current is being pushed into the Arduino when the digital output is LOW. I would expect only a few mAs

Leaving the one relay on all day supplied from the arduino's 5V line should not be a problem.

VincenzoV2 (author)2016-05-04

I wanted to know if the food relay with 24 volts instead of 5 volts arduino risk of burning it ?

drmpf (author)VincenzoV22016-05-04

Not sure I completely understand your question.

If you mean a bare relay then NO. Unless you use a relay driver board like this one which will handle 5V to 24V relays but driven from Arduino.
http://www.freetronics.com.au/pages/relay8-8-chann...

If you mean a 24V relay board with built in driver circuits. Then choose one that advertises being Arduino compatible. That is you need one with a 5V control signal.

mutea (author)2016-03-07

Hello

please

I want someone design for me from A to Z Arduino sketch To control

Relays

If there is a cost , so we can talk about this

my mail mutea_sabir@hotmail.com

thanks

killeriq (author)2015-10-07

how do i messure Low/high trigger and the mAmp concumpsion?

Thanks

drmpf (author)killeriq2015-10-07

Do this Voltage check first if you are using a 3V3 Arduino board.

To check the trigger voltage, power up the relay module with 5V then connect the multimeter on volts from the input pin to gnd and see what reading is. If you are driving the relay module from a 3V3 board then the volts reading must not exceed 3V3.

For my high trigger relay input the reading was a few mV (i.e. 0.025V)

For the current mA reading, you need a multimeter set on mA current reading. Then wire up the circuit relay using a 5V (USB) supply so that you can trigger the relay ON and OFF. Then break (disconnect) the lead where you want to measure the current and insert your meter there, one meter lead to each end of the disconnected leads. It does not matter which way around the meter leads are. The trigger the relay again and measure the current.

There are two current readings you want to make.

i) the total current in the 5V supply lead to the relay when the relay is operated (ON). Your Arduino board 5V will need to supply this current, or you will need a separate 5V supply if the current it too high (many relays)

ii) the current in the trigger lead. (relay on and relay off) The Arduino output pin will supply this current.

killeriq (author)drmpf2015-10-09

Thanks for fast reply, just want to confirm i got it :)

1. Trigger voltage

a) if i got it right i have to connect Multimeter this way? as on picture?

b) should the value change when i put PIN possition to LOW or HIGH?

Thanks

drmpf (author)killeriq2015-10-09

yes looks good,

I would expect high trigger to measure <0.5V and low trigger to measure 5V,

but it depends on the circuit in the relay module so that why you measure it.

killeriq (author)drmpf2015-10-09

Thanks for reply...

one more thing: What happens when i take out the PIN for low/high trigger and keep it removed?

drmpf (author)killeriq2015-10-09

Test it and let me know. Depends on the circuit, which I don't have a copy of.

p.s. If you can find a circuit for this relay module, let me know.

killeriq (author)drmpf2016-03-05

Hello again, need some help :)

I got this board 5V 8x Relays i did connect it as on picture, recorded "BLINK" to trigger the relay (PIN1-8) with PIN13 (Arduino) but no light or action at all :(

With extra LED diod test is working fine.

I did try to connect the board with external supply and connect 5V or GND to one of the PIN1-8 to trigger it manually, but nothing :(.

1. How do i test the functionality of the board without Arduino? With PowerSupply and MultiMeter?

2. Maybe even trigger each Relay separately from the bottom of the board

3. What could be the 3rd PIN "COM"

I got 5V and 12V boards same types , but same issue :( Before i order new one and wait few weeks i want to be sure i tried all.

Thanks!

drmpf (author)killeriq2016-03-05

A bit difficult without a circuit for the relay board, but..

the presents of a COM and what looks like Opto-isolators on the board suggests that you need to connect the COM as well.

I would try COM to GND and then drive the IN8 high, i.e. just connect it to +5V (no Arduino connected)

That is connect it like the "Driving 5V optically isolated relay from Arduino" photo above.

Once that is working try driving with Arduino.

For the +12V board try connecting COM to GND and connecting IN8 to +5V. Let us know how you get on.

killeriq (author)drmpf2016-03-06

Hello,

Thanks for fast reply.

Here is what ive tried:

1. connect from - (minus Adapter 5V) to both COM,GND

+5V to any PIN1-8 or VCC - NO RESULT

2. i turn around connector to switch polarity on Adapter 5V

+5V to COM,GND and - to PIN1-8 - it LIGHTS UP

When i tried to connect - to VCC and pair VCC with PIN1-8 - LIGHTS UP also

3. +5V to VCC

- (minus Adapter 5V) to COM - NO RESULT

4. again i turn around connector to switch polarity on Adapter 5V

+5V to COM and - to PIN1-8 - it LIGHTS UP When i tried to connect - to VCC and pair VCC with PIN1-8 - LIGHTS UP also

----

I did try with MultiMeter if the polarity is right from 5V Adapter and its ok, so seems like the both 5V and 12V boards have it opposite.

Also the 12V relay board was powered by 5V (see pic) and its working also, so im confused what is it then...

1. On 12V board I connected VCC (GND) and PIN1-8 with MultiMeter and got 3.7V Value so is LOW trigger?

2. Did the same with mA setting - got 0.33mA - only on empty (not connected) PIN1-7, on connected PIN8 was 0 mA

Same results on 5V Board

killeriq (author)killeriq2016-03-06

So even the RED light on board goes on, it doesnt trigger the RELAY (i dont hear any TICK), even the connection is still between COM and NC, doesnt change to NO - to the 12v light bulb is still ON :( ahhh

killeriq (author)killeriq2016-03-06

Found solution over here:

From Arduino +5V to COM and VCC (both of them)

GND to GND

Then it switch the relay and TICK also :) Finally!!!

KentinH (author)2015-10-23

Hi,

I don't really understand how to choose between a 5v relay and 12v one ? what is the difference (except the input power ?)

I got Arduino resets troubles with a 5v relay board because I powered the coils with Arduino +5V, it's apparently caused by EMI, did you meet as well this problem ?

Thanks you

drmpf (author)KentinH2015-10-23

5v versus 12v usually depends on what power supply you have available that can supply the current to drive the relay coils. USB supplies are readily available with 2Amp plus so 5V relays are often convenient.

To use a 12V relay you need a driving circuit to convert from the Arduino 5V digital IO to the 12 coil. Buy one of the pre-built relay modules.

Most relay modules have a suppression diode built in across the coil, but if you were driving a stand alone 5V relay you will need to add your own diode.

So even if using a 5V relay, I recommend you use one of the inexpensive relay modules that isolate the Arduino drive from the relay coil.

KentinH (author)drmpf2015-10-26

Thanks a lot :)

drmpf (author)KentinH2016-01-06

Your EMI problems may be being made worse by an arduino hardware issue.

see the comment on http://blog.gmane.org/gmane.comp.hardware.arduino....

by Andrew Kroll (6 Jan 08:37 2016)

"I've been doing some testing here, and I have found a really neat flaw on the MEGA2560 rev3. This possibly may affect other boards using the ATmegaxxxU2 and quite possibly other boards as well.

Briefly, with an EMI frequency sweep from 80Mhz and 125MHz at 10V/M2 a fail will occur. Take one to your local CE lab and try it. The fail is pretty much near 100Mhz.On the schematic, from USBVCC there is a 100nF cap. According to the datasheet from Atmel, and in my own tests this is WAY too small of a capacitance value. Any sort of EMI disturbance, especially common mode perturbs the voltage, and causes the ATmegaxxxU2 to drop from the USB.
When I added 22uF tantalum capacitor, this problem went away, although I'm sure the 10uF recommended value would work as well. A ferrite is also used in many other designs, to get rid of any other higher frequencies, but I'm not sure if that is needed for a full-speed device."
adamleo39 (author)2015-10-09

I have a single relay without the labelling. How do I connect it to the arduino?

drmpf (author)adamleo392015-10-09

Put it aside and buy a relay module.

The problem is the current required to drive the relay coil directly is more than an Arduino output can provide directly. So to use that relay you need to add at least a transistor driver. See this reference for possible circuits https://developer.mbed.org/users/4180_1/notebook/r...

The exception is a Reed Relay as noted in this instructable. They have very low current requirements.

But as I said at the begining, easier to buy a ready made relay module.

drmpf (author)2015-09-04

Added section on FET shields.

aleee (author)2015-09-04

hey !
im using mega 2560, in my home automation project,which relay module will b compatible with it ?

drmpf (author)aleee2015-09-04

Any relay module with a 5V drive, which is most of them. For example
http://www.seeedstudio.com/depot/Relay-Shield-v30-...
which will plug straight in.
OR
for a single relay, one of the 5V opto relay modules available on line.

Opto isolated modules are preferable.

drmpf (author)2015-08-27

Added section on using High/Low trigger relay module with 3.3V module, e.g. ESP8266-01

Iqrar AliS (author)2015-01-06

i am doing my prject on home automation system using arduino sim900 and 4 channal relay module . . i have a prob with the sketch can you help me with that?

drmpf (author)Iqrar AliS2015-01-06

If you need more help post here or on the pfodForum (http://www.forward.com.au/pfod/forum.html) or email me via pfod.com.au at support

About This Instructable

137,685views

309favorites

License:

More by drmpf:Simple WiFi to BLE (Bluetooth Low Energy) BridgeRetrofit BLE Control to High Power Loads - No Extra Wiring RequiredAdafruit Feather NRF52 Custom Controls, No Coding Required
Add instructable to: