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

To check the status of relay using interrupt in raspberry pi

Tue Jul 10, 2018 6:50 am

Hi, I am working with a raspberry pi with a relay with the incandescent bulb, buzzer, and button via SSH. The code is in a way that when I press a key from the keyboard the bulb and buzzer should be ON and when I press button both should get OFF. But my button code is not working properly.
And also I want to check the status of the relay using the interrupt and whenever the light on it should be sent a message to the database. But I don't know with interrupts. Below is my code. Please help me. Thanks in advance

Code: Select all

import RPi.GPIO as GPIO    
import time    
in1 = 25 #GPIO25 pin22    
buzzer=24 #GPIO24 PIN18    
led=8 #GPIO8 PIN24    
button=23 #GPIO23 PIN 16   

GPIO.setmode(GPIO.BCM)    
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)   
# check from database whether it is effective or deffective .currently I have inputted from keyboard     
                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)    
                        if in1==True || buzzer==True:    
                                print "messge to database:pending"     
                #def my_callback(channel):    
                #if GPIO.input(button) == True:        
                GPIO.wait_for_edge(button, GPIO.FALLING)       
                #if variable=="b":       
                        #while 1:        
                GPIO.output(in1,False)        
                GPIO.output(led,False)        
                GPIO.output(buzzer,False)        
                print "mesage to database:ack completed"         
                        #else:    
                                #pass    
                #else:     
                        #pass     
                GPIO.output(in1,False)     

except:     
        GPIO.cleanup()    
        GPIO.output(in1,False)    

If there is any error in my code please help me to rectify that. Thanks

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: To check the status of relay using interrupt in raspberry pi

Tue Jul 10, 2018 6:53 am

Why have you posted this twice? viewtopic.php?f=91&t=217782

I won't read discussion split across two threads, please discontinue this one.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

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

Re: To check the status of relay using interrupt in raspberry pi

Tue Jul 10, 2018 7:44 am

you have asked the same question 3 times

viewtopic.php?f=91&t=217733&p=1338666#p1338666

viewtopic.php?f=91&t=217782&p=1338925#p1338925

viewtopic.php?f=91&t=217786

and people have posted answers , how many time are you going to ask this ? you wont get a different answer just because you keep asking the question.
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: To check the status of relay using interrupt in raspberry pi

Tue Jul 10, 2018 8:32 am

Yes please don't keep creating new threads on the same issue.
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”