# Raspberry Pi triggers relay before power is turned on.

#### Wilmer Kluever

Joined Dec 1, 2020
9
I bought a relay like this today for my raspberry pi, and I am encountering a very strange issue. I connected the 5v output to the VCC pin, the ground to ground and a GPIO pin to the IN pin on the relay. I opened python and assigned 'led' to 'LED(15)', which is very standard. THAT triggered the relay. If I run led.on() or led.off(), it makes no difference but assigning the gpio pin to a variable triggers it. Only when I run '(led = '')' thus unassigning the gpio pin from the variable, it disables the relay. Why is this? I am using the gpiozero library in python.

#### ErnieM

Joined Apr 24, 2011
8,078
Hi Wilmer. Seems like something is stuck.

From what I can gather looking at the picture of the relay it uses a BJT transistor and not a MOSFET to drive the relay. That kinda rules out any pull up in the Pi turning it on meaning you need a "real" voltage to turn it on.

Do you have a voltmeter to probe the IN pin to ground?

Next, in the reply box under the symbol that looks like "…\/" hit the "</> Code" choice in the drop down and paste your full code. Just paste the smallest program that has this problem.

#### Wilmer Kluever

Joined Dec 1, 2020
9
Yes I have a multimeter, but why should I measure the voltage on those pins?
Python code:
from gpiozero import LED
import time

led = LED(2)
Like I said, the "led = LED(2)" part triggers the relay when powered by 5v or 3.3v which is incorrect.

#### sagor

Joined Mar 10, 2019
318
Most of those relay types are active LOW. Maybe put a pull-up resistor on the line to keep the input high until such time you actually drive it low with some code.
Without pullups, that line may be floating low enough to trigger the relay.

#### AlbertHall

Joined Jun 4, 2014
10,776
Most of those relay types are active LOW.
I believe that module is indeed active low.

#### prairiemystic

Joined Jun 5, 2018
151
That relay board appears to be active low and for 5V logic - RPi is not 5V logic outputs.
If you configure the GPIO pin as an input it floats but clamped to RPi 3.3V plus a diode so 4V which still turns on the transistor.
"... logic ‘high’ level requires a minimum of about 4.2V on the input pin. Anything below about 4.0V will be interpreted as a logic low. A pull-up resistor may be advisable for some setups."
It's a crappy relay board design. This article modifies the board: https://www.instructables.com/5V-Relay-Module-Mod-to-Work-With-Raspberry-Pi/
Not the best way to go but I guess it worked.

#### Wilmer Kluever

Joined Dec 1, 2020
9
That relay board appears to be active low and for 5V logic - RPi is not 5V logic outputs.
If you configure the GPIO pin as an input it floats but clamped to RPi 3.3V plus a diode so 4V which still turns on the transistor.
"... logic ‘high’ level requires a minimum of about 4.2V on the input pin. Anything below about 4.0V will be interpreted as a logic low. A pull-up resistor may be advisable for some setups."
It's a crappy relay board design. This article modifies the board: https://www.instructables.com/5V-Relay-Module-Mod-to-Work-With-Raspberry-Pi/
Not the best way to go but I guess it worked.
View attachment 224737
Thanks I'll see what I can do. Also make sure I'm buying decent relays next time...

#### kaindub

Joined Oct 28, 2019
45
Rather than change the relay driver, to turn the relay on, set the output to a low. To turn off the relay, set the pin to be an input. It then goes into a high impedance mode and does not pull the base low.

#### AlbertHall

Joined Jun 4, 2014
10,776
Rather than change the relay driver, to turn the relay on, set the output to a low. To turn off the relay, set the pin to be an input. It then goes into a high impedance mode and does not pull the base low.
But then the gpio pin will be pulled up to 5V and the rPi is running on 3.3V. Read post #6