4

I would like to use a 8 channel relay of SainSmart for house automation:

http://www.sainsmart.com/8-channel-dc-5v-relay-module-for-arduino-pic-arm-dsp-avr-msp430-ttl-logic.html

This Relay module works with the raspberry ONLY if you add some resistors and transistors to each channel, because the logic of Raspberry Pi is 3.3 V. This is described here:

https://docs.google.com/file/d/0B5-HND9HJkXWSTQtYlFTZ3VyODA/edit?usp=sharing

However, I found there is an 'Adafruit 8 Channel Bi-Directional Logic Level Converter' here: http://www.pi-supply.com/product/adafruit-8-channel-bi-directional-logic-level-converter/

Will this Logic converter work properly? or should I follow the diagram instead?

  • You need to get back to SainSmart and get clarification. The added resistor/transistors they use for the Pi seem to be turning the system from active low to active high. Why not just use the relay as active low (i.e. invert your software logic), I bought the cheapest 8Ch relay I could find on eBay. It turned out to be active high, youtube.com/watch?v=RDrZDYGRj90 – joan Apr 24 '14 at 7:40
3

You don't need any additional hardware.

The board uses active low optocoupler to switch on the relay. But since the Pi is 3.3V, when the Pi put a pin high (3.3V). But if the relay board is powered by 5v, this 3.3V is still 1.7V lower, and the optocoupler will (apparently) trigger.

To fix this you can just remove the jumper that connects JD-VCC to VCC. Next connect 5V to the JD-VCC pin, and connect 3.3V to the VCC pin. If you look at the schematic on sainsmart you'll see that VCC is only used to power the led inside the optocoupler. While JD-VCC is used to activate the relay. Originally the jumper connected JD-VCC to VCC so both would be 5V.

Another option would be to set the GPIO pins to INPUT when the relay needs to be turned off. This will prevent any current from flowing (where it did when you'd set it to 3.3V). To activate the relay, set the GPIO pin to OUTPUT and LOW

Third option would be to add a resistor between the GPIO pin and the IN of the board. You'd have to find a suitable value that will disable the optocoupler when 1.7V is applied, but not too high that it won't work on 5V.

  • 1
    It seems you are correct. When I looked at the site it did not mention optocouplers, and many of the links did not work. It makes you wonder why the suppliers didn't suggest connection to 3.3V. It makes you wonder at the logic of using an optocoupler, and connecting both sides to the same supply! – Milliways Apr 25 '14 at 2:00
  • Indeed Milliways. I think they are just reselling the board under their own name. And they just copied some documentation of one of their users, who used it with a Pi. If you go to the github link attached to the second video, the person actually added a warning saying This was formerly stated to be for the SainSmart relay modules, but it was later pointed out to me that these boards actually already have this logic built in to them. – Gerben Apr 25 '14 at 16:16
  • I'm just get a bit more confused. What are the caveats of just following the diagram provided by SainSmart? And what about if separate the power source of the module and the RPi? – Mr_LinDowsMac May 26 '14 at 22:18
  • The sainsmart diagram requires additional components, while there is no need for it. The fact that they suggested that tells me they don't know their own hardware. It is not safer or anything. Adding an additional power supply isn't necessary. – Gerben May 27 '14 at 7:43
  • 1
    Gerben - To clarify, I say to not power the relay coil(s) through the pi because each coil can use ~70-80mA. So while the pi will easily power one or two, once there are 8 channels (as the OP has) if all get tripped at once you will pull 600mA, which is probably enough to trip the fuse in the pi... (and while in most cases you're right about them coming back, I have personally waited 24 hours for one of these to reset on the pi 2...) – alphacharlie Jun 25 '15 at 20:57
1

The relay module requires 20mA ea which is more than the Pi can supply, so you will need drivers. The circuit in "Driving a relay" of http://elinux.org/RPi_GPIO_Interface_Circuits shows how to do this.

The level translator is a low power device and won't help. Indeed it is generally unnecessary to translate Pi outputs. This would be appropriate to drive Pi inputs from 5V circuits.

  • 1
    The 20mA is per energised coil and will be coming from the 5V rail. So the Pi would need to supply 160mA on the 5V rail to energise all the coils which it can do. – joan Apr 24 '14 at 7:31
  • The relayboard in question already has the transistors on board. The problem was that current will still flow when the GPIO pin is set to HIGH. That i, current would flow from the 5V of the board, through the optocoupler, to the 3.3V. – Gerben Apr 24 '14 at 18:19
0

I've got one of these, but with 1 relay instead of 2. I couldn't get it to work with 5V, but just plugged 3.3V into the VCC and it suddenly works with a Pi (active low).

Pi 3.3V --> VCC

Pi GND --> GND

Pi wiringPi pin0 --> Signal pin

-1

Apparently there are quite a few of these modules which look "exactly alike". I suspect they would all have similar electrical properties, but you can run a simple test to see if they are safe to connect to a Pi directly. This is what the "Pi side" of circuitry of the module looks like:

5V ------///------|>|------|>|------- control pin

There are two forward biased diodes (the LED and the one in the optocoupler) and a resistor (1K in my case) in the path from the 5V supply to the pin for connection to the Pi. The diodes seem to cause a sufficient voltage drop to make the connection safe.

o Connect a 5V supply to the module.

o Measure the voltage between any one of the 8 control pins (for connection to the Pi outputs) to the ground. In my case this was 2.8V, indicating that a total of 2.2V remain as the junction potentials on the diodes. (LEDs and the optocoupler LEDs -probably a GaAs version- have larger junction voltages than ordinary diodes.) This 2.8V is the highest potential that this pin will see, unless current is forced into the module - even then, it will be limited by the voltage produced by Pi.

o Next, set your multimeter into the current measuring mode and measure the current from this pin to the ground. You will notice that the relay trips, and the LED will light up. This corresponds to the maximum current that the Pi pin will have to sink. In my case this is about 2ma. (There is a 1K resistor in the path - there is no way this current can be 20ma. Other interesting things would happen if a 20ma current were to flow through a LED so small.)

So, for my module, I saw no reason why not to connect it directly to the Pi pins directly. Obviously, now a "0" on the pin means "on" and a "1" (or tri-state) on the pin means "off".

[Original source]

  • 1
    Welcome to the RPi StackExchange, @mcy. While it is important to cite sources, we generally try to discourage link only answers, since they're prone to rot. If you could add a high level summary of what the link contains, that would improve your answer a lot. If you haven't already, please take a look at the help center. raspberrypi.stackexchange.com/help/how-to-answer – Jacobm001 Jun 23 '15 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.