Relay module for dummies

I’ve bought a 2-relay module, and as usual it came with no documentation. Here are the pictures:



(I’ve included the pictures attached as well just in case they remove the links).

I’ve been googling and I’ve found some info for (apparently) similar modules.

My main concern is how to wire the relay inputs (Normally Open, Common and Normally Closed). The printed symbol is not enough clear:

--\ K1 --
|  \    |
A   B   C

Which one are A, B anc C?

My second question is about the pins JD-Vcc, Vcc and GND in the left corner, of which JD-Vcc and Vcc already came jumpered. I’ve read that these are for an alternative power source so that the arduino only switches the LED in the octocoupler. I guess this alternate power source would be used to switch the relays. How do I know if I need to provide an alternate power source? What current and voltage would be needed, and why is the Arduino not able to provide it?

My third question is about the second group of pins in the right corner (GND, IN1, IN2, Vcc). I guess GND and Vcc should be wired to the arduino GND and 5V pins, and IN1 and IN2 control the relays state. I’ve read that for similar relay modules the inputs IN1 and IN2 are active low. Apparently, to ensure no relays turn on in startup or reset, this initialization would be required in the setup method:

 digitalWrite(relay_pin, 1);
 pinMode(relay_pin, OUTPUT);

Is this the case with my relay module? If so, why do they write in the pin before configuring it as output?

Thanks in advance.

img_1.jpg

img_2.jpg

relaycircuit.jpg

http://arduino-info.wikispaces.com/arduinopower explains everything.

When the relay is unenergized there is continuity between A and B. When you energize the relay it switches to provide continuity between B and C.

Chagrin: http://arduino-info.wikispaces.com/arduinopower explains everything.

When the relay is unenergized there is continuity between A and B. When you energize the relay it switches to provide continuity between B and C.

I've already read that page, but the module they use is different, so it is not clear if the wirings will be valid for mine's. I'm interested in the "Normally Open" case.

The "JD-VCC" thing is explained lower on the page under the "Optical Isolation" section. The eight relay board he has pictured is essentially the same as your relay board (although with six more relays).

"Normally Open" (NO) means that the contacts are open (no current passes through) when the relay is not energized or powered off, and "Normally Closed" (NC) is where there is continuity between the contacts when the relay is powered off. Going by your picture, to the left of the screw terminals the scribbles describe that the bottom screw of each set of three is the NC contact, the middle screws are the "Common", and the top screws are the NO contacts.

dlloyd:

Exactly. I have just tested it and was about to post it. Thanks man.

I'll post it in code as a precaution against future image removals:

--\ K1 --
|  \    |
NC  C  NO

I've been playing a bit with it and I'm afraid I'm using it the wrong way, or else it does not work as expected.

I don't want to fry the duino in case the module is defective, so I'm testing it with a 9V battery instead, via a voltage divider that provides Vo = 5V. I'm using just the 4 pins in the right corner (GND, IN1, IN2, Vcc). I've connected Vcc to Vo, GND to ground and IN1 to GND to try to switch the #1 relay on, but it was not enough. The led turns half on, but there's no click and the multimeter measures no connectivity. The Vcc voltage measures 2.6 V when connected to the voltage divider output Vo. If I disconnect the module, then Vo measures 5V.

So I've replaced R1 in my voltage divider with a potentiometer, and slowly increased Vo. I notched it up untill reaching 8.1 Volts disconnected, then I connected the module's Vcc to Vo, and still it was not enough to turn the relay on (Vcc measures 2.8 V). Then I increased Vo a little bit more to around 8.7 V disconnected, connected again the module and that produces a Vcc around 3V. That switches the relay on, a click can be heard and the led in the module turns fully on. When it connects, Vcc suddenly rises from aorund 3V to 7.8V.

So it seems that this module consumes more energy when the relay is off.

Is this normal? Would a duino output pin have enough punch to power this thing on just 5V? Should I use the alternate power source instead? If so, again, does anyone know which voltage and current are required?

Is this normal? Would a duino output pin have enough punch to power this thing on just 5V? Should I use the alternate power source instead? If so, again, does anyone know which voltage and current are required?

You could connect the relay module's VCC terminal to Arduino's 5V to power the module.

From this link it shows coil power: 0.36W, 0.45W.

