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/

tlfong01
  • 4,847
  • 3
  • 12
  • 24
that-ben
  • 219
  • 3
  • 10

2 Answers2

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

tlfong01
  • 4,847
  • 3
  • 12
  • 24
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.

Milliways
  • 62,573
  • 32
  • 113
  • 225