Uncategorized
1
1

Devices I am using are:

1) Songle 2 channel relay module – https://www.electronicscomp.com/2-channel-5v-relay-module-with-optocoupler?gclid=CjwKCAjwvuzkBRAhEiwA9E3FUnbadf71q6h2pX_VsmrUK6x0c9dHQm9aZ0EjEIRIoKsbmvFoRhY96xoCbcUQAvD_BwE

2) Breadboard power supply module – https://robu.in/product/mb102-breadboard-power-supply-module-3-3v5v-arduino-solderless-bread-board/?gclid=CjwKCAjwvuzkBRAhEiwA9E3FUv8xyHVyNeRe8mcrdalrsXgTt5vg0q4JGdTITGhJbK6W5PAdKWy4XRoC64YQAvD_BwE

Connections which I have done are :-

Do keep in mind that I have used the Raspberry Pi for only GPIO pins connection to IN1 and IN2 of the relay module and power supply to the relay module is from that breadboard power supply module I have put the link to above.

1) JD-VCC of the relay module to 5V of the power supply module.

2) VCC of the relay module to 3.3V of the power supply module.

3) GND of the relay module to the ground of the power supply module.

4) IN1 and IN2 of the relay module to Raspberry Pi’s GPIO 13 and GPIO 6 pins. (No power supply is there from the Raspberry Pi).

