Notes: It should be noted that the supply pin (Vcc) voltage needs to be the same as the logic level voltage (IN) pin for this relay to work. For example, you would need to use the 3.3V rail on a Raspberry Pi as its GPIO pins operate at 3.3V.
And realised that I was powering VCC using 5V.
So I tested using VCC at 3.3V from the pi and it does not switch. It quietly half-clicks, but doesn’t switch. So my relay does not seem to work at 3.3V
I can get it working using the 5V line and switching with the 3.3V GPIO line (as wired in the photo above) using this code:
import RPi.GPIO as GPIO
from time import sleep
relayPin=24
GPIO.setmode(GPIO.BCM)
GPIO.setup(relayPin, 0) # Relay clicks and green LED turns on
sleep(2)
GPIO.setup(relayPin, 1) # Relay clicks and green LED turns off
GPIO.cleanup()
Is there any risk in using it this way? Could I damage my pi?
Thanks, John
Can you confirm that the relay you are using is the one from the product page for this thread - the image isn’t quite clear enough to be sure. But if it is this one then it will not operate reliably with 3.3V logic levels, whatever the Vcc supply is. It might work, it might not. The fact that it works with one setting on the GPIO pins (whatever ‘setup’ actually does) and not with the proper setting (‘output’) indicates it is marginal. The flicker of the green LED indicates the same thing.
I would recommend a relay that is specified for 3.3V logic levels. It will likely also be specified for a Vcc of 3.3V also, because the logic signal is referenced to Vcc and Gnd.
Thanks for the quick reply.
Yes, I can confirm it is the one from the product page.
I looked up the source code for the setup function (raspberry-gpio-python / Code / [be8e4d] /source/c_gpio.c), but my C is somewhat rusty, so I am not sure what is going on.
Thanks for the suggestion to get another relay, but I think I might risk it
The pi is an original 1B (and I have another spare if it dies) plus the relay will only be switching 5V at 800mA so worst case it dies and I have to buy a new relay.
I will provide feedback to core as this is not working at 3.3V so they need to at a minimum change the description.
Hi John
A circuit for this device would be handy but as usual not easy to find.
Someone produced one some time ago when all this came up. I don’t remember if it was an official circuit or someone took the trouble to reverse engineer the board.
I think it was established that the logic signal is OK at 3.3V but for reliable operation the RELAY SUPPLY should be 5V. As you just found out. You must have got a relay that does not like the 3.3V.
I looked at the product page and it looks like that 3 pin header is marked Sig, Gnd, 5V. so where does the 3.3V for a relay supply come from. This is only somebody’s sketch on the page. The marketers have very cleverly obscured the screen print on these pins. If that pin is actually MARKED “VCC” then that would create much confusion. It looks to me that somebody has finally realised that 3.3V is out of spec for the actual relay and it needs 5V to be reliable. Then marked up the product page accordingly.
Personally I don’t care. There is not enough info available for me to evaluate whether the device will do my job or not so I personally would not purchase one. It goes to follow then that I am never going to look at one to find out what the screen print says.
Cheers Bob
Hi,
I also tested using the pin 1 3.3V like your picture. The relay switched correctly, so I guess it is the lack of current from the GPIO pin which is causing the issue.
Thanks,
John
I have one of these, buzzed out the circuit. (see pic below)
The DC coil resistance is 68ohms and draws 84mA when activated on VCC = 5V; 50mA on 3V3.
3V3 would not be reliable as the relay action is less positive.
A low on the IN pin will trigger it.
Hi James
Can’t work. Turn the transistor upside down. Emitter to VCC (positive), collector to relay.
Cheers Bob
Not a particularly good design if you are correct (which you are probably are except for transistor orientation) as VCC HAS to be 3.3V if you are using 3.3V logic. That means you can’t use a 5V relay supply in case the relay won’t work with 3.3V.
If you have +5V on the transistor emitter and only 3.3V on the base the transistor would be on all the time. Ir would be better if the transistor was a NPN as a low side switch so the relay could be powered separately.
@Robert93820 Thanks for picking that up Robert.
You are correct, the transistor looked wrong but I didn’t have time to check it fully this morning.
I have now edited the pic and reposted it. Looking at it now makes sense. Any pullup would need to be to VCC or higher to ensure the transistor is normally off.
The relay action is not very good at 3V3 and I would not trust it to be reliable long time. But the action is very solid at 5V. Past experience has shown these type of relays need about 70mA for a good solid switch.
You are right there. I think the make and break time for these relays is 10ms. It is anybody’s guess what it would be at 3.3V. I don’t anybody realises any other repercussions this slower operation will have on other things. Like switching larger currents with the longer arcing time. Anything like this might drastically reduce the life of the device.
I don’t have any of this type relay in the 5V range and if I did they would probably be Omron. I could measure the operate time at the lower voltage if I had one. I think I have a couple of this style (Omron)
at 12V and if I get the time and motivation I might see what the difference is at 66% of nominal. I think that once operated they will hold at the lower voltage but I would not use them to operate at this voltage. I hav a feeling that operate time could extend out past 20 or even 50mS. Whatever it is it would not be good.
To be honest I have had quite a lot to say in the past about operating these relays way outside specification but no one seems to take any notice. Even Core who continually market these things as 3.3V units. Some units which use low side switching or an opto transistor switch can have 3.3V logic and are able to have a 5V relay supply. That is all good. BUT if your schematic is correct that design is CRAP. I think I saw somewhere that these units need to have VCC the same as the logic voltage to work. That appears to be so.
As I am getting a bit fed up talking about this subject I think I will pull the pin on it with one last bit of advice
Use at 3.3V relay supply at your own risk and don’t complain if experiencing problems later.
Cheers Bob