Using P = V2/R, 0.45 = 25/R, R = 55 OHM (coil resistance). Using V = IR, I = 5/55 = 0.091 (91 mA is the coil's current draw).

So both relays energized should draw less than 0.2A from the Arduino's 5V supply. You should be OK ... it would be the same as having about 9 LEDs on at 20 mA each.

I've finished my tests. Here are my findings:

Each relay draws about 90mA (according to my measurements), so theoretically it is possible to use as many as 2 relays simultaneously, given that Arduino's Vcc pin can source 200mA max (refer here for your board's limitations). However, if there are additional loads connected to the arduino you might exceed this budget. In this case it is possible to power the relays with a dedicated power supply, and then only 2mA will be drawn from the arduino (enough as to light the LED in the octocouplers).

This alternative power source can be attached to the left group of pins, and it will be used to switch the relays. Again the source must be able to provide about 90mA per relay. I made my tests with a 5V 350mA phone charger. The alternative power source must be connected in addition to the arduino pins on the right block. Thus, Arduino Vcc and GND should remain connected to the right group of pins, and also IN1, IN2, etc to Arduino's digital output pins, while the secondary power source must be connected to JD-VCC and GND pins in the left, after removing the jumper. I've read that in this case Arduino's GND should not be connected. This is actually nonsense, since both GND pins in the module are interconnected (you can see this by looking at the soldered paths in the back side) and I think it is bad practice to leave the arduino's Vcc floating in the module, instead of having a common GND for all the power sources. When using the alternative power source, it is possible to connect the right VCC in the module to just 3.3V.

buffer_overfly:
The alternative power source must be connected in addition to the arduino pins on the right block. Thus, Arduino Vcc and GND should remain connected to the right group of pins, and also IN1, IN2, etc to Arduino’s digital output pins, while the secondary power source must be connected to JD-VCC and GND pins in the left, after removing the jumper. I’ve read that in this case Arduino’s GND should not be connected. This is actually nonsense, since both GND pins in the module are interconnected (you can see this by looking at the soldered paths in the back side) and I think it is bad practice to leave the arduino’s Vcc floating in the module, instead of having a common GND for all the power sources. When using the alternative power source, it is possible to connect the right VCC in the module to just 3.3V.

Just to be clear, when using the optoisolation:

  • Remove JD-VCC to VCC jumper
  • Connect Arduino VCC to VCC
  • Connect Arduino digital pins to IN1, IN2, etc.
  • Alternate power source positive to JD-VCC
  • Alternate power source negative to GND (any of the GND pins)

There’s no need to connect the Arduino GND to the GND of the module – and doing so will negate the optical isolation. The Arduino’s VCC is connecting to the anodes of the optocouplers and the digital pins are acting as current sinks, connected to the cathodes of the optocouplers. It’s functionally equivalent to connecting an LED to the Arduino VCC and a digital pin.

Chagrin: There's no need to connect the Arduino GND to the GND of the module

Agree

Chagrin: ...and doing so will negate the optical isolation.

This is what I don't really understand. Why would it negate the isolation? AFAIK when a second source is provided, the Arduino's Vcc is only used for the octocoupler, so why would it hurt having a common ground?

Each relay draws about 90mA (according to my measurements), so theoretically it is possible to use as many as 2 relays simultaneously, given that Arduino's Vcc pin can source 200mA max (refer here for your board's limitations).

You are misunderstanding that 200ma max current rating. The 200ma limit is the total you can draw from all the output pins at any single time, as it's a current limit inside the 328P chip. The limit on the shield 5V pin depends on how you are powering the board. If from USB power the 5V pin can source up to around 400ma or so (limited by the 500ma thermfuse), less the total current being drawn from the output pins. If being powered from the external DC connector you can usually get a could of hundred MA above that from the on-board 5 volt regulator.

buffer_overfly:

Chagrin: There's no need to connect the Arduino GND to the GND of the module

Agree

Chagrin: ...and doing so will negate the optical isolation.

This is what I don't really understand. Why would it negate the isolation? AFAIK when a second source is provided, the Arduino's Vcc is only used for the octocoupler, so why would it hurt having a common ground?

Well it depends on one's definition and requirement for 'isolation', as the relay contacts are already isolate the controlled circuit from the arduino circuit. The optoisolator only effectively if you both don't connect the grounds and you don't use the arduino's Vcc to power the relay coils. I never kind understood this common Asian relay module design because of that issue. If you are using a higher then 5vdc relay coils then the optoisolator kind of makes sense, but really it's the coil to contact isolation that is the real deal with relay applications.

It's the inductive spike from the relay coils that you're isolating from. I'll agree that the inductive spike is usually not a problem (as long as the module is properly designed with a flyback diode -- and it is); I'm just trying to set the record straight. OP never provided any detail about his project that would let us know if the optical isolation was appropriate or not.

