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) 
Milliways
  • 54,718
  • 26
  • 92
  • 182
Rod
  • 117
  • 1
  • 6
  • 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": https://electronics.stackexchange.com/questions/202680/relay-what-is-the-difference-between-low-level-trigger-and-high-level-trigger. Happy triggering. Cheers. – tlfong01 May 21 '20 at 01:27
  • 3
    some relay modules have a jumper to switch between high and low trigger – Jaromanda X May 21 '20 at 01: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": https://raspberrypi.stackexchange.com/questions/99988/rpi-gpio-controlling-5v-relay-problem. 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 '20 at 01: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": https://www.raspberrypi.org/forums/viewtopic.php? f=37&t=234552&p=1436656&hilit=relay+jumper+tlfong01#p1436656. Cheers. – tlfong01 May 21 '20 at 01:59
  • And here is the big picture: https://penzu.com/public/ea1dd169. Cheers. – tlfong01 May 21 '20 at 02:07

0 Answers0