only the relay status led is getting blinking, but not the relay switching sound is not being heard.

  • Sure I will edit my question. – Aditya Raghu Mar 27 at 17:16
  • Connect 3v3 from PI to VCC on 4 pin connector next to IN2, connect iN1 and IN2 to pi, connect a SEPARATE 12V supply to JDVCC and GND on the three pin connector – that is all you need – do not connect GND on 4 pin connector, when opto-isolated, you actually don’t need it. – Jaromanda X Mar 27 at 20:49
  • I actually have a relay with a 5V operating voltage, not a 12V. I put up the wrong link by mistake. I changed it just now. The thing is I don’t want to give any power supply from the raspberry pi, I want to give everything from the breadboard power supply itself. And I have tried what you said also many times actually, but I am getting the same result. – Aditya Raghu Mar 28 at 1:12
  • you definitely need vcc (next to IN2) connected to pi 3v3 … because that vcc forms a circuit, through an opto-isolater, and back through IN1/IN2 to control the relay … edit (removed rant about 5v, since you are not putting 5v there) – Jaromanda X Mar 28 at 1:17
  • also GND of the relay module to the ground of the power supply module which GND? the one on the JD-VCC headers (correct) or the IN1/IN2 headers (incorrect, see my comment do not connect GND on the 4 pin connector – Jaromanda X Mar 28 at 1:20
  • Sure then, I will try it out again and let you know asap. – Aditya Raghu Mar 28 at 1:40
  • You said you tried before, so don’t – Jaromanda X Mar 28 at 1:42
  • So what else shall I do? – Aditya Raghu Mar 28 at 1:46
  • I was kidding, of course do exactly what I suggested, and see if it works – Jaromanda X Mar 28 at 1:52
  • I am 90% sure that yours is a “low logic level trigger” module which Rpi cannot directly control. – tlfong01Mar 28 at 2:35   
  • @tlfong01 GPIO.setmode(GPIO.BCM) GPIO.setup(4,GPIO.OUT) GPIO.output(4,GPIO.LOW) time.sleep(15) GPIO.output(4,GPIO.HIGH) GPIO.cleanup() this is the code which we have used to trigger the relay using raspberry pi,we have connected 5v source to jd-vcc and 3.3v to vcc of the 4 pin header.Is there any harm in using the above method in the functioning of the relay. – Aditya Raghu Mar 28 at 4:50
  • My English is bad. My brain has been squeezed with too many foreign language stuff, so short term memory left is 5 times smaller than average. As I said earlier, I will draw you a picture later to confirm your complicated JD-Vcc wring, and also confirm your code. I appreciate your patience. – tlfong01 Mar 28 at 6:58  
  • @Aditya Raghu: Your program seems one off. You may read my demo program in the old post referred below. I am using a repeat loop to switch on and off the relay, so I can hear a click click song, and also use a oscilloscope to watch any noise or EMI. – tlfong01 Mar 30 at 4:59   

2 Answers

2

The specification of the relay board you linked to says it requires 12V to operate it.

  • Sorry, I just put up the wrong link. My relay needs 5V to get activated. The thing is when I connect the VCC and JD-VCC to the arduino, my relay is working fine but not from the breadboard power supply module. – Aditya Raghu Mar 28 at 1:05
0

Solution 1 – Add a resistor at the input terminal

Short Answer

Add a 4k7 resistor at the IN terminal. Rpi should now switch on/off the relay without any problem. Yes, it is that simple. If 4k7 does not work, read the long answer below to find a value that works.

Add 4k7 to IN

Long Answer

The OP’s relay is optoisolated, low level triggered designed for 5V Arduino. This type of relay switches on if input signal is less than 1V, and switches off when input is greater than 4V.

Arduino has no problem because its high low signal meets the spec. However, 3V3 Rpi’s low signal meets spec, but high signal is only around 3V, therefore cannot switch off the relay. In other words the relay is always on.

There are 5 methods to get around, and a schematic is helpful to explain.

Low trigger relay circuit analysis

Now a picture of the real thing – the OP’s relay and two similar relays I am testing.

OP's relay and two similar ones

Now I am using a jumper wire to connect IN to the following voltage levels, (1) Ground, (2) 5V, (3) 3V3.

Green LED is on if IN = 0V (Gnd), off if IN = 5V. In other words, it 5V logic compatible.

Howeve, Green LED is still on if IN = 3V3. This means 3V3 is not high enough to switch off.

I checked that the IN current at 0V = 3.8mA, at 5V = 0.001mA, but at 3V3, current is still high, 0.6mA.

in signal = 0V, 5V, and 3V3

Now that for the fixed input values of oV, 3V3, and 5V, the currents are 3.8mA, 0.6mA, and 0.002mA, and corresponding status of relay are On, On, Off. To make the relay 3V3 logic or Rpi compatible, the 3V3 current should be so small to cut off the optocoupler and therefore relay off.

To look at the whole picture of the relay characteristics, I used a adjustable voltage power supply to check the If vs In voltage, and plot a graph as below. Now I can see the trigger point is < 3.62V (On) and > 3.84V (off).

I need to modify the circuit so that the trigger band shifts down to below 3V, Rpi’s High signal value.

Relay optocoupler infrared LED current vs In signal

Actually it is very easy to shift the trigger band down to below 3V. The trick is to note that the corresponding trigger current is around 0.15mA (highlighted in orange). So just increase the current limiting resistor so that the current is below 0.15mA when Vin ~=3V (or 2.8V, to add a little bit of safety margin).

But if modified current limiting resistor too large, then photo transistor won’t saturate. So I did a couple of trials and errors and found 4k7 seems a good choice. The engineering trade off / experimentation is selfied below.

Solution 1 - add 4k7 to IN terminal

Now I have checked the LED current vs Vin from 0V to 5V, to make sure that the trigger band is not too narrow to cause a stability problem. So far so good.

Next step is to use a python program to verify that Rpi GPIO ~3V/~0.5V High/Low signal can directly drive the modified 5V relay.

Modified (adding 4k7 to IN terminal) If vs Vin graph.
.
.
.
.

/ to continue, …

The very long answer below is to be shortened later

I am 90% sure that your module cannot be directly controlled by Rpi. I will first point out the problems, then suggest ways to get around.

enter image description here

I will search my junk box to find a relay similar, and do some experiments to verify my guesses are correct.

Luckily I found a similarly looking guy. First thing first is to check out if it is (1) low logic level activate/triggerable, and (2)5V Logic compatible.

Me no English, so I selfie!

To show module (1) low activate, (2) 5V logic

Now that I know the relay module switches on when In1 is Ground, and off when In1 is 5V, I move on to test (a) how high, say, 3V or 4V can still turn it off, and (b) how low, say, if 1V or 2V can still turn it off.

There you go, selfies again.

Finding relay activate/deactivate signal voltages

Earlier I though my module similar to the OP is not Rpi compatible either. But I surprising found that its trigger points are approximately 1.8V- and 2.4V+. Since Rpi’s low level is < 1V, and high level > 2.8V, therefore Rpi has no problem switching it on/off. (Arduino high/low are approximately < 1V and > 4V, so also has no problem.)

So now I still need an example similar to the one OP has, to explain why Rpi’s low signal is OK to switch it on, but Rpi’s high signal is not high enough to to switch it off (without fiddling with the JD-Vcc jumper, which most newbies never heard of!). I searched my junk box again, and did similar engineering experimentation with the results below.

enter image description here

Now the time has come for me to answer the OP’s question about using the JD-Vcc way of supplying power to the relay, and an example of Rpi Python code to control it.

I am using a relay recommended by Forbes. You might like to read the following Forbes article before I explain. But the picture first.

Everything You Need To Set Up Raspberry Pi Home Automation – Don Reisinger, Forbes(recommending an optoisolated, low level trigger relay) https://www.forbes.com/sites/forbes-finds/2018/07/12/everything-you-need-to-set-up-raspberry-pi-home-automation/#7c65bdb04cdb

Forbes low trig opto relay

Will this code harm rpi, and how does JD-Vcc work?

GPIO.setmode(GPIO.BCM) … code used to trigger relay using raspberry pi, connected 5v source to jd-vcc and 3.3v to vcc of header. Is there any harm in using the above …

connected 3.3V of relay to 3.3V of the RPi. JD-VCC to 5V of the power supply. ground of relay to ground of power supply. Now it’s working. The question now is, why isn’t the relay working when I connect the VCC of the relay to 3.3V of the power supply. …

To answer the above questions, we need first to see how the photocoupler works. Here is the picture.

EL87C and EL354 Photocoupler summary notes

Now that we know the specification of the photocoupler, we can do some quick and dirty calculations, to make sure that the relay will not harm you rpi GPIO.

Not using Rpi’s 40 pin connector’s 5V, 3V3 power pins to power relay

Just now I read your question again and I gave it an up vote, because of the more than ten user questions I read so far about this FAQ topic, yours has the most detailed description of the frequent newbie problem of Rpi not being able to turn off a low level trigger relay which Arduino has no problem, because the relay was designed for Ardunio, perhaps before Rpi was born.

I particularly appreciate your specifically pointing out that you are using the external power supply unit, even with a web link. This is a very important guideline for newbies often connecting the wrong wires by mistake. Actually I have been using Rpi for 5 years, and I NEVER USED the RPI’s 40pin connector power pins to power any external device.

Low Trig Opto EL817C 5V Relay Rpi GPIO Input Current Requirement Calculation

enter image description here

Working backwards, Ic needs only 1mA. Working forward, If 5mA would generate 10mA Ic, fully saturate photo transistor. Conclusion – Rpi GPIO Low need only 5mA to fully saturated photo transistor.

The question is Rpi GPIO High too High to cut off photo transistor?

Now I am going to measure the current flowing into low level signal (power ground, or Rpi low). The objective is to check if current flowing into Rpi GPIO signal pin is too large to damage the Rpi. I am going to check two types of low level relays, (1) without optoisolation, (2) with optoisolation, similar to the OP’s relay. The results shows that for this relay, signal current is between 0mA~4mA, safe enough for Rpi, but not compatible to Rpi, because Rpi High is not high enough to switch on this relay.

The second relay tested is low trigger PNP type relay, as shown on the left of the schematic below. One way to get around the Rpi high level signal is not high enough problem is to increase the series resistance, so that less current flows into the LED and therefore cannot drive the photo transistor into saturation.

Next to measure the current for OP’s opto isolation type low trigger relay.

No opto isolation relay low signal current measurement

Now I am measuring the currents of the optoisolated, low level trigger relay that looks similar to the OP’s dual relay module. However, the OP’s module does not work with Rpi, unless Vcc = 3V3, and JDVcc = 5V. For this relay just tested, JdVcc = Vcc = 5V works for both Arduino and Rpi.

enter image description here

If If is only -2mA, I need to check the CTR at this point and see if Ic and Vce(sat) etc. So I checked out the CTR pic and found CTR at 2mA is 70%. So Ic is 2mA * 70% = 1.4mA, should be safe enough, …

EL817C CTR at If = 5mA

To avoid frying Rpi, first test manually, by hand, using a jumper wire to select hardware signals, from breadboard PSU module, 5V, 0V, 3v3 power rail, and 555 square wave etc, to test relay, BEFOREusing Rpi GPIO by python program.

Youtube showing a NE555 timer 1Hz square wave, switching on/off a 5V Rpi incompatible, low level trigger, optoisolated Relay

Summary of three Relays Tested So Far

Now I am going to write a Rpi Python program to toggle the third relay module. First, a summary of the three relay modules so far tested.

(1) 5V dual channel, with optocoupler, low level trigger. This relay is identical to the OP’s relay, except one thing:- OP’s relay is NOT Rpi compatible. This one is. Because I cannot repeat OP’s failures using this module, so I found the second relay to try.

(2) This relay module has not optocoupler, but only one PNP BJT directly driving the Songle relay switch. Since this is not like OP’s module with optoisolation. So I tried another one.

(3) This is similar to OP’s modules, but only single channel, and without JDVcc jumper for separate control logic and relay switch power supplies. I found this NOT Rpi compatible, so is ideal to test out for the OP’s question.

The Rpi Python Program to use logical level shifted up GPIO signal to drive relay.

OP has at least three ways to get around, (1) Using JDVcc and Vcc PSU, (2) Setting GPIO pin to input, in order to switch off the relay, (3) using a logical level shifter to convert Rpi GPIO 3V level to 5V.

I think the first two solutions are not safe for newbies. For newbies, I recommend to shift Rpi 3V signal to 5V. The program written below is for this solution.

Now I have debugged a little python program to toggle the relay which in turn drives a 12VDC motor and a 12VDC solenoid at the same time.

Next step is to check the level of back EMF, EMI which transmit back to the Rpi side and successfully isolated by the optocoupler, …

youtube of Rpi driving relay to control 12VDC motor and solenoid

Back EMF Check of Four Inductive Loads (Motor, Solenoid, Water Pump, Solenoid Valve)

enter image description here

enter image description here

youtube video of relay driving 4 inductive loads

Optoisolated Back EMF Voltage

Input signal seems almost completely optoisolated. Next is to compare relay WITHOUT optoisolater.

enter image description here

enter image description here/ to continue, …

  • thank you so much for your help. According to the above circuit diagram of yours, I connected VCC of my relay module to 3.3V of the RPi and the JD-VCC to 5V of the breadboard power supply. And I connected the IN1 and IN2 pins of the relay to GPIO pins. Now it’s working perfectly. But just one more thing, may I know why when I connect both the VCC and JD-VCC of the relay to 3.3V and 5V of the breadboard power supply module, it’s not working? Why only when I connect it to two separate sources it works? May I know the reason why? – Aditya Raghu Mar 28 at 16:48
  • Just a quick reply. Perhaps no common ground, or no ground for Rpi sink driver to return current. I need to look at the schematic again later. Perhaps you can also check the current loop and common ground thing. This is also a FAQ and common newbie trap. Have a nice DIY weekend. – tlfong01 Mar 29 at 9:26
  • Before I make a long reply, you might like to skim my other long answer in the following post. Take note of the activate current of 70mA of the relay switch. I will use that to calculate the safe current of the Rpi sink driver. The manual testing of using a jumper wire to test an opto low trig relay is also useful. I will also extend that to explain the separate JDvcc and Vcc separate power supply and no command ground problem. raspberrypi.stackexchange.com/questions/27928/… – tlfong01 Mar 30 at 2:43
  • I skimmed my old post above and found that I mentioned the following: FAQ1 – How to power Rpi and relay module and tie grounds together, FAQ2 – How to avoid floating input problem. These are actually old answers to your new questions here. But I forgot where I put the answers which are scattered all over the place. I need to google search my own rubbish, tidy them up and perhaps post it here. – tlfong01 Mar 30 at 3:13

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

============================================================================================

0

A am using working on a project that requires a camera analyzing some images and activating the appropriate GPIOs to control a relay board. I currently have a touchscreen display, a Raspberry Pi Cam attached to the Raspberry Pi. I am trying to connect a 16 channel relay module to control some motors. Here is the specific relay module I am using: https://www.amazon.com/SainSmart-101-70-103-16-Channel-Relay-Module/dp/B0057OC66U/ref=asc_df_B0057OC66U/?tag=hyprod-20&linkCode=df0&hvadid=311990496852&hvpos=1o1&hvnetw=g&hvrand=16991409045459790175&hvpone=&hvptwo=&hvqmt=&hvdev=c&hvdvcmdl=&hvlocint=&hvlocphy=9028086&hvtargid=pla-405660916688&psc=1 I looked at videos online about how to connect, however whenever I run it, nothing happens. The relay module has an external 12V power supply, which I connected. And I have connected all the GPIOs that I wanted to use from the Raspberry Pi to the relay board. IN addition, I connected the 5V and 3.3V connections to the 2 5V pins on the relay module (I used the 3.3 because the other 5V is being used to power the touchscreen display). I have checked all the voltages and everything seems fine. Whenever I run the following code, nothing seems to happen:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.serwarnings(False)

x = [27,28,29,32,31,36,33,38,35,40]

for y in x:
    GPIO.setup(y,GPIO.OUT)
    GPIO.output(y, GPIO.HIGH)
    time.sleep(0.5)
    GPIO.output(y,GPIO.LOW)
GPIO.cleanup()

Connections from Raspberry Pi

Connection to Relay

Overview Connections

migrated from superuser.com 14 hours ago

This question came from our site for computer enthusiasts and power users.

  • What is the point of connecting 3V3 to a 5V input? Why not split the 5V line? You need to add clear photos of your wiring if you want practical help. – joan 14 hours ago
  • I didnt have anything to split the 5V with… – Sajid Khan 10 hours ago
  • Perhaps it uses 5V logic. See if it switches if you connect 5V to one of the relay inputs. – joan 9 hours ago
  • This appears to use opto-isolation. There are many similar modules on the market and frankly they are unsuitable for the Pi. Get a module with logic inputs. – Milliways 9 hours ago

2 Answers

0

The relay module you linked (which has limited documentation) states:-

12V 16-Channel Relay interface board, and each one needs 15-20mA Driver Current

The Pi GPIO can (safely) sink up to 16mA – and if using all relays would overload an Arduino, and probably the Pi.

Of cause this is assuming the Pi could even drive the opto-isolator, but if this has a series LED and resistor is unlikely.

Powering from 5V is dangerous and is likely to blow up the Pi.

The comments on the Amazon site indicate it us unsuitable for use with the Pi.

As an aside there is absolutely NO POINT is using an opto-isolator with a relay! Any additional isolation they claim to supply is illusory if there is ANYcommon connection between the two. Opto-isolators have a low current transfer ratio – which just makes it harder for the Pi to drive.

There are a number of (poorly-designed) relay boards on the market – they MAY work with an Arduino, but are unsuitable for the Pi. (There are quite a few posts on this site discussing these.)

There ARE modules (without opto-isolators) designed to be driven by 3.3V logic levels which are suitable.

You could drive this from the Pi using a transistor (if you haven’t already blown the Pi).

0

Question

  1. relay module has 12V power supply, …
  2. have connected all the Rpi GPIOs relay board, …
  3. connected 5V and 3.3V connections to the two 5V pins on the relay module (5V is being used to power the touchscreen display) , …
  4. Run code, nothing happen, …

Answer

It is not clear why you connect 3V3 power to 5V. And it is not clear if your 12V power relay accepts Rpi GPIO 3V3 signals.

The most newbie proof way is to use 3V3 relays which are a bit expensive (see Appendix A below).

Cheapy relays are mostly 5V powered, but only those High level trigger types are almost guaranteed to work for Rpi.

Almost half of those Low level triggered relay work for Arduino, but NOT work for Rpi (See Appendix B for get around).

And avoid using 12V powered relays, because newbies always connect the wrong wires to Rpi GPIO.

Appendices

Appendix A – Rpi Compatible 3V Relays (very expensive!)

PiFace Raspberry Pi Relay Board – £27

WaveShare Raspberry Pi Relay Board – $19

SeeedStudio Raspberry Pi Relay Board – $25

Using the Seeed Studio Raspberry Pi Relay Board – JM Wargo 2017feb14

Appendix B – Get Around for Arduino Compatible Low Trigger Relay not Working for Rpi

Get Around for Arduino Compatible Low Trigger Relay not Working for Rpi

 

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: