1

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/

4
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Darth Vader
    May 2, 2018 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. May 4, 2018 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, 2018 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, 2020 at 18:55

2 Answers 2

5

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)

.END

8
  • WOW, what an elaborate answer! I'm reading this now. Thanks!
    – that-ben
    May 3, 2018 at 15:53
  • 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, 2018 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, 2018 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, 2018 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, 2018 at 12:26
1

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.

8
  • 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, 2018 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, 2018 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, 2018 at 0:21
  • What do you mean they are different????
    – that-ben
    May 2, 2018 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, 2018 at 2:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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