0

Given:
Raspberry Pi3
Sunfounder 2 channel relay
plugged into 3.3v
plugged into ground
plugged into pin 18

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)

GPIO.output(18, GPIO.HIGH)
time.sleep(5)
GPIO.output(18, GPIO.LOW)

The light on the relay comes on only when I swap the high and low in the code that I saw on YouTube. Why is mine working backwards?

Mine has to be like the following snippet:

GPIO.output(18, GPIO.LOW)
time.sleep(5)
GPIO.output(18, GPIO.HIGH) 
5
  • 1
    Ah, there two types of relays: Yin and Yang. The following ENC SE Q&A clarifies well: "Relay : What is the difference between Low level trigger and high level trigger? Asked 2015nov25, Viewed 39k times": electronics.stackexchange.com/questions/202680/…. Happy triggering. Cheers.
    – tlfong01
    May 21, 2020 at 1:27
  • 3
    some relay modules have a jumper to switch between high and low trigger May 21, 2020 at 1:38
  • 1
    And in case you think your relay is of the "wrong" type, and wants to get a "correct" one, here is a relay shopping guide: "Rpi GPIO Controlling 5V Relay Problem Asked 2019jun26, Viewed 1k times": raspberrypi.stackexchange.com/questions/99988/…. And if you are of the "can't make up my mind" type, you can, as @Jaromanda X suggests, get a "Jumper select High/Low trigger relay". Happy locking down shopping. Cheers..
    – tlfong01
    May 21, 2020 at 1:40
  • 1
    One more confusing thing: Beside the High/Low trigger select jumper, there is another JD-Vcc jumper: The following confusion guide might help to clarify or confuse newbies further: "Relay Newbie Total Confusion Guide (High/Low trig jumper vs JD-Vcc High/Low Vcc jumper) - Rpi.org Forum": raspberrypi.org/forums/viewtopic.php? f=37&t=234552&p=1436656&hilit=relay+jumper+tlfong01#p1436656. Cheers.
    – tlfong01
    May 21, 2020 at 1:59
  • And here is the big picture: penzu.com/public/ea1dd169. Cheers.
    – tlfong01
    May 21, 2020 at 2:07

0

Your Answer

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

Browse other questions tagged or ask your own question.