The "VCC" pin on the relay module is only providing current to the LED side of the optocouplers. The "JD-VCC" pin is providing current to the transistor, optocoupler phototransistor, and the relay coils. There is appropriate isolation in that respect.

Chagrin: It's the inductive spike from the relay coils that you're isolating from. I'll agree that the inductive spike is usually not a problem (as long as the module is properly designed with a flyback diode -- and it is); I'm just trying to set the record straight. OP never provided any detail about his project that would let us know if the optical isolation was appropriate or not.

The "VCC" pin on the relay module is only providing current to the LED side of the optocouplers. The "JD-VCC" pin is providing current to the transistor, optocoupler phototransistor, and the relay coils. There is appropriate isolation in that respect.

They certainly can be set up to offer 'double isolation' if wired up properly, just overkill for many projects/applications in my opinion as most cases one would want to utilize the arduino's 5V pin to power the coils rather then the added expense to use an independent voltage source just for the relay coil power . Not a bad thing that they are 'over designed' in that matter as the price is very attractive and you can set them up anyway you wish. I've bought a few and they work fine. I've always questioned if the relay quality was up to pare with US manufactures but I've no way to determine that.

Chagrin: It's the inductive spike from the relay coils that you're isolating from. I'll agree that the inductive spike is usually not a problem (as long as the module is properly designed with a flyback diode -- and it is); I'm just trying to set the record straight. OP never provided any detail about his project that would let us know if the optical isolation was appropriate or not.

The "VCC" pin on the relay module is only providing current to the LED side of the optocouplers. The "JD-VCC" pin is providing current to the transistor, optocoupler phototransistor, and the relay coils. There is appropriate isolation in that respect.

Thanks for the clarification. There's no current project, but lets assume I might need optical isolation in the future. About the common GND, I was writting a small "how to" for future reference, and it was more intuitive to describe the wiring for the optical isolation mode as the normal wiring plus some other pins. I've now changed that and will keep Arduino's GND not connected. But I still don't really understand why it can be bad. Maybe because if the module breaks it might inject a reverse current through the Arduino's GND?

Other than this, my only doubt now is about the setup code, which I found in the link you posted I think:

 digitalWrite(relay_pin, 1);
 pinMode(relay_pin, OUTPUT);

Why the internal pullup? Is it needed for this module?

Why the internal pullup? Is it needed for this module?

There’s no need to worry about pull-ups, either at the Arduino or at the relay board.
Floating conditions (when the Arduino’s pins are un-configured) will have no effect and will not turn on the relay because this is an optically controlled (and isolated) device.
Remember that logic 0 (LOW) at the Arduino turns on (energizes) the relay, logic 1 (HIGH) turns off the relay.

However, resistor (R4) will be needed as in your previous diagram to limit the current through the IR led of the opto-isolator. This isn’t connected as a pull-up, it’s connected in series as a current limiting resistor.
EDIT: R4 not needed, already part of the relay board.

Other than this, my only doubt now is about the setup code, which I found in the link you posted I think: Code: digitalWrite(relay_pin, 1); pinMode(relay_pin, OUTPUT);

Why the internal pullup? Is it needed for this module?

That's just a function of how the relay boards opto input is wired to the arduino. It requires a output pin and set LOW to turn on the relay, and a HIGH output to turn it off. Putting this code in setup function and making the output pin HIGH early in the sketch is just a way to insure the relay doesn't 'glitch' on when first being powered up, especially if you are using an external DC voltage source to power the relay coils. Many begineers using these boards have a mental block about a digital output = high means turn off the relay channel and output = low means turn on the relay channel, but it's only a user mental limitation, not a coding problem. ;)

I agree ... forget about my R4 comment earlier (its already included on the relay board).

hey.. Relay works like a switch only..the thing is that it works from the 5v input signals from Arduino that turns it On or OFF..

for simple connections like connecting a Lamp all you need to do is

1) Take the live wire from the source, i.e your home and connect it to "COM" 2) take the live or positive wire of the Lamp and connect it to "NO" 3)COnnnect the Neutral of both the supply(the wire from house socket) and the LAMP together.

4)Vcc of Relay module to Arduino's 5v output 5) GND of relay module to Arduino's GND output 6) IF u are using the Relay no 1 then connect the 1st Relay's Input pin from the relay module to any of the Arduino's output pins as per your program.

Hope you find this helpful!

GOOD LUCK!