-1

I am a complete newbie here. I bought RPi, flashed the OS. I also bought 5v relay. I have connected the 2nd pin to VCC of the relay, 6th pin to GND of the relay, 40th pin to the 'IN' point of the relay. At present I have not connected anything to the other side of the relay (but the problem also exists if I connect a load of led). Also no other changes have been made to the RPi except the SSH connection enablement and software update using sudo apt get commands i.e RPi is almost at factory settings. My Code:

import RPi.GPIO as GPIO
import time

in1 = 21 //i.e 40th pin

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

try: GPIO.output(in1, GPIO.HIGH) //1 time.sleep(1) GPIO.output(in1, GPIO.LOW) //2 print("inside try after low") //3 time.sleep(1)

except KeyboardInterrupt: GPIO.cleanup() //4

My problem: Once the relay turns high at comment //1 it does not turns off at point //2. I kill the program using 'control + c' then it turns off which is not what I desire. I just want it to turn on and then turn off. The point //3 does get executed. //4 executes when ctrl+c pressed. If I remove cleanup code and do not press ctrl+c then the relay's green light remains turned on continuously. P.S This is raspberry pi 64bit OS

enter image description here

LearneriOS
  • 99
  • 1

1 Answers1

0

Connecting the vcc of the relay to 3.3v of the RPi caused the relay to turn off correctly. I am not sure if this is the solution for this.

LearneriOS
  • 99
  • 1