Muhsina
Posts: 3
Joined: Mon Jul 09, 2018 12:31 pm

how to check the status of relay pin using an interrupt.

Mon Jul 09, 2018 12:50 pm

Hi,

I am working with the 5v relay module with an incandescent bulb and raspberry pi3. I have done my code in a way that relay should work continuously if I press a key from keyboard and it should be off when another key is pressed. So now I want to check the status of the relay pin using the interrupt functions and then if the bulb is on it should send a message.


import RPi.GPIO as GPIO
import time
in1 = 16
buzzer=18
led=24
button=22

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(in1, GPIO.OUT)
GPIO.setup(buzzer,GPIO.OUT)
GPIO.setup(led,GPIO.OUT)
#GPIO.setup(button,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.output(in1, False)
GPIO.output(buzzer,False)
GPIO.output(led,False)
try:

GPIO.output(in1,False)
while True:
GPIO.output(in1,False)
variable=raw_input()
if variable=="a":
m=variable
for x in m:

GPIO.output(in1, True)
time.sleep(0.05)
GPIO.output(in1, False)
time.sleep(0.05)
GPIO.output(buzzer,True)
GPIO.output(led,True)
#def my_callback(channel):
#if GPIO.input(button) == True:





if variable=="b":
#while 1:
GPIO.output(in1,False)
GPIO.output(led,False)
GPIO.output(buzzer,False)
#else:
#pass
#else:
#pass
GPIO.output(in1,False)
except:
GPIO.cleanup()

Please help me with the code. Thanks in advance.

pcmanbob
Posts: 6449
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: how to check the status of relay pin using an interrupt.

Mon Jul 09, 2018 2:48 pm

Hi.

There is no feed back on a relay pin ( I assume you mean the IN control pin ), if only function is to take a high or low input.

The only way to test if the relay is actually on is to use a spare relay contact ( if the relay has one ) and wire it as you would a normal switch to the pi gpio and then test this to see if the relay is active or not.

what ever you do not connect the relay contact that is connected to your bulb as any voltage over 3.3v with damage you pi gpio.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

texy
Forum Moderator
Forum Moderator
Posts: 5155
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: how to check the status of relay pin using an interrupt.

Tue Jul 10, 2018 8:33 am

Locking due to duplicate threads. Please post any further replies on this one :
viewtopic.php?f=91&p=1338925#p1338925

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Return to “Beginners”