I have a basic question about Relay. My background is not related to electrical so I'm sorry if my wording is not correct.

I have a quite standard relay with 3 inputs: SIG, VCC and GND. And it has 2 LED, let's call LED1 for Relay power and LED2 for the switch. If I wire GND to GND, SIG to pin 31, and VCC to 5V, then I can switch the load by turning ON/OFF the pin 31. That means LED1 is always on and LED2 is toggle on/off base on pin 31 state.

Now I want to control the relay power programmatically so instead of wiring VCC to 5V, I wire VCC to pin 32. That means if I want to switch on the load, I will turn on pin 32 first and then turn on pin 31. But what really happened is that after turning on pin 32, LED1 is ON and then right after turning on pin 31, LED1 is off and LED2 is on which means I cannot switch on the load either.

Here is what I tested

#! /usr/bin/python

import RPi.GPIO as GPIO
import time


#turn on relay VCC
#turn on switch


Can anyone help to explain why I couldn't control both signals of the relay?

Updated: Here is the link to the relay: http://wiki.sunfounder.cc/index.php?title=Relay(HIGH)_for_Arduino_and_Raspberry_Pi


The two LEDs in the relay module have two different purposes.

D0 = Power supply status.

D1 = Signal (SIG) status.

So if you wan't to switch of the LED D0 you have to desolder it or the resistor R0, see schema below.

To connect a GPIO pin to Vcc is asking for disaster, it is rated at max 16mA and the relay module consumes (Relay 120mA 0 two LEDs) approx 150mA, nearly ten times what the GPIO is capable off.

enter image description here

  • 1
    The module still connects the 5V Vcc rail to the Sig (via a LED and resistor). The end result (unless the resistor was very high, in which case the LED would not light), this will present ~5V to the GPIO, and overload the substrate diode, which will eventually cause problems on the Pi. Why anyone would build a module with an emitter-follower remains unclear. – Milliways Sep 11 '17 at 10:08

First of all, you need to be sure that the pin that you're using has enough power to control the device, in this case, a relay module. Which is not true for most of the cases.

You'll need to wire up a transistor for powering the relay module. ie, you can use a circuit like this one to power it:

enter image description here

Your load will be the relay. + will be VCC pin and - will be GND. That way you're going to be able to turn on and off the relay using the pin, and then, you can change the state using the other pin.


There is no such thing as a "standard relay", you appear to have a relay module (ideally you should provide a link to the module).

One thing that is clear is that you can NOT supply power to any relay or relay module from a GPIO pin (which is limited to 16mA).

It is unclear why you you want to "control the relay power". The whole point of a relay is is used to control a large load with a small current. It would be possible to control the power, but this is NOT straightforward, simply using a NPN transistor would most likely prevent the module from working, to use a PNP transistor requires additional circuitry of moderate complexity.

  • If your goal is to keep the power consumption low , turning off the external modules while not using them is a nice way to reduce it. Otherwise, there is no point on doing that. – Luis Diaz Sep 11 '17 at 8:31
  • Thank you all for your response. I know that it only uses very small current but I just don't want to see the LED turn on all the time (I leave it in my room). I've just updated the link to the relay in the original post – Cold Rain Sep 11 '17 at 8:39
  • 1
    Frankly, based on the paucity of the data in your link, I would be reluctant to use this device, there are stacks of better devices available. If it is ACTUALLY using a NPN transistor in emitter-follower mode (as the Raspberry Pi link shows) it will be unreliable when operated from 3.3V, it certainly WON'T saturate the transistor, which will likely overheat. It will also provide 5V to the GPIO pin (when off), risking damage to the Pi. – Milliways Sep 11 '17 at 8:51

Raspberry Pi has 3.3V GPIO pins. Assuming your relay module needs 5V as VCC (as you write it's working correctly from constant 5V).

In your second configuration, my assumption without knowing the exact type/schematic of your Relay Module:

  1. GPIO pin 32 gives 3.3V to Relay Module VCC, apparently enough to light up LED1 (Power indicator)
  2. When it comes to activate the coil of the Relay (to switch Relay output) by setting pin 31, it would draw more current than your GPIO pin 32 can give, so LED1 becomes unlit, and relay might not switch correctly.

To control Relay Module 5V power from GPIO, you can use a transistor in switching mode to provide switched 5V output based on the state of a GPIO.

Or, if the VCC pin doesn't need more than a few milliamps, can use a 3.3<->5V level shifter to have an extra simple solution.

  • Thanks, I've just updated the link to the model in the original post – Cold Rain Sep 11 '17 at 9:00

So I see the consensus from everyone is that GPIO (32 this case) only can provide 16mA which is not enough to power on the Relay properly. I appreciate everyone for your explanation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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