Uncategorized

Rpi GPIO pin’s High level signal possibly not High enough to switch off the 5V relay problem

Rpi GPIO pin’s High level signal possibly not High enough to switch off the 5V relay problem

Ask QuestionAsked 2 years, 9 months agoActive 11 months agoViewed 3k times1

This question was asked before here, but there was no answer 1 year ago. I’m facing the same issue:

I’m switching the same 5V relay (SONGLE SRD-05VDC-SL-C) using a GPIO on HIGH and this works, but then when I put the GPIO on LOW, it goes down to 0.15V (I checked with a multimeter) but the relay stays ON, it does not want to go OFF after being ON. I tried 2 other GPIO pins and it does the same. Is there any safe way to bring the voltage to zero so that the relay goes to the OFF state?

RELAY PINS:
VCC is Rpi PIN #04 (5 volts)
GND is Rpi PIN #06
IN is Rpi PIN #40 (GPIO 21)

  • So, initially when the GPIO pin is not exported yet, the relay is in OFF state.
  • Then when the GPIO pin exports 3.3v (HIGH) the relay switches to the ON state.
  • THE PROBLEM: Then when the GPIO pin goes to 0.15v (LOW) the relay STAYS TO the ON state. I checked with a multimeter and it really stays engaged despite the 0.15v tension on the GPIO signal wire.
  • Then if I disconnect the signal wire, the relay correctly goes to the OFF state.

5 years ago, somebody successfully used the exact same relay on a Raspberry Pi, so there has to be a way to make it work in 2018 too. http://www.instructables.com/id/Web-Controlled-8-Channel-Powerstrip/gpiorelayShareEditFollowCloseFlagedited Feb 28 ’20 at 1:42tlfong013,49633 gold badges77 silver badges2222 bronze badgesasked May 1 ’18 at 23:46that-ben18111 silver badge88 bronze badges

  • Comments are not for extended discussion; this conversation has been moved to chat. – Darth Vader May 2 ’18 at 13:38
  • 0.15V is close enough to 0 for any practical purpose. If you allow a wild guess, I’d say you’re trying to use 3.3V signal as 5V, which is indeed not close enough. Many relay boards have inverted inputs, that is, they are switched off by 5V. That would explain why yours always stays on. – Dmitry Grigoryev May 4 ’18 at 11:19 
  • @DmitryGrigoryev Interesting, thanks, I have ordered a 3.3V switchable relay module instead. This will solve the problem, I guess. – that-ben May 5 ’18 at 12:22
  • FWIW, I think this is a useful question! +1 It has certainly expanded the knowledge base on relays here. If there’s a lesson from all of this, perhaps it’s a cautionary tale on the hazards of buying stuff from irresponsible vendors? – Seamus Feb 28 ’20 at 18:55

Add a commentStart a bounty

2 Answers

ActiveOldestVotes5

Introduction

I found OP’s “GPIO pin Low not Low enough” question very interesting.

I agree with Jaromanda X in chat saying:

… relay triggers on LOW not on HIGH … when … LOW, it should be in it’s triggered state … so that may be why you think GPIO21 being LOW is not doing what you want!

In other words, OP seems to have asked the wrong question. Instead OP should ask:

Why Rpi Low can switch on relay but Rpi High cannot switch off. Is Rpi High not High Enough?

I browsed SE and found a similar FAQ:

*Rpi Low can switch on relay, but High cannot switch off, … *

Rpi cannot switch off, though I can switch off by GPIO.cleanukp, …

The FAQ’s answer is the following get around:

Don’t use Rpi High to switch off, instead Set GPIO to Input.

*A similar trick to GPIO.cleanup, which resets GPIO to Input”

Everybody says this trick works, but nobody explains why it works.

And there is a big problem with this set-gpio-to-input-mode-to-turn-off-relay is that you cannot initialize you system with relay off. Whenever you say something like below:

GPIO.setup(11, GPIO.OUT, inital = GPIO.HIGH)

Your system is initialized with GPIO pin high, but relay is already on.

Anyway, I was curious to know why the trick works, and more importantly if it damages or shorten Rpi’s life. And if there is a better way to turn off relay. So I did some experiments and summarized the results and conclusion below.

Op’s module spec

OP’s module is 5V Low Level Trigger One 1 Channel Relay Module DC AC 220V Interface Relay Board Shield LED Indicator for Arduino

OP's relay module - Arduino, 5V, Low trigger, 4mA activate
Songle relay coil

I agree Millways saying in chat that it should be PNP transistor input module

I guess the circuit is something like below:

Arduino relay circuit

Now I am trying to vary the IN to transistor base resistance from 220R to a higher value, hoping that now even Rpi GPIO High of 2.4V is high enough to turn off the relay.

pnp relay test

However, I very soon found OP’s relay module spec a bit unusual. It says drive current at least 4mA Ib, to switch on PNP BJT Ic to drive the 55R coil at 90mA. This implies a DC current gain of 90/4 ~= 20.

I found my first PNP to simulate OP’s module is not suitable, because the Ic(sat) too big. So I replaced it by 2N5401 (see appendix below for a spec summary), which at Ib = 1mA, Ic = 50mA, hFE already is 50.

In other words, this 2N5401 module input current of 1mA, 1/4 of OP’s module, is enough to switch on the relay. So I cannot simulate OP’s module of 4mA input, 2.4V+ relay switch off condition.

Instead, I just tried to bias the PNP BJT to trigger at 1.0V+, which is high enough to entertain RPi’s 0.6V- Low. And the trigger/activate deactivate band is around 0.2V-. I repeatedly verify that the trigger signal 0.2V to 1.0V will activate the relay and 1.0V to 2.4V (rpi’s high

So Rpi’s High of 2.4V+ must be able to switch the relay off!.

After manually tested the module using a 0~5V power supply unit to simulate Rpi/Arduino GPIO signals and found everything working as expected, the time has come to do the real thing: actually using Rpi GPIO signal instead of the 0~5v PSU, using an working python program.

But to my surprise, the program does NOT work!

The reason is that I forgot there is something called hysteresis. The relay switch hysteresis characteristic is as below.

Songle relay spec

/ to be continued, …

Why the set-GPIO-to-input trick can switch relay off

Rpi GPIO to relay module connection

/ to be continued, …

Appendices

2N5401 hFE, Ib, Ic, Vce(sat), Vbe(sat)

2N5401 Summary
2N5401 Ib, Ic, Vbe(sat), Vce(sat)

.ENDShareEditDeleteFlagedited May 25 ’18 at 14:46answered May 2 ’18 at 14:55tlfong013,49633 gold badges77 silver badges2222 bronze badges

  • WOW, what an elaborate answer! I’m reading this now. Thanks! – that-ben May 3 ’18 at 15:53
  • Welcome! …… – tlfong01 May 4 ’18 at 4:44   
  • This is an interesting (if highly speculative) post. Unfortunately it has nothing to do with the question, because the OP is not actually using the relay module in the other question linked to the question, and is not using an opto-isolator. In some of the diagrams above an opto-isolator is connected to the Pi Vcc – this is just inefficient, and does nothing that could not be done better with a single transistor. – Milliways May 4 ’18 at 9:46
  • Sorry. I might have misunderstood the original question. I thought the question was on a relay module with opto-isolator. If not, then my long answer is irrelevant. Now I tried again and added a short answer (at the beginning of the post). – tlfong01 May 4 ’18 at 13:27    
  • Just now I read the chat record and found that OP actually is using a pnp transistor type module which is not the opto-isolator type mentioned in the original question. Now I know why I am confused. My lesson learnt is this: Beside old answers and comments, also read chat record before giving a new answer. – tlfong01 May 5 ’18 at 2:08    
  • Yes, sorry, I didn’t realize at first that “SONGLE SRD-05VDC-SL-C” is not enough to identify how the relay module works. Also, an admin moved that bit of the conversation to the chat section (rightfully I guess) but it was directly below the question on the first day. – that-ben May 5 ’18 at 12:26
  • No worries. I only learnt about the chat thing when I read your post the third or fourth time. I am a 20 day newbie here, so I lost my way all the time. It is only last week that I knew the meaning of OP, > 3 etc. I have never used any 5V relay before, so to me it is a very good learning experience. So you saw in my long answer that I admit errors every now and then. I want to remember my mistakes so I will not make them again. Happy relaying! – tlfong01 May 5 ’18 at 13:37    
  • I have also read amazon relay products reviews and concluded that their products are very bad. It is not worth our time trying to fix the problem. – tlfong01 May 13 ’18 at 13:16   
  • Just so you guys know, I have just received a bunch of relay modules I’ve tested yesterday with my Raspberry Pi Zero W and those modules are 100% working straight from the Rpi 3.3v GPIO pins, absolutely no step up, resistor, transistor or anything else required: JQC3F-03VDC-C and JQC-3FF-S-Z and they’re both triggered by LOW, not HIGH. Also before receiving the 3.3v relay modules, I actually managed to make the OP relay (SRD-05VDC-SL-C) work perfectly fine using a ULN2003APG transistor IC. It may seem over-complicated, but this actually costs less than a 3.3v relay module! – that-ben Nov 8 ’18 at 14:12

Add a comment1

If you are using the same relay module (which has no meaningful documentation) there are answers. PS The number of negative comments on the Amazon site should serve as a warning to other purchasers.

As we don’t know what the module requires, we can’t answer definitively.

It appears to use an opto-isolator (WHY? this seems pointless – the relay is already isolated) and the GPIO may be unable to provide sufficient current.

One manufacturer seems to provide devices based on a PNP transistor, which CAN’T be controlled by the Pi UNLESS powered from the Pi 3.3V.

You may be better advised to seek a more suitable module.ShareEditFollowFlagedited May 2 ’18 at 0:16answered May 2 ’18 at 0:00Milliways47.2k2222 gold badges7878 silver badges153153 bronze badges

  • The 3.3v rail is not enough, it requires 5V to switch. The LED lights up on 3.3v but the relay itself is not switching. It does switch ON perfectly fine on the Raspberry Pi’s 5V rail tough! I also have a 3.3v to 5v step up regulator module, but I don’t think I can make use of it for this application. Anyway, here’s the exact relay module: aliexpress.com/item/… – that-ben May 2 ’18 at 0:12 
  • It has zero negative comment out of 59 votes on AliExpress, tough and I must say it switches to the ON state perfectly fine, it only wants absolute 0v to switch to the OFF state, which is what I’m seeking advice for. Wait… are you suggesting that instead of using the relay’s IN pin connected to the GPIO, I should use the GPIO connected to a step up voltage module and then connected to the VCC and IN pin both in parrellel? BRILLIANT, it could work, let me try this! – that-ben May 2 ’18 at 0:20
  • The module in your Comment IS TOTALLY DIFFERENT to that referenced in your question, and appears to use a transistor, but is equally lacking adequate documentation. This may be the PNP transistor module, which is unsuitable for the Pi. If you are thinking of using a boost voltage converter DON’T !!!! – Milliways May 2 ’18 at 0:21 
  • What do you mean they are different???? – that-ben May 2 ’18 at 0:39
  • As you mentioned, the voltage step up doesn’t work on this relay, when I measure the output of the step up alone it’s 5V but when I connect it to the relay, it goes down to 2.5V 😦 – that-ben May 2 ’18 at 2:03
  • Ended up buying a different type of relay, one that has a JD-VCC jumper on it, hoping it will work better and I’ve seen a multitude of tutorials using the relay I just ordered, so fingers crossed. Thanks. – that-ben May 2 ’18 at 13:49
  • If the “step up” drops to 2.5V, then it is not suitable and should not be used. Can you tell me what is the input to the step up? The input to the step up might be too weak, therefore overloaded. – tlfong01 May 5 ’18 at 13:23   
  • Well, your mentined JD-Vcc, I have another guess. Are you using 3V3 to power the module (at the V+, V-, Signal connector)? If so then you have a problem, because 3V3 is not strong enough to drive the magnetic coil. My module has the JD-Vcc thing, but I don’t use it, because I used another 5V0 to power the module. – tlfong01 May 5 ’18 at 13:28    

Add a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.