I am currently using Raspberry PI to to control a 2 switch relay. I am testing it with the most basic code just switching one of them on and off. Before I connect it to something live I want to make sure I have this figured out as it seems there is something weird going on. It seems like my states are the wrong way around.

Here is my code:

import RPi.GPIO as GPIO

Now the issue is with the last line. The moment I use that command my GPIO pin activates however, on all tutorials this is not the case.

The next part is if I call:


I would expect it to turn off however I need to use:


To power it off. To be honest it doesn't make much of a difference however I don't like the fact that it is on by default. Apart from that it works as expected. Tested with LEDs and had the same effect.

I am really new so might be missing something simple. Any help would greatly be appropriated.

1 Answer 1


Some relays are active high (switch on with a high input) and some relays are active low.

Whether LEDs light when a GPIO is set high or low depends on how you wire them.

If you have GPIO - resistor - aLEDc - Ground the LED will light with a high GPIO and go off with a low GPIO.

If you have GPIO - resistor - cLEDa - 3V3 the LED will light with a low GPIO and go off with a high GPIO.

The a (anode) and c (cathode) either side of LED indicates their orientation.

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.