OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Raspberry pi GPIO pin not turning off

  • Thread starter Thread starter LearneriOS
  • Start date Start date
L

LearneriOS

Guest
I bought RPi, flashed the OS. I also bought a 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:

Code:
import RPi.GPIO as GPIO
import time

in1 = 29  # 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.

This is raspberry pi 64bit OS.
<p>I bought RPi, flashed the OS. I also bought a 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.</p>
<p>My code:</p>
<pre><code>import RPi.GPIO as GPIO
import time

in1 = 29 # 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
</code></pre>
<p>My problem:
Once the relay turns high at comment <code># 1</code> it does not turns off at point <code># 2</code>. 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.</p>
<p>The point <code># 3</code> does get executed. <code># 4</code> 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>
<p>This is raspberry pi 64bit OS.</p>
 

Latest posts

A
Replies
0
Views
1
Alfredo Augusto Petri
A